QR decomposition different in lm and biglm?

后端 未结 1 553
轮回少年
轮回少年 2021-01-14 04:31

I\'m trying to recover the R matrix from the QR decomposition used in biglm. For this I am using a portion of the code in vcov.biglm and put it into a function like so:

1条回答
  •  别那么骄傲
    2021-01-14 04:59

    The difference between the two R matrices is that biglm apparently performs its rotations such that R's diagonal elements are all positive, while lm (or, really, the routines it calls) imposes no such constraint. (There should be no numerical advantage to one strategy or the other, so the difference is just one of convention, AFAIKT.)

    You can make lm's results identical to biglm's by imposing that additional constraint yourself. I'd use a reflection matrix that multiplies columns by either 1 or -1, such that the diagonal elements all end up positive:

    ## Apply the necessary reflections
    R.lm2 <- diag(sign(diag(R.lm))) %*% R.lm
    
    ## Show that they did the job
    mean(R.lm2 - R.biglm < 1e-6)
    # [1] 1
    

    0 讨论(0)
提交回复
热议问题