我使用rpart运行回归树
library(MASS)
N = 1000
episolon = rnorm(N, 0, 0.01)
x1 = rnorm(N, 0, sd=1)
x2 = rnorm(N, 0, sd=1)
eta_x = 1/2*x1+x2
Kappa_x = 1/2*x1
w = rbinom(N, 1, 0.5)
treatment = w
makeY = function(eta, Kappa){
Y = eta+1/2*(2*w-1)*Kappa+episolon
}
Y1 = makeY(eta_x, Kappa_x)
fit = rpart(Y1 ~ x1 + x2)
plot(fit)
text(fit)
我希望有一个函数给我这棵树有12片叶子