lm(): What is qraux returned by QR decomposition in LINPACK / LAPACK

前端 未结 1 1725
攒了一身酷
攒了一身酷 2020-12-07 03:17

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

相关标签:
1条回答
  • 2020-12-07 03:30

    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.


    Householder reflection matrix

    Householder transformation

    Householder QR factorization (without pivoting)

    Compact storage of QR and rescaling


    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)
    

    my function gives:

    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
    
    0 讨论(0)
提交回复
热议问题