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
The lists of x and y values. As in problem 11.3 in the text,
represents the year i = 1 is 1972, etc.
represents the median sales price (in 1000's of $) for
a single family house in the US in year
> | Xlist:=[1.,2,3,4,5,6,7,8]; |
> | Xbar:=Mean(Xlist); |
> | 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
in a linear model Y = +
Using the formulas and
presented in class:
> | Ybar:=Mean(Ylist); |
> | Sxy:=add((Xlist[i]-Xbar)*(Ylist[i]-Ybar),i=1..nops(Xlist)); |
> | Sxx:=add((Xlist[i]-Xbar)^2,i=1..nops(Xlist)); |
> | beta[1]:=Sxy/Sxx; |
> | beta[0]:=Ybar-beta[1]*Xbar; |
To display the regression line together with the observed data
points ( ), first we ``zip together'' the two lists to
make a single list of pairs:
> | points:=[seq([Xlist[i],Ylist[i]],i=1..nops(Xlist))]; |
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); |
So, we can conclude that over this time frame, the median sales price
was increasing roughly linearly, at a rate of approx. = $4,842 dollars
per year.