Chapter 11

Computational Algorithms for Fitting a Regression

[20/55%]
Show
LaTeX
Problem 11.1

Write a program to implement the Gram-Schmidt algorithm (Algorithm 11.3 in Section 11.3). Try out your program on the Longley data and the polynomial approximations described in Example 11.3 in Section 11.8.4. Compare your results with those in Examples 11.2 and 11.3.

?
Problem 11.2

Verify the formulas for the updating algorithm in Section 11.7.

?
Problem 11.3

Try some experiments to compare the execution time of a regression performed using the Cholesky method with one using the SVD. Do the flop counts given in the text give a reasonable indication of the relative speed of the two methods?

?
Problem 11a.1

Calculate algebraically the solution to the system of linear equations corresponding to the matrix

[111111+ϵ221213] \left[\begin{smallmatrix} 1 & 1 & 1 & 1 \\ 1 & 1+\epsilon & 2 & 2 \\ 1 & 2 & 1 & 3 \end{smallmatrix}\right]

using Gaussian elimination with and without partial pivoting. Show that if partial pivoting is not used, the solution x3x_{3} is computed as

−2−1/ϵ1/ϵ -\frac{2-1 / \epsilon }{1 / \epsilon }

and as 1−2ϵ1-2 \epsilon if partial pivoting is used. Comment on the accuracy of these two methods if ϵ\epsilon is very small.

?
Problem 11a.2

Show that applying one Gaussian elimination step to the matrix XTX\mathbf{X}^{T} \mathbf{X} yields the matrix

[nnx‾0X~TX~] \left[\begin{smallmatrix} n & n \overline{\mathbf{x}} \\ \mathbf{0} & \widetilde{\mathbf{X}}^{T} \widetilde{\mathbf{X}} \end{smallmatrix}\right]

where X~\widetilde{\mathbf{X}} is the centered version of X\mathbf{X}.

?
Problem 11a.3

Verify (11.15) and hence show that RSS\sqrt{\mathrm{RSS}} is given by the (p+1,p+1)(p+1, p+1) th element of RA\mathbf{R}_{A}.

?
Problem 11a.4

If RTR\mathbf{R}^{T} \mathbf{R} is the Cholesky decomposition of XTX\mathbf{X}^{T} \mathbf{X}, show that

det⁡(XTX)=∏i=1prii2 \operatorname {det}\left(\mathbf{X}^{T} \mathbf{X}\right) = \prod _{i = 1}^{p} r_{i i}^{2}
?
Problem 11b.1

Let q1,…,qp\mathbf{q}_{1}, \ldots , \mathbf{q}_{p} be the vectors constructed in Algorithm 11.3. Show that q1,…,qj\mathbf{q}_{1}, \ldots , \mathbf{q}_{j} is an orthonormal basis for C(a(1),…,a(j))\mathcal{C}\left(\mathbf{a}^{(1)}, \ldots , \mathbf{a}^{(j)}\right) for j=1,2,…,pj = 1,2, \ldots , p.

?
Problem 11b.2

Show that an upper triangular matrix with positive diagonal elements is nonsingular. Also, prove that the inverse of an upper triangular matrix with unit diagonal elements is also upper triangular with unit diagonal elements.

?
Problem 11b.3

Derive formulas (11.23), (11.24), and (11.25).

?
Problem 11b.4

Prove that at the beginning of stage jj of the MGSA, the columns a(1),…,a(j)\mathbf{a}^{(1)}, \ldots , \mathbf{a}^{(j)} are orthogonal, are orthogonal to a(j+1),…,a(p)\mathbf{a}^{(j+1)}, \ldots , \mathbf{a}^{(p)}, and span the first jj columns of the original matrix.

?
Problem 11b.5

Show that a product of orthogonal matrices is orthogonal.

?
Problem 11b.6

Show that if Qp,Qn−p\mathbf{Q}_{p}, \mathbf{Q}_{n-p} and r1\mathbf{r}_{1} are as defined in (11.36), the fitted values Y^\widehat{\mathbf{Y}} are given by

Y^=(Qp,Qn−p)(r10). \widehat{\mathbf{Y}} = \left(\mathbf{Q}_{p}, \mathbf{Q}_{n-p}\right)\binom {\mathbf{r}_{1}}{\mathbf{0}} .
?
Problem 11b.7

Let Gih\mathbf{G}_{i h} be given by (11.40)(11.40) and D~=diag⁡(d~1,…,d~n)\widetilde{\mathbf{D}} = \operatorname {diag}\left(\tilde{d}_{1}, \ldots , \tilde{d}_{n}\right). Show that there is a diagonal matrix D=diag⁡(d1,…,dn)\mathbf{D} = \operatorname {diag}\left(d_{1}, \ldots , d_{n}\right) and a fast rotator of the form (11.45) such that Gih=DMD~−1\mathbf{G}_{i h} = \mathbf{D M} \tilde{\mathbf{D}}^{-1}. Show that

dl=d~l(l≠i,l≠h)di=sd~hdh=sd~iα=r/tη=1/rt \begin{aligned} d_{l} & = \tilde{d}_{l} \quad (l \neq i, l \neq h) \\ d_{i} & = s \tilde{d}_{h} \\ d_{h} & = s \tilde{d}_{i} \\ \alpha & = r / t \\ \eta & = 1 / r t \end{aligned}

where t=s/ct = s / c and r=d~h/d~ir = \tilde{d}_{h} / \tilde{d}_{i}.

?
Problem 11c.1

Prove that the condition number of Xw\mathbf{X}_{w} is given by (11.61).

?
Problem 11c.2

Repeat the calculations in Example 11.3 using the function f(t)=cos⁡4tf(t) = \cos 4 t in place of exp⁡(sin⁡4t)\exp (\sin 4 t). Does the ranking of the methods still hold good? Sample R-code is given after Exercise 3 below.

?
Problem 11c.3

Modify the code given below to count the number of flops that are required to execute each algorithm. How accurate are the formulas given in Table 11.2? ####################################################### # MGSA function: calculates Q and R^{-1} of QR decomp mgsa<-function(A){ n<-dim(A)[1] p<-dim(A)[2] GG<-diag(p) for(i in 1:(p-1)){ a<-A[,i] denom<-sum(aa) G<-numeric(p) for(j in (i+1):p){ num<-sum(A[,j]a) G[j]<- -num/denom A[,j]<-A[,j]+aG[j] } GG<-GG + outer(GG[,i],G) } list(W=A,G=GG) } ####################################################### #Householder function: calculates R of QR decomp of A house<-function(A){ n<-dim(A)[1] p<-dim(A)[2] for(j in 1:p){ indices<-j:n # construct Householder vector u<-numeric(n) u[indices]<-A[indices,j] unorm1<-sqrt(sum(u[indices]^2)) unorm2<-sum(u[indices[-1]]^2) uu<-u[j] u[j]<-if(uu<0)uu-unorm1 else -unorm2/(uu+unorm1) gamma<-0.5(unorm2 + u[j]^2) # multiply by householder matrix A[indices,j]<-0 A[j,j]<-unorm1 if(j==p)return(A) for(l in (j+1):p){ k<-sum(A[indices,l]u[indices])/gamma A[indices,l]<-A[indices,l] - ku[indices] } } A } ####################################################### # Givens function: calculates R of QR decomp of A givens<-function(A){ n<-dim(A)[1] p<-dim(A)[2] for(j in 1:(p-1)){ indices<-j:p for(i in (j+1):n){ sqr<-sqrt(A[j,j]^2+A[i,j]^2) cc<-A[j,j]/sqr ss<-A[i,j]/sqr temp<-ccA[j,indices] + ssA[i,indices] A[i,indices]<- -ssA[j,indices] + ccA[i,indices] A[j,indices]<-temp } } A }

?
Problem 11d.1

Suppose that we fit a least squares regression to a subset JJ of the nn available cases. Let XJ\mathbf{X}_{J} be the submatrix of X\mathbf{X} corresponding to the cases in JJ, let eie_{i} be the ii th residual from this fit, i=1,…,ni = 1, \ldots , n, and let hij=xiT(XJTXJ)−1xjh_{i j} = \mathbf{x}_{i}^{T}\left(\mathbf{X}_{J}^{T} \mathbf{X}_{J}\right)^{-1} \mathbf{x}_{j}. Show that if we drop case i∈Ji \in J and add case j∉Jj \notin J, the change in the residual sum of squares is

ej2(1−hii)−ei2(1+hjj)+2eiejhij(1−hii)(1+hjj)+hij2 \frac{e_{j}^{2}\left(1-h_{i i}\right)-e_{i}^{2}\left(1+h_{j j}\right)+2 e_{i} e_{j} h_{i j}}{\left(1-h_{i i}\right)\left(1+h_{j j}\right)+h_{i j}^{2}}
?
Problem 11d.2

Using the result in Exercise 1 above, write an R function implementing Hawkins's method of calculating an approximation to the LTS estimate.

?
Problem 11d.3

Write an R function to implement Ruppert's algorithm to calculate an approximation to the LTS estimate. You will need to refer to Ruppert [1992] for the details of the algorithm. Devise a small simulation to compare Ruppert's algorithm to Hawkins's.

?