MATH 376 -- Probability and Statistics 2
April 3, 2006
First Least Squares Regression Example
The housing price data:
| > | read "/home/fac/little/public_html/ProbStat0506/MSP.map"; |
Warning, the name changecoords has been redefined
For computation of the estimators for the coefficients in the model
Y =
We enter the lists of x and y coordinates of the data points separately:
| > | XList:=[0.,1,2,3,4,5,6,7]; |
| > | YList:=[27.6,32.5,35.9,39.3,44.8,48.8,55.7,62.9]; |
Means:
| > | Xbar:=Mean(XList); |
| > | Ybar:=Mean(YList); |
Organizing the computation as we described in class:
| > | SXY:=add((XList[i]-Xbar)*(YList[i]-Ybar),i=1..8); |
| > | SXX:=add((XList[i]-Xbar)*(XList[i]-Xbar),i=1..8); |
| > | hatbeta[1]:=SXY/SXX; |
| > | hatbeta[0]:=Ybar-hatbeta[1]*Xbar; |
Plot the data points together with the line determined by the least-squares estimators
for
and
| > | with(plots): |
| > | Pts:=[seq([XList[i],YList[i]],i=1..8)]; |
| > | PP:=plot(Pts,style=point,color=blue,symbol=circle): |
| > | LP:=plot(hatbeta[0]+hatbeta[1]*x,x=0..8): |
| > | display(PP,LP); |
| > |
This indicates a pretty good "fit" with the linear model. (Other functional forms could
also be considered, though, since it seems that the y 's are consistently low in the
middle of the range of x's. )