[Rd] Using predict on a model with NA as a level (PR#14127)

From: <tomas.larsson_at_usaa.com>
Date: Thu, 10 Dec 2009 17:50:09 +0100 (CET)


Full_Name: Tomas Larsson
Version: 2.8.0
OS: Windows XP
Submission from: (NULL) (167.24.24.150)

There appears to be a problem with using predict on a data set when NA has been specified as a level in the model, see example below.

> # generate some data
> x<-matrix(,10,2)
> x[,1]<-c(numeric(5),numeric(5)+1)
> x[,2]<-c(0,0,NA,0,1,1,0,NA,1,1)
> x<-as.data.frame(x)
> # add NA as a level in the model
> x[,2]<-addNA(x[,2])
> m<-glm(data=x,formula=V1~V2)
> #works
> predict(m)

   1 2 3 4 5 6 7 8 9 10 0.25 0.25 0.50 0.25 0.75 0.75 0.25 0.50 0.75 0.75
> # does not work to use predict when using the new data option
> predict(m,newdata=x)

Error in drop(X[, piv, drop = FALSE] %*% beta[piv]) :   subscript out of bounds



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 10 Dec 2009 - 20:10:16 GMT

This archive was generated by hypermail 2.2.0 : Thu 10 Dec 2009 - 21:01:06 GMT