



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




STAT 511 Assignment 3 Name ________________ Spring 2002
Reading Assignment: Rencher: Review Sections 2.8 and 2.13. You should have already read Chapter 11 which provides an overview of estimation, estimability, and testing hypotheses in linear models. Applications of these ideas to parameter estimation in one-way analysis of variance and regression analysis are given in Sections 12.1-12.3 and 7.1-7.5, respectively. You covered this material in Stat 500, but it may be helpful to review it at this time. The later parts of Chapters 7 and 12 are on hypothesis testing. We will need to cover the material in Chapters 4 and 5 before we begin our discussion of hypothesis testing. You should next read Chapters 4 and 5.
Written Assignment: On-campus students: Due Wednesday, February 6. Distance students: Put it in the mail by February 14.
(a) If A is positive semidefinite, then PTAP is positive semidefinite.
(b) If A is positive definite, then PTAP is positive definite.
(b) Find two other generalized inverses for A.
(a) Show that X is an eigenvector of the matrix I −− X(XT^ X) −−^1 XT. (b) What is the eigenvalue associated with X? (c) Show that any vector V that is orthogonal to X , i.e. XTV^ == 0 , is also an eigenvector of I − − X(XT^ X) −−^1 XT. (d) What are the eigenvalues of I − − X(XT^ X) −−^1 XT?
r^0 LT
represent the spectral decomposition of A. Then, ∆r is an r×r diagonal matrix containing the positive eigenvalues of A, and L is an n×n orthogonal matrix where the columns are
eignenvectors of A. Show that G = L (^)
r^1^0 LT^ satisfies the definition of the Moore-
Penrose inverse of A.
(b) Write an S-Plus function to compute the inverse square root matrix of a symmetric positive definite matrix. (If V is a symmetric positive definite matrix, find a matrix
V −^1 /^2 such that V −^1 /^2 V −^1 /^2 = V −^1 .) Submit a listing of your code.
(c ) Use your function from part (b) to evaluate V −^1 /^2 for the matrix in part (a).
(d) Suppose ~
~
~ 0 and VAR( ~
where V is the matrix in part (a). Let ~
1 / 2 ~
Z == V −− Y. Find E ( ~
Z ) and Var ( ~
with E(εi ) = 0 for all i = 1, 2, ..., n. This model can be expressed as a linear model with
E(Y) = X ββ and Var( Y )=∑. An ordinary least squares estimator for ββ is any vector b that
minimizes the sum of squared residuals, i.e., minimizes
1
2 i 1 1i k ki
Y Xb Y X b
n^ T
i
The first line of this file has the variable names. (If you want to analyze these data with the
SAS package you should use the data file posted under biomass.dat. There are no variable
names in that file.) Copy the data file to your Stat 511 directory. Start S-PLUS on Vincent
or start up a windows version of S-PLUS and get into the Command window. You can
enter these data into S-PLUS as a data frame with the command
biomass ← read.table("filename",header=T)
Then, use the command
biomass
to view the data frame. It should have eight columns and 45 rows. Now create two matrices
that will be used to fit a regression model to these data. Create a vector Y from the third
column of the data frame and a matrix X from the last five columns of the data frame with
the following commands:
Y ← as.matrix(biomass[ ,3]) X ← as.matrix(biomass[ ,4:8])
Note the use of [ ] to select columns from the data frame. Here, the function as.matrix
is used to create a matrix from one or more columns of the data frame. To add a column of
ones to the model matrix, use the commands
X0 ← rep(1, length(Y)) X ← cbind(X0, X)
a. Create a scatterplot matrix for X 1 , X 2 , X 3 , X 4 , X 5 and Y with the command
splom(~biomass[ ,3:8], aspect=”fill”)
Describe what this scatterplot matrix reveals about relationships between the variables.
In examining a plot for possible trends or patterns, it is sometimes helpful to pass smooth
curves through the points on the plot. The following code creates a function that inserts points and a smooth curve on a plot. Then it is applied to the last 6 columns of the biomass data frame with the pairs( ) function. The par( ) function sets the size and other features of the plot, such as thickness of lines and type and size of plotting symbols.
points.lines <- function(x, y) { points(x, y) lines(loess.smooth(x, y, 0.90)) }
par(din=c(7,7), pch=18, mkh=.15, cex=1.2, lwd=3) pairs(biomass[ ,-(1:2)], panel=points.lines)
You can compute a correlation matrix with the following code. The cor( ) function computes the correlations and the round( ) function rounds the printed correlations to 4 digits after the decimal point.
round(cor(biomass[-(1:2)]),4)
b. Use the qr( ) function to compute the rank of X.
c. Compute a vector of estimated regression coefficients
b = (XT^ X)-1XT Y
Use matrix operations to do this. Do not use any built in S-PLUS functions for model fitting.
d. Compute the vector of estimated means, == X b
∧ ∧ Y , and the vector of residuals ∧ ∧ e == Y −−Y. Plot the residuals against the estimated means. This can be done with the following code. Some information on the par() function is included as comment statements.
case<-1: heading <- c("Case","Salinity", "pH", "K", "Na", "Zn", "Biomass", "Predicted", "Residuals") temp <- cbind(case, X[ ,-1], Y, yhat, e) dimnames(temp) <- list(case, heading) round(temp,4)
Now the write.matrix( ) function is used to write this matrix to the file “c:/stat511/temp.out”. You should change to file name to indicate where you want to save the file on your computer.
write.matrix(temp,file="c:/courses/st511/hw/temp.out")
Compute the estimate of the covariance matrix for b. The formula for this matrix is s 2 (XTX)^ -1. Use this result to obtain standard errors for the estimated regression coefficients. Do not report the value of s 2 (XTX)-1. Modify the S-PLUS code to create a matrix with the estimated coefficients in the first column and the corresponding standard errors in the second column. Label the rows and columns of your matrix. Use the write.matrix( ) function to write it out to a file. Submit a listing of the matrix and your S-PLUS code.
i. In this problem we entered the data into S-PLUS as a data frame, and converted parts of the data frame to matrices. Describe the difference between a matrix and a data frame in S-PLUS?