Bug 16256 - bug in predict with type="terms" in the presence of missing
Summary: bug in predict with type="terms" in the presence of missing
Status: NEW
Alias: None
Product: R
Classification: Unclassified
Component: Models (show other bugs)
Version: R 3.1.2
Hardware: All All
: P5 minor
Assignee: R-core
URL:
Depends on:
Blocks: 16258
  Show dependency treegraph
 
Reported: 2015-03-12 17:25 UTC by Antonio Gasparrini
Modified: 2015-03-14 07:09 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Antonio Gasparrini 2015-03-12 17:25:06 UTC
The method predict() for classes lm and glm with the argument type="terms" returns a matrix of term components. This matrix is expected to include an attribute 'constant'.
However, when the model is fitted with a na.action such as "na.exclude", this attribute is not included.
The error is likely to be generated by a call to napredict() within the function predict.lm(). This call re-inserts the missing values of the term matrix, preserving the original dimensionality, but also causes the additional attributes, such as 'constant', to be erased.

A simple example:

y <- rnorm(10)
x <- 1:10
x[3] <- NA

m <- lm(y~x)
predict(m,type="terms")

m1 <- update(m,na.action="na.exclude")
predict(m1,type="terms")