@@ -42,15 +42,22 @@ chol(x, \dots)
4242 error occurs. If \code {x } is positive semi - definite (i.e. , some zero
4343 eigenvalues ) an error will also occur as a numerical tolerance is used.
4444
45- If \code {pivot = TRUE }, then the Cholesky decomposition of a positive
45+ If \code {pivot = TRUE }, then the Cholesky decomposition of a (rearranged )
46+ positive
4647 semi - definite \code {x } can be computed. The rank of \code {x } is
4748 returned as \code {attr(Q , " rank" )}, subject to numerical errors.
4849 The pivot is returned as \code {attr(Q , " pivot" )}. It is no longer
4950 the case that \code {t(Q ) \%* \% Q } equals \code {x }. However , setting
5051 \code {pivot <- attr(Q , " pivot" )} and \code {oo <- order(pivot )}, it
5152 is true that \code {t(Q [, oo ]) \%* \% Q [, oo ]} equals \code {x },
5253 or , alternatively , \code {t(Q ) \%* \% Q } equals \code {x [pivot ,
53- pivot ]}. See the examples.
54+ pivot ]}. Notice also , that \code {Q [,oo ]} is typically not triangular.
55+ See the examples.
56+
57+ NOTE : For versions of R up to 4.5.2 , the above wasn ' t quite true.
58+ You also needed \c ode{rank <- attr(Q, "rank")} and
59+ \c ode{t(Q[1:rank, oo, drop=FALSE]) \% *\% Q[1:rank, oo, drop=FALSE]}
60+ and similar for the alternative version.
5461
5562 The value of \c ode{tol} is passed to LAPACK, with negative values
5663 selecting the default tolerance of (usually) \c ode{nrow(x) *
@@ -99,8 +106,8 @@ crossprod(cm) #-- = 'm'
99106
100107# now for something positive semi-definite
101108x <- matrix(c(1:5, (1:5)^2), 5, 2)
102- x <- cbind(x , x [, 1 ] + 3 * x [, 2 ])
103- colnames(x ) <- letters [20 : 22 ]
109+ x <- cbind(x, x[, 1] + 3*x[, 2], 2*x[, 1] + x[, 2] )
110+ colnames(x) <- letters[20:23 ]
104111m <- crossprod(x)
105112qr(m)$rank # is 2, as it should be
106113
@@ -118,6 +125,13 @@ crossprod(Q[, order(pivot)]) # recover m
118125try(chol(m)) # fails
119126(Q <- chol(m, pivot = TRUE)) # warning
120127crossprod(Q) # not equal to m
128+
129+ ## another example, this time with positive, negative, and zero eigenvalues
130+ ## notice that this (and the previous example) gets the rank wrong
131+ (m <- matrix(c(1,1,2, 1,1,2, 2,2,1), 3, 3))
132+ chol(m, pivot=TRUE)
133+ eigen(m)$values
121134}
135+
122136\k eyword{algebra}
123137\k eyword{array}
0 commit comments