MATH 376 -- Probability and Statistics 2
April 5, 2006
Example 1.
Normal equations for fitting the linear model
to the data points [0,0,2], [1,0,1], [0,1,4], [1,1,5]
| > | X:=matrix([[1.0,0,0],[1,1,0],[1,0,1],[1,1,1]]); |
| > | Z:=matrix([[2],[1],[4],[5]]); |
| > | XtX:=multiply(transpose(X),X); |
| > | XtZ:=multiply(transpose(X),Z); |
| > | beta:=linsolve(XtX,XtZ); |
| > | PlP:=plot3d(beta[1,1]+beta[2,1]*x+beta[3,1]*y,x=-0.5..1.5,y=-0.5..1.5,axes=boxed): |
| > | SP1:=plot3d([0.05*cos(theta)*sin(phi),0.05*sin(theta)*sin(phi),2+0.05*cos(phi)],theta=0..2*Pi,phi=0..Pi,color=blue): |
| > | SP2:=plot3d([1+0.05*cos(theta)*sin(phi),0.05*sin(theta)*sin(phi),1+0.05*cos(phi)],theta=0..2*Pi,phi=0..Pi,color=blue): |
| > | SP3:=plot3d([0.05*cos(theta)*sin(phi),1+0.05*sin(theta)*sin(phi),4+0.05*cos(phi)],theta=0..2*Pi,phi=0..Pi,color=blue): |
| > | SP4:=plot3d([1+0.05*cos(theta)*sin(phi),1+0.05*sin(theta)*sin(phi),5+0.05*cos(phi)],theta=0..2*Pi,phi=0..Pi,color=blue): |
| > | display3d(SP1,SP2,SP3,SP4,PlP,scaling=constrained); |
We see the plane in
that comes closest to containing the 4 data points.
Example 2.
Normal equations for fitting the linear model
Y =
to the data points [0,1], [1,4], [2,7], [3,8].
| > | with(linalg): |
We let
and
The normal equations are
| > | X:=matrix([[1.0,0,0],[1,1,1],[1,2,4],[1,3,9]]); |
| > | Y:=matrix([[1],[4],[7],[8]]); |
| > | XtX:=multiply(transpose(X),X); |
| > | XtY:=multiply(transpose(X),Y); |
| > | beta:=linsolve(XtX,XtY); |
| > | with(plots): |
| > | Pts:=[[0,1],[1,4],[2,7],[3,8]]; |
| > | PP:=plot(Pts,style=point,symbol=circle,color=blue): |
| > | RP:=plot(beta[1,1] + beta[2,1]*x + beta[3,1]*x^2,x=-1..4): |
| > | display(PP,RP); |
| > |