From tomas.larsson at usaa.com  Thu Dec 10 17:50:09 2009
From: tomas.larsson at usaa.com (tomas.larsson at usaa.com)
Date: Thu, 10 Dec 2009 17:50:09 +0100 (CET)
Subject: [Rd] Using predict on a model with NA as a level (PR#14127)
Message-ID: <20091210165009.C19B5282EFCA@mail.pubhealth.ku.dk>

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



[Rd] Using predict on a model with NA as a level (PR#14127)
tomas.larsson at usaa.com