Computational algorithms for least squares

[22/50%]
Show
LaTeX

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.

?

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}.

?

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}.

?

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

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.

?

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.

?

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}} .
?

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}.

?

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 }

?

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

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.

?

Write a small computer program to calculate the residual sum of squares for all possible regressions using the Garside algorithm. What size problems can reasonably be handled?

?

Implement the Morgan and Tatar algorithm. What sort of improvements do you notice over the Garside algorithm?

?

Consider a regression with regression matrix X\mathbf{X} and LSE β^\widehat{\mathbf{\beta }}. Suppose that a new case with data (x,Y\mathbf{x}, Y) is added. Show that the residual sum of squares is increased by an amount e2/(1+xT(XTX)−1x)e^{2} /\left(1+\mathbf{x}^{T}\left(\mathbf{X}^{T} \mathbf{X}\right)^{-1} \mathbf{x}\right), where e=Y−xTβ^e = Y-\mathbf{x}^{T} \widehat{\mathbf{\beta }}.

?

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.

?

Verify the formulas for the updating algorithm in Section 11.7.

?

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?

?

Explain how you could calculate the ridge estimate β^(k)\widehat{\beta }(k) using a least squares program.

?

References

[SeLe03] Seber G.A., Lee A.J. Linear Regression Analysis. 2nd ed., John Wiley & Sons, 2003.