homework 3 St 708
Homework 3 St 708
< Hypothesis tests etc.
/* ---------------------------------------Due Sep.18, 2003-----------
| This exercise reviews hypothesis tests etc. |
| |
--------------------------------------------------------------------
Questions
/*---------------------------------------------------------------------- | |
| Work Ex. 3.5 pg. 94 by hand or using SAS PROC IML. In addition, |
| compute the whole 7x7 matrix P in SAS . |
| Sum the elements on the diagonal of P and explain how this sum |
| relates to the idea of a projection. |
| Compute D=P*P-P and print out D. What have you shown? |
| In addition, suppose I am interested in the difference between |
| the first and third residual value. Compute a standard error |
| for this difference. Hint: from the distribution of the residuals, |
| get the distribution for the difference of these two residuals. |
| Finally, create a SAS dataset with variables Y X1 and X2 as given |
| in the problem (it's easy if you just edit this file) |
| Now run this code: |
| PROC REG; MODEL Y = X1 X2 / XPX I P; |
| All I need to see is the output, but you should take a minute to |
| see that PROC REG has given you most of what the problem requests. |
| |
| Work Ex. 3.6 pg. 94. |
| |
| Work Ex. 4.5 pg. 151-2 |
| Recall for part c that the "R notation" uses R(X2|X0,X1,X3) to |
| denote the difference in model sums of squares between a model |
| with Y regressed on X0, X1, X2, and X3 and one with Y regressed on |
| just X0, X1, and X3. |
| Also note the use of the word "causal" in d (i) - would the answer |
| change if it said "important regressor variable" rather than "causal" |
| variable? |
-----------------------------------------------------------------------*/
* partial PROC IML code for problem 3.5 ;
PROC IML; DATA =
{ 78.5 1 7 2.6,
74.3 1 1 2.9,
104.3 1 11 5.6,
87.6 1 11 3.1,
95.9 1 7 5.2,
109.2 1 11 5.5,
102.7 1 3 7.1 } ;
sums = data[+, ]; print sums;
X= Data[ ,2:4]; Y=data[ ,1]; print X Y;
xpy = x`*y; inxpx = inv(x`*x);
* Note: 2:4 means columns 2 through 4 in the above code ;
* You do the rest ;
*Some IML code for problem 4.5 ;
PROC IML;
Y = {6.68, 6.31, 7.13, 5.81, 5.68, 7.66, 7.30, 6.19, 7.31};
X = {
32.6 4.78 1092 293.09 17.1,
33.4 4.62 1279 252.18 14.0,
33.2 3.72 511 109.31 12.7,
31.2 3.29 518 131.63 25.7,
31.0 3.25 582 124.50 24.3,
31.8 7.35 509 95.19 0.3,
26.4 4.92 942 173.25 21.1,
26.2 4.02 952 172.21 26.1,
26.6 5.47 792 142.34 19.8};
int = shape(1,9,1); X = int||x; print int[format = 3.1] X Y;
P = X*inv(X`*X)*X`;
YPY=Y`*P*Y; YY=Y`*Y;
print YPY YY;
YIPY = Y`*(I(9)-P)*Y; YIJY = Y`*(I(9)-j(9)/9)*Y;
print YIPY YIJY;
YPJY = Y`*(P-J(9)/9)*Y; YJY = Y`*(J(9)/9)*Y;
print YPJY YJY;
* note that shape(a,r,c) creates an rxc matrix each entry of which is a
This is one way to create J. Notice how A[+, ] returns all columns of
matrix A summed down the rows (it is a row of sums). Also I(r) creates
an rxr identity, J(r) a matrix of 1s, and finally note the || horizontal
concatenation operator. A similar // will give vertical concatenation
of matrices. ;
Optional problem of historic interest