Lab 3 1 2 1 2 3 1 3

advertisement
Stat404
Fall 2009
Lab 3
1. The following are three matrices:
1 2
B = 3 4
1 5
A = 1 2 3
4 5 6
C = 1 3
2 9
a. Give the dimensions of A, B, and C.
T
T
T
T
b. Show that A + B = B + A .
c. Show that A + B  A + B .
tr  ABC  = tr  BCA  = tr  CAB  .
d. Show that
T
T
T
e. Show that  CA  = A C .
C  I 2 = I 2  C = C , where
with dimensions, 2  2 .
f. Show that
g. Calculate det(C) and find C
h. Show that
C
–1
C = CC
2. Consider the linear model
1
X = 1
1
1
1
3
5
7
–1
–1
T
T
˜
T
b. Compute  X X 
–1
.
.
= I2 .
y = Xb + e ,
˜ ˜
˜
34
y = 47
55
˜
64
and
a. Compute X X , X y , and
T
I 2 is an identity matrix
y y.
˜ ˜
where
1
–1
T
T
c. Compute b =  X X  X y .
˜
d. Find
˜
2
2
1
T
n–k–1 ˜ ˜
and ̂ = ---------------------  e e  .
e = y – Xb
˜
˜
˜
T
e. Compute var  b  = ̂  X X 
–1
.
2
Note: Here and in part d ̂ is
˜
a scalar (i.e., a single number).
f. Show that
T
–1
T
 I 4 – X  X X  X  is idempotent (i.e., that multiplying
it by itself yields the original matrix).
g. Construct an ANOVA table with sums of squares (namely, the
regression-, error-, and total-sums of squares), associated degrees
of freedom, and mean squares. Does X explain a significant
proportion of the variation in y at the .05 level?
Use an F-test to
˜
support your conclusion. Hints: Be sure to show your work on this
and all problems (an on exams too). The error and total sums of
squares can be found using matrix algebra as follows:
T
SS ERROR = e e
˜ ˜
SS TOTAL
1
T
1 T
=  y – Y1   y – Y1  , where Y = ---  y 1  , and where 1 = 1 .
n
1
˜
˜
˜ ˜
˜
˜
˜
1
3. Use the following SPSS commands to verify your calculations in
problem 2:
data list records=1 /1 y 1-2 x 4.
variable labels y 'dependent var' x 'independent var'.
begin data.
34 1
47 3
55 5
64 7
end data.
regression variables=y,x/dependent=y/enter.
In doing this problem, circle and assign unique letters to the numbers
on the output that correspond to your computations (in the previous
2
2
problem) of b , ̂ , as well as of values in the ANOVA table
˜
and for the F-test. Write these letters (circled to make them
obvious, please) next to the corresponding numbers in your
computations.
Below please find R and SAS code for problem 3:
# R
# Code:
# Create a data set named, “lab3,” with column vectors for “x” and “y”
y <- c(34,47,55,64)
x <- c(1,3,5,7)
lab3 <- data.frame(cbind(y,x))
attach(lab3)
# Regression
reg1 <- lm(y~x)
summary(reg1)
# ANOVA
anova1 <- aov(y~x)
summary(anova1)
* SAS
* Code:
* Create a data set named, “lab3q3,” consisting of the variables, “y”
and “x”;
DATA lab3q3;
INPUT y x;
DATALINES;
34 1
47 3
55 5
64 7
;
RUN;
* Regression;
PROC REG data=lab3q3;
MODEL y=x;
RUN;
3
Download