|
This quantlet illustrates the concept of linear regression by setting up a scatter plot and a line, and allowing the user to change the slope or intercept of the line to try to minimize the residual sum of squares. To activate this, the following should be typed in:
twlinreg()After this, the user should see the following windows:
These are specifications for the scatter-plot diagram, the
same as with the
twpearson
quantlet. After the
specifications are entered and the OK button is clicked,
the following window should appear (this is for the default
values of 30 data points, 0 correlation):
The upper frame of the Display window contains the
scatter-plot diagram, as well as a line for which we would
like to minimize the residual sum of squares. The middle
frame contains the equation of this line (yhat =
),
as well as the residual sum of squares (
). The lower
frame contains a graph of the residuals. That is, each
vertical line in the bottom graph represents the distance
between one of the points and the line in the above graph.
The
is the sum of the squares of these distances. The
object is to find the line which gives the minimum of these
sums, which can be done by changing the slope and/or intercept
of the given line.
The first four selections in the Choose window are for changing the given line -- the user simply makes the appropriate choice(s), then clicks on OK to see the result. Additionally, the user can request for the following to be shown on the scatter plot:
A user who is learning linear regression for the first
time can change the slope and/or intercept of the given
line and see if this decreases the
. The lower frame
of the display gives a visual demonstration of the
distances between the points and the line. Showing the
regression of
on
can verify if the user has the
minimum
, and show how far off he/she is. Showing
the regression of
on
, and the total regression,
shows how different the result can be if the distance is
measured in two alternative ways.
The following formulas are used for the computations of
and
, which are taken from the Gauss-Markov
theorem:
![]() |
![]() |
![]() |
|
![]() |
|||
![]() |
|||
![]() |
![]() |
![]() |