6 3 2 3 4

advertisement
CROP 590 Experimental Design in Agriculture
Lab exercise – Week 10
Special Topic: Matrix Algebra
ANOVA and Regression in Matrix Notation
Refer to the power point presentation for background information for this exercise.
6
4
A
8
2

3
9

2
7 
2
1
B
6
8

3
7

5
4 
1) What is b3,2? What are the dimensions of B?
2) Calculate C = A – B
3) Calculate E = A + B
4) What is the transpose of A?
5) Calculate A’B
1
6) Calculate the determinant of H and the inverse of H.
 7 2
H

5
3


7) What is the trace of H?
8) You wish to fit a quadratic curve to the following data.
X
2
4
6
8
Y
6
13
17
16
Yi = b0 + b1Xi + b2Xi2
In Matrix notation , Y = XB + e
Y =
6 
13 
 
17 
16 
  
X
1
1
1
1
B
+ e
4
 e1 
b


0
16     e 2 
 b1   
36     e3 
b2   
64   e 4 
2
4
6
8
The solution to the normal equations is B = X’X-1X’Y
9) Use matrix functions in Excel to solve for B (MMULT, TRANSPOSE, and MINVERSE)
10) Solve for B using PROC IML in SAS
PROC IML;
X={1 2 4, 1 4 16, 1 6 36, 1 8 64};
Y={6, 13, 17, 16};
XPX=X`*X;
print XPX;
XPXinv=inv(XPX);
print XPXinv;
XPY=X`*Y;
print XPY;
B=XPXinv*XPY;
print B;
quit;
2
11) Now let’s analyze a simple CRD experiment with matrix notation:
TRT
1
1
2
2
3
3
Y
3
4
1
4
8
6
Y =
X
3   1
 4  1
  
 1  1
 4   1
  
8   1
  
 6  1
1
1
0
0
0
0
B
+ e
0
 e11 
e 
0
 b0   12 
1    e 21 
b1   
1   e 22 
 b2 
 e31 
0
 

0
 e32 
proc iml;
X={1 1 0,
1 1 0,
1 0 1,
1 0 1,
1 0 0,
1 0 0}
;
Y={3, 4, 1, 4, 8, 6};
CF=sum(Y)*sum(Y)/countn(Y);
XPX=X`*X;
XPXinv=inv(XPX);
XPY=X`*Y;
B=XPXinv*XPY;
SSTotal=(Y`*Y)-CF;
SSTrt=B`*XPY-CF;
SSE=SSTotal-SSTrt;
YHAT=X*B;
Resid=Y-YHAT;
print SSTotal SSTrt SSE B YHAT Resid;
QUIT;
Refer to the power point presentation for more details….
3
Download