[R] error using "predict"

David Winsemius dwinsemius at comcast.net
Sun Jul 25 14:44:55 CEST 2010


On Jul 25, 2010, at 8:18 AM, Xebar Saram wrote:

> Hi
>
> I am very new to R (so excuse me in advance if this is pretty trivial)
>
> I am using the predict function to get prediction on a dataset from
> another dataset using the follwoing command:
>
> newpredT2003 = predict( object=out.model_T2003, newdata=aodmc_2003 ,  
> level = 0 )

I would have used interval="none" if my intent were to suppress  
calculation of confidence intervals. It's possible that setting levels  
to 0 would accomplish the same goal but I would need  examination of  
the code since the help page for predict.lm does not tell me whether  
level=0 is an acceptable alternative.

> yet i get this error:
>
> Error in na.fail.default(list(AOD = c(0.092, 0.081, 0.086, 0.085,  
> 0.09,  :
>  missing values in object
> Calls: predict ... model.frame.default -> <Anonymous> ->  
> na.fail.default

If you provide results of:

     str() on both the data.frames and ....

     show us the code that was used to create that model object, ...

.... it might be possible to answer this question. At the moment only  
those who possess mind-reading powers could provide any substantive  
help. (You should re-read the Posting Guide more thoroughly, since it  
should have been apparent from its reading that inclusion of more  
detailed information was expected of you.)

>
> i think its something simple but cant find any info when googling..can
> anyone point me in the right direction on what needs to be done to fix
> the errors?

As a general rule, the newdata object must be a data.frame containing  
only complete cases of all of the variables in the derivation dataset.  
It appears that you may be failing the "complete cases requirement"  
based on a cursory examination of the error message. This should have  
been clear from reading the help page for predict.

-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list