Re: [R] rpart plot question

From: John Field <JohnField_at_ozemail.com.au>
Date: Thu 11 Aug 2005 - 19:41:53 EST


Petr Pikal wrote:

Dear all

I am quite confused by rpart plotting. Here is example.

set.seed(1)

y <- (c(rnorm(10), rnorm(10)+2, rnorm(10)+5))

x <- c(rep(c(1,2,5), c(10,10,10))

fit <- rpart(x~y) ## NB should be y~x

plot(fit)

text(fit)

Text on first split says x < 3.5 and on the second split x < 1.5 what

I understand:

If x < 3.5 so y is lower and y values go to the left split. OK. But,

sometimes there is

whatever >= nnn and it seems to me that if this condition is true

response variable follow to right split.

try:

y1<-(c(rnorm(10)+5,rnorm(10)+2, rnorm(10)))

fit<-rpart(y1~x)

plot(fit)

text(fit)

Well, I am not sure I express myself clearly. Am I correct that

when there is < sign I shall follow left node but when there is >=

sign I shall follow the right one?

Best regards

Petr Pikal

Petr Pikal

<https://stat.ethz.ch/mailman/listinfo/r-help>petr.pikal at precheza.cz If instead of rpart you use mvpart, ie

library(mvpart)
fit <- mvpart(y~x, data=data.frame(cbind(x,y))) plot(fit)
text.rpart(fit,which=4)

then the plot will be much clearer about the condition for splits.

summary(fit) will also help.

Regards,
John



John Field Consulting Pty Ltd
10 High St, Burnside SA 5066, Australia
ph: +61 8 8332 5294 or +61 409 097 586
fax: +61 8 8332 1229
email: JohnField@ozemail.com.au



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 Thu Aug 11 19:48:17 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 15:13:58 EST