Docsity

Matrix Algebra and Linear Regression: Spring 2002 Assignment, Assignments of Data Analysis & Statistical Methods

Toggle sidebar
bg1
1
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.
1. Suppose P is a non-singular matrix. Use the definitions of positive definite and positive
semi-definite matrices to prove the following results.
(a) If A is positive semidefinite, then PTAP is positive semidefinite.
(b) If A is positive definite, then PTAP is positive definite.
2. Only square, nonsingular matrices have inverses, but every matrix has a generalized inverse.
For example, let
A =
2-
5
2
1
(a) Show that B =
[
]
0001 is a generalized inverse for A.
(b) Find two other generalized inverses for A.
3. Let T
n21 )x,,x,x(XK== denote any non-zero vector of length n.
(a) Show that
X
is an eigenvector of the matrix T1TX)XX(XI−−
−− .
(b) What is the eigenvalue associated with
X
?
(c) Show that any vector V that is orthogonal to
X
, i.e. 0VXT== , is also an eigenvector
of T1TX)XX(XI−−
−− .
(d) What are the eigenvalues of T1TX)XX(XI−−
−− ?
pf3
pf4
pf5

Partial preview of the text

Download Matrix Algebra and Linear Regression: Spring 2002 Assignment and more Assignments Data Analysis & Statistical Methods in PDF only on Docsity!

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.

  1. Suppose P is a non-singular matrix. Use the definitions of positive definite and positive semi-definite matrices to prove the following results.

(a) If A is positive semidefinite, then PTAP is positive semidefinite.

(b) If A is positive definite, then PTAP is positive definite.

  1. Only square, nonsingular matrices have inverses, but every matrix has a generalized inverse. For example, let

A =

(a) Show that B = [ 1 000 ] is a generalized inverse for A.

(b) Find two other generalized inverses for A.

  1. Let X == (x 1 ,x 2 ,K,xn)T denote any non-zero vector of length n.

(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?

  1. Let A be an nxn symmetric matrix with rank (A) = r. Here r may be smaller than n. Let

A = L 

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.

  1. (a) Use the eigen ( ) function in S-Plus to compute the eigenvalues and eigenvectors of

V =

(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 ~

Y = ( Y 1 Y 2 Y 3 ) T is a random vector with E(

~

Y ) =

~ 0 and VAR( ~

Y ) = V,

where V is the matrix in part (a). Let ~

1 / 2 ~

Z == V −− Y. Find E ( ~

Z ) and Var ( ~

Z ).

  1. Consider a linear model Yi = β 1 X1i + β 2 X2i + ... + βkXki + εi, where εi is a random error

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

( Y bX b X ).

1

2 i 1 1i k ki  

− − − = ^ −

∑

Y Xb Y X b

n^ T

i

L

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.

Specify plotting symbol and size of graph in inches.

fin=c(w,h) specifies a plot that is w inches wide

and h inches high

pch=18 requests a filled diamond as a plotting

symbol

mkh=b requests plotting symbols that are b

inches high

cex=c sets the size of the characters used to

print labels at c times the printer default

mar mar=c(5,5,4,2) specifies the number of lines

of text on each side of the plot, starting

at the bottom and moving clockwise. Here

write up to 5 lines at the bottom, up to

5 lines on the left side, etc…

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?