ST790R -- Fall 2010 Homework #3 -- due Tuesday, 28 September 2010 Exercises in Textbook: (*just turn in these) *5.13 *modified* Compare either the algorithm in 5.11 (code with a loop) or (2.5.1)(*correct it*) with the 'usual' calculations of SUM(x(i)^2) - (SUM(x(i)))^2/N, etc. and with R's 'var' function. Use (2^k) + i, for i=1, ...,32 and k=12, 25, 27, 30. Just compare the variance calculations. 0) Centering, or subtracting the mean from a covariate, is a common practice in regression, and it has its advantages in computation. Writing Xb = X*S*inv(S)*b = Wc where X and W have the same column space, the 2nd through p-th cols of W are centered cols of X, write the p*p matrix S, and construct its inverse. ( W = X*S and c = inv(S)*b ) R Exercises: 1) Let y = (4.82, 4.88, 4.70, 4.72, 4.88, 4.66, 4.94, 4.80)' and let x = (38, 40, 42, 44, 36, 42, 38, 40)' be the covariate of a simple linear regression model, where the first column of the design matrix X is one, and the second column is x. Compute y'Pone y, y'(Px-Pone)y, and y'(I-Px)y, where Pone is a matrix with each element equal to 1/n (here n=8), and Px is X*inv(X'X)X' the usual symmetric projection matrix. *** this time, do this using the qr() function *** 2) Read in the Ramus Data from the file 'ramus.dat' in the course 'rfiles' directory. My old-fashioned code is Ramus <- t( matrix( scan("ramus.dat"), 4, 20) ) which will make a 20x4 matrix. 3) Compute the sample covariance matrix using var(Ramus) and call this matrix V *4) Partition the matrix V into the first two and last two rows/ columns and compute V11 - V12*inv(V22)*V21 *** For Homework #2, I wanted you to use chol() and forwardsolve(), (and that's all!) so redo (4). *** this time, do this using either qr() function or sweep *** (you can use the original matrix 'Ramus' instead of V) *5)(similar to *New *1* in 'Update' for Chapter 5) In the file "uspop.dat" are values of the US population for the years 1948-1971. The first column is the year and the second column is the population in millions. Compute the condition number for a quadratic regression (three columns: intecept, linear, quadratic). Center the year either by 1900 or by its mean and recompute the condition number.