Re: [R] Rpart -- using predict() when missing data is present?

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Sun 09 Oct 2005 - 04:07:32 EST

On Sat, 8 Oct 2005, Ajay Narottam Shah wrote:

> I am doing
>
>> library(rpart)
>> m <- rpart("y ~ x", D[insample,])
>> D[outsample,]
> y x
> 8 0.78391922 0.579025591
> 9 0.06629211 NA
> 10 NA 0.001593063
>> p <- predict(m, newdata=D[9,])
> Error in model.frame(formula, rownames, variables, varnames, extras, extranames, :
> invalid result from na.action
>
> How do I persuade him to give me NA since x is NA?

I think the point is to do something sensible! One x prediction problems are not what rpart is designed to do, and the default na.action (na.rpart) fails in that case. (The author forgot drop=F.)

> I looked at ?predict.rpart but didn't find any mention about NAs.

How about ?rpart ? That does.

> (In this problem, I can easily do it manually, but this is a part of
> something bigger where I want him to be able to gracefully handle
> prediction requests involving NA).

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Sun Oct 09 04:25:07 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 18:32:58 EST