[R] Bug in predict.lm?

Toth, Denes tdenes at cogpsyphy.hu
Fri Nov 15 23:32:34 CET 2013


The same problem appears on a 64-bit linux:
platform       x86_64-pc-linux-gnu
arch           x86_64
os             linux-gnu
system         x86_64, linux-gnu
status
major          3
minor          0.2
year           2013
month          09
day            25
svn rev        63987
language       R
version.string R version 3.0.2 (2013-09-25)
nickname       Frisbee Sailing

After dputting the predict.lm function (traceback etc. did not give a hint
on the source of the error message) I could locate the invalid call at
around the 70-80th rows of the function:

...
        if (type != "terms") {
            if (p > 0) {
                XRinv <- if (missing(newdata) && is.null(w))
                    qr.Q(qr.lm(object))[, p1, drop = FALSE]
                else X[, piv] %*% qr.solve(qr.R(qr.lm(object))[p1,
                                                               p1])
                ip <- drop(XRinv^2 %*% rep(res.var, p))
            }  else ip <- rep(0, n)
        }
...

Here ...&& is.null(w)... causes the troubles.




> Bert Gunter <gunter.berton <at> gene.com> writes:
>
>>
>> Yes, I realize that it is more likely  a misunderstanding on my part.
>> Suitable humility will be tendered if this is pointed out.
>>
>> The claimed "bug" is that predict.lm throws an error when the scale
>> argument is specified with interval = "conf" (and in some other
>> cases):
>>
>> > z <- lm(rnorm(10)~I(1:10))
>>
>> > predict(z,int="conf",scale=1)
>> Error in predict.lm(z, int = "conf", scale = 1) : object 'w' not found
>>
>> R version 3.0.2 (2013-09-25)
>> Platform: i386-w64-mingw32/i386 (32-bit)
>>
>> Cheers,
>> Bert
>>
>
> I do not see this (see below).
>
> Maybe traceback() or options(recover=browser) to get
> to the bottom??
>
>
>
>> z <- lm(rnorm(10)~I(1:10))
>> predict(z,int="conf",scale=1)
>           fit        lwr       upr
> 1  0.02491723 -1.1270591 1.1768935
> 2  0.06402057 -0.9129873 1.0410284
> 3  0.10312392 -0.7185606 0.9248085
> 4  0.14222726 -0.5569958 0.8414504
> 5  0.18133060 -0.4477852 0.8104464
> 6  0.22043395 -0.4086818 0.8495497
> 7  0.25953729 -0.4396858 0.9587604
> 8  0.29864063 -0.5230439 1.1203252
> 9  0.33774398 -0.6392639 1.3147518
> 10 0.37684732 -0.7751290 1.5288236
>> version
>                _
> platform       x86_64-apple-darwin10.8.0
> arch           x86_64
> os             darwin10.8.0
> system         x86_64, darwin10.8.0
> status
> major          3
> minor          0.2
> year           2013
> month          09
> day            25
> svn rev        63987
> language       R
> version.string R version 3.0.2 (2013-09-25)
> nickname       Frisbee Sailing
>>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list