lm(): LINPACK/LAPACK 中 QR 分解返回的 qraux 是什么 [英] lm(): What is qraux returned by QR decomposition in LINPACK / LAPACK
问题描述
rich.main3
是 R 中的线性模型.我了解列表中的其余元素,但我不明白 qraux
是什么.文档指出它是
rich.main3
is a linear model in R. I understand the rest of the elements of the list but I don't get what qraux
is. The documentation states that it is
长度为 ncol(x) 的向量,其中包含关于 old{Q}" 的附加信息.
a vector of length ncol(x) which contains additional information on old{Q}".
这意味着什么附加信息?
str(rich.main3$qr)
qr : num [1:164, 1:147] -12.8062 0.0781 0.0781 0.0781 0.0781 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:164] "1" "2" "3" "4" ...
.. ..$ : chr [1:147] "(Intercept)" "S2" "S3" "x1" ...
..- attr(*, "assign")= int [1:147] 0 1 1 2 3 4 5 6 7 8 ...
..- attr(*, "contrasts")=List of 3
.. ..$ S : chr "contr.treatment"
.. ..$ ID : chr "contr.treatment"
.. ..$ Block: chr "contr.treatment"
$ qraux: num [1:147] 1.08 1.06 1.16 1.21 1.27 ...
$ pivot: int [1:147] 1 2 3 4 5 6 7 8 10 11 ...
$ tol : num 1e-07
$ rank : int 21
- attr(*, "class")= chr "qr"
推荐答案
想必你不知道 QR 分解是如何计算的.我在 LaTeX 中写了以下内容,可能会帮助您澄清这一点.当然,在编程站点上,我需要向您展示一些代码.最后给大家推荐一个玩具R函数计算家庭反射.
Presumably you don't know how QR factorization is computed. I wrote the following in LaTeX which might help you clarify this. Surely on a programming site I need to show you some code. In the end I offer you a toy R function computing Householder reflection.
住户反映矩阵
家庭转型
家庭 QR 分解(无旋转)
QR 和重新缩放的紧凑存储
LAPACK 辅助例程 正在执行 Householder 变换.我还写了下面的玩具R函数来演示:
The LAPACK auxiliary routine dlarfg
is performing Householder transform. I have also written the following toy R function for demonstration:
dlarfg <- function (x) {
beta <- -1 * sign(x[1]) * sqrt(as.numeric(crossprod(x)))
v <- c(1, x[-1] / (x[1] - beta))
tau <- 1 - x[1] / beta
y <- c(beta, rep(0, length(x)-1L))
packed_yv <- c(beta, v[-1])
oo <- cbind(x, y, v, packed_yv)
attr(oo, "tau") <- tau
oo
}
假设我们有一个输入向量
Suppose we have an input vector
set.seed(0); x <- rnorm(5)
我的函数给出:
dlarfg(x)
# x y v packed_yv
#[1,] 1.2629543 -2.293655 1.00000000 -2.29365466
#[2,] -0.3262334 0.000000 -0.09172596 -0.09172596
#[3,] 1.3297993 0.000000 0.37389527 0.37389527
#[4,] 1.2724293 0.000000 0.35776475 0.35776475
#[5,] 0.4146414 0.000000 0.11658336 0.11658336
#attr(,"tau")
#[1] 1.55063
这篇关于lm(): LINPACK/LAPACK 中 QR 分解返回的 qraux 是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!