Bug 14817 - predict.lm(*, terms) bug
predict.lm(*, terms) bug
Status: CLOSED FIXED
Product: R
Classification: Unclassified
Component: Analyses
R 2.14.1
All All
: P5 normal
Assigned To: R-core
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-02-16 13:27 UTC by Martin Maechler
Modified: 2014-02-16 11:43 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Maechler 2012-02-16 13:27:26 UTC
[cut & paste from an e-mail to R-core:]

To: R Core Team <R-core@....>
Subject: Bug in stats predict.lm function
Date: Tue, 14 Feb 2012 11:26:22 +0100
I use the convenient function termplot and am working on some added
functionality. While doing this I noticed this bug:

Error in predict.lm(model, type = "terms", se.fit = se, terms = terms) :
  subscript out of bounds

This error comes when running the following simple code:

library(datasets)
fit <- lm(mpg~disp+hp+wt+drat, data=mtcars)
termplot(fit, terms=2, se=T)

The problem is due to an error at the bottom of the predict.lm function:

...
    if (se.fit || interval != "none") {
        se <- sqrt(ip)
        if (type == "terms" && !is.null(terms))
            se <- se[, terms, drop = FALSE]
    }
....

The se variable has only one dimension, the if(type=="terms" &&
!is.null(terms)) should probably be left out since it is done in a
previous step:
...
            if (!is.null(terms)) {
                predictor <- predictor[, terms, drop = FALSE]
                if (se.fit)
                    ip <- ip[, terms, drop = FALSE]
            }
....

Regards
Max Gordon
Comment 1 Jackie Rosen 2014-02-16 11:43:43 UTC
(spam comment removed)