[R] bug in rpart?

From: X. Li <xl_goskins_at_yahoo.com>
Date: Wed 15 Jun 2005 - 05:30:08 EST


Dear R-helpers,

Can you help me to see why "code 1" gives error while "code 2" runs fine? The only difference in the data is the distribution of age categories. I am attaching the session after the code.

Many thanks.

XL

library(survival)
library(rpart)
# code 1
n <- 20
age <- rep(1:3, c(2, 3, 15))
eg<- data.frame(rexp(n), rbinom(n,1,prob=.3), age=age)                      

names(eg) <- c("surv", "status", "age")
rpart(Surv(surv, status)~age, data=eg)

# code 2
n <- 20
age <- rep(1:3, c(5, 5, 10))
eg<- data.frame(rexp(n), rbinom(n,1,prob=.3), age=age)                      

names(eg) <- c("surv", "status", "age")
rpart(Surv(surv, status)~age, data=eg)

# my session:

> library(rpart)
> # code 1
> n <- 20
> age <- rep(1:3, c(2, 3, 15))
> eg<- data.frame(rexp(n), rbinom(n,1,prob=.3),
age=age)
> names(eg) <- c("surv", "status", "age")
> rpart(Surv(surv, status)~age, data=eg)
Error in "$<-.data.frame"(`*tmp*`, "yval2", value = c(1, 7)) :

        replacement has 2 rows, data has 1
>
> # code 2
> n <- 20
> age <- rep(1:3, c(5, 5, 10))
> eg<- data.frame(rexp(n), rbinom(n,1,prob=.3),
age=age)
> names(eg) <- c("surv", "status", "age")
> rpart(Surv(surv, status)~age, data=eg)
n= 20

node), split, n, deviance, yval


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 Wed Jun 15 05:33:19 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:38 EST