[R] rpart$where and predict.rpart

Chua Siang Li siang.li.chua at acceval-intl.com
Wed Jul 23 05:09:23 CEST 2008

   Brian, thanks for the prompt reply.
   I am quite new to R and have no clue on how to call internal function.
   Tried the following but failed:
   > .Internal("pred.rpart")
   Error in .Internal("pred.rpart") : invalid .Internal() argument
   > .Internal()
   Error in .Internal() : 0 arguments passed to '.Internal' which requires 1
   > .Primitive("pred.rpart")
   Error in .Primitive("pred.rpart") : no such primitive function
   > .Primitive("rpart-internal")
   Error in .Primitive("rpart-internal") : no such primitive function
   So, I copy the whole source code into my codes
   pred.rpart <- function(fit, x) {

       frame <- fit$frame
       nc <- frame[, c('ncompete', 'nsurrogate')]
   but still have error msg:
   >   where <- pred.rpart(mod, newdata=as.matrix(xLost))
   Error in pred.rpart(mod, newdata = as.matrix(xLost)) :
     unused argument(s) (newdata = c("1335.0", "1335.0", "1335.0", "1335.0",
   Btw, my predict function is ok.
   >  predictLost <- predict(mod, newdata=data.frame(y=yLost, x=xLost))
   Chua Siang Li
   Consultant - Operations Research
   Acceval Pte Ltd
   Tel: 6297 8740
   Email: siang.li.chua at acceval-intl.com
   Website: www.acceval-intl.com
   This  message and any attachments (the "message") are intended for the
   designated recipient only and may contain information that is confidential
   and privileged. If you are not the intended recipient, please notify the
   sender and delete all its contents. Any use , reliance on, reference to,
   review  ,  disclosure or copying of the message and the information it
   contains is prohibited.

   --------- Original Message --------
   From: "Prof Brian Ripley" <ripley at stats.ox.ac.uk>
   To: "Chua Siang Li" <siang.li.chua at acceval-intl.com>
   Cc: r-help at r-project.org
   Subject: Re: [R] rpart$where and predict.rpart
   Date: 07/22/08 18:51
   On Tue, 22 Jul 2008, Chua Siang Li wrote:
   > Hello there. I have fitted a rpart model.
   > > rpartModel <- rpart(y~., data=data.frame(y=y,x=x),method="class", ....)
   > and can use rpart$where to find out the terminal nodes that each
   > observations belongs.
   > Now, I have a set of new data and used predict.rpart which seems to give
   > only the predicted value with no information similar to rpart$where.
   > May I know how to find out the terminal nodes that each new observations
   > belongs to?
   You need to read the code to answer questions about internals. A very
   quick glance at predict.rpart would have told you that
   where <- pred.rpart(object, rpart.matrix(newdata))
   is what you are looking for. (Note that pred.rpart like many other
   internal functions is not exported from the name space.)
   > Many thanks.
   > ----
   > Chua Siang Li
   > Consultant - Operations Research
   > Acceval Pte Ltd
   > Tel: 6297 8740
   > Email: [1]siang.li.chua at acceval-intl.com
   > Website: [2]www.acceval-intl.com
   Brian D. Ripley, [3]ripley at stats.ox.ac.uk
   Professor of Applied Statistics, [4]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


   1. mailto:siang.li.chua at acceval-intl.com
   2. http://www.acceval-intl.com/
   3. mailto:ripley at stats.ox.ac.uk
   4. http://www.stats.ox.ac.uk/~ripley/

More information about the R-help mailing list