MATH 376 -- Probability and Statistics II

First Regression Example

April 16 - 19, 2004

>    read "/home/fac/little/public_html/ProbStat/MaplePackage/MSP.map";

Warning, the name changecoords has been redefined

130908691

The lists of   x   and   y   values.  As in problem 11.3 in the text,

    x[i]   represents the year i = 1  is 1972, etc.

  

    y[i]   represents the median sales price (in 1000's of $) for

       a single family house in the US in year x[i]

>    Xlist:=[1.,2,3,4,5,6,7,8];

Xlist := [1., 2, 3, 4, 5, 6, 7, 8]

>    Xbar:=Mean(Xlist);

Xbar := 4.500000000

>    Ylist:=[27.6,32.5,35.9,39.3,44.2,48.8,55.7,62.9];

Ylist := [27.6, 32.5, 35.9, 39.3, 44.2, 48.8, 55.7, 62.9]

We want to find the least-squares estimators for the coefficients

beta[0], beta[1]   in a linear model   Y  = beta[0]+beta[1]*x   + epsilon

Using the formulas   beta[1] = S[xy]/S[xx]    and   beta[0] = ybar-beta[1]*xbar

presented in class:

>    Ybar:=Mean(Ylist);

Ybar := 43.36250000

>    Sxy:=add((Xlist[i]-Xbar)*(Ylist[i]-Ybar),i=1..nops(Xlist));

Sxy := 203.3500000

>    Sxx:=add((Xlist[i]-Xbar)^2,i=1..nops(Xlist));

Sxx := 42.00000000

>    beta[1]:=Sxy/Sxx;

beta[1] := 4.841666667

>    beta[0]:=Ybar-beta[1]*Xbar;

beta[0] := 21.57500000

To display the regression line together with the observed data

points ( x[i], y[i] ),  first we ``zip together'' the two lists to

make a single list of pairs:

>    points:=[seq([Xlist[i],Ylist[i]],i=1..nops(Xlist))];

points := [[1., 27.6], [2, 32.5], [3, 35.9], [4, 39.3], [5, 44.2], [6, 48.8], [7, 55.7], [8, 62.9]]

Then we load the plots package, create separate plots for the data

points, and the line (note the colons at the end of the plot commands --

see what happens if you use the normal semicolon to display the output;

also note that we are assigning the output from the plot commands

to names  PP (for ``point plot'')  and  LP  (for ``line plot'') --

these have no intrinsic meaning for Maple, but they should be

suggestive of what's actually going on here!

>    with(plots):

>    PP:=plot(points,style=point,color=blue):

>    LP:=plot(beta[0]+beta[1]*x,x=0..9,color=red):

Finally, to plot the data points and the regression line together on the

same coordinate axes, we use the   display   command from the plots

package:

>    display(PP,LP);

[Maple Plot]

So, we can conclude that over this time frame, the median sales price

was increasing  roughly linearly, at a rate of approx.   beta[1]  = $4,842  dollars

per year.