[R] varaince explined of a regression tree using ctree

Patrick Breheny patrick.breheny at uky.edu
Tue Dec 6 21:51:46 CET 2011


On 12/06/2011 03:05 PM, Antonio Punzon Merino wrote:
> I would like know the way to calculate the variance explained of a
> regression tree. I use the function "ctree" from library "party"

ctree does not provide this information by default, but it is not 
difficult to calculate:

X <- matrix(rnorm(100*10),ncol=10)
y <- X%*%c(rep(2,5),rep(0,5))+rnorm(100)
fit <- ctree(y~.,data=as.data.frame(X))
r <- y - predict(fit)
1-var(r)/var(y)

-- 
Patrick Breheny
Assistant Professor
Department of Biostatistics
Department of Statistics
University of Kentucky



More information about the R-help mailing list