Conditional Regresion Tree in R

In [2]:
# Conditional Decision Trees

# load the package
library(party)

# load data
data(longley)

# fit model
fit <- ctree(Employed~., data=longley, controls=ctree_control(minsplit=2,minbucket=2,testtype="Univariate"))

# summarize the fit
print(fit)

# make predictions
predictions <- predict(fit, longley[,1:6])

# summarize accuracy
mse <- mean((longley$Employed - predictions)^2)
print(mse)
	 Conditional inference tree with 4 terminal nodes

Response:  Employed 
Inputs:  GNP.deflator, GNP, Unemployed, Armed.Forces, Population, Year 
Number of observations:  16 

1) GNP <= 365.385; criterion = 1, statistic = 14.511
  2) GNP <= 284.599; criterion = 0.99, statistic = 6.555
    3)*  weights = 4 
  2) GNP > 284.599
    4)*  weights = 4 
1) GNP > 365.385
  5) GNP <= 444.546; criterion = 0.984, statistic = 5.832
    6)*  weights = 4 
  5) GNP > 444.546
    7)*  weights = 4 
[1] 0.4776895