[R] predict.tree

White.Denis@epamail.epa.gov White.Denis at epamail.epa.gov
Fri Mar 8 19:54:15 CET 2002


We are trying to implement Breiman's one standard deviation
pruning rule for tree models.  I have run into a problem with
predict.tree.

This bit of R code, a skeleton for a cross-validation process,

library (tree)
dat <- data.frame (matrix (runif (3*100), nrow=100, ncol=3))
a.dat <- dat[1:50,]
b.dat <- dat[51:100,]
a.tree <- tree (a.dat)
b.pred <- predict.tree (a.tree, newdata=b.dat, type="tree")

will produce the message,

> b.pred <- predict.tree (a.tree, newdata=b.dat, type="tree")
Error in as.list(X) : Object "response.names" not found

The offending lines in predict.tree seem to be,

    response.vars <- all.vars(formula(Terms)[[2]])
    response.exists <- sapply(response.names, function(nm,
      newdata) eval(local = newdata, substitute(exists(nm),
      list(nm = nm))), newdata)

When I changed "response.names" to "response.vars", the call to eval
failed, not recognizing parameter "local".  I could not understand
how to repair this.  When I replaced this code with
response.exists <- TRUE, then the tree variable output from
predict.tree seemed to be not well formed, because the residuals.tree
function produced this message, as did model.frame.tree,

> model.frame (b.pred)
Error in [.data.frame(structure(list(X1 = c(0.847547228412597,
0.683225137340656,  :
        invalid subscript type

Any guidance is much appreciated.

Denis White
   US EPA, 200 SW 35th St, Corvallis, Oregon, 97333 USA
   voice: 541.754.4476, email: white.denis at epa.gov
   web: www.epa.gov/wed/pages/staff/white/

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list