[R] library(rpart) or library(tree)

From: Ingo Holz <Ingo.Holz_at_uni-hohenheim.de>
Date: Wed, 19 Dec 2007 17:14:45 +0100


 I have a problem with library (rpart) (and/or library(tree)).

 I use a data.frame with variables
"pnV22" (observation: 1, 0 or yes, no)
"JTemp" (mean temperature)
"SNied" (summer rain)

 I used function "rpart" to build a model:

	result <- rpart(pnV22 ~ JTemp + SNied)

 I got the following tree:

  n=55518 (50 observations deleted due to missingness)

node), split, n, deviance, yval

 I constructed a simple new.data.frame:

     new.data.fame <- data.frame
     new.data.frame[,"JTemp"] <- 10.5
     new.data.frame[,"SNied"] <- 430

Than I used predict() to predict values for "pnV22" in the following way:

    pred <- predict(result, data.frame)
    pred2 <- predict(result, new.data.frame)

The results are the same, which I checked by ploting the values of pred and pred2 and by

   table(pred ==pred2) which is true for all values.

Looking at the tree I would expect that pred2 has the same high value for all elements of the vector. Did I make a mistake?

Thanks, Ingo

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 19 Dec 2007 - 16:24:33 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 19 Dec 2007 - 22:30:19 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.