| prune.modelparty {partykit} | R Documentation |
modelparty objects.This function allows for post pruning of modelparty objects. Not thate this is usually not neccessary if p-values are used for stopping.
## S3 method for class 'modelparty' prune(tree, type = "AIC", ...)
tree |
object of class |
type |
pruning type. Can be |
... |
additional arguments. |
type can be set to a function(objfun, df, nobs)
which either returns TRUE to signal that a current node can be pruned
or FALSE. All supplied arguments are of length two: objfun is the sum of objective
function values in the current node and its child nodes, respectively.
df is the degrees of freedom in the current node and its child nodes,
respectively. nobs is vector with the number of observations in the
current node and the total number of observations in the dataset, respectively.
An object of class modelparty that is smaller or equal the original.
Heidi Seibold
set.seed(29)
n <- 1000
x <- runif(n)
z <- runif(n)
y <- rnorm(n, mean = x * c(-1, 1)[(z > 0.7) + 1], sd = 3)
z_noise <- factor(sample(1:3, size = n, replace = TRUE))
d <- data.frame(y = y, x = x, z = z, z_noise = z_noise)
fmla <- as.formula("y ~ x | z + z_noise")
## glm versus lm / logLik versus sum of squared residuals
lm_big <- lmtree(formula = fmla, data = d, maxdepth = 2, alpha = 1)
glm_big <- glmtree(formula = fmla, data = d, maxdepth = 2, alpha = 1)
AIC(lm_big)
AIC(glm_big)
## pruning
lm_aic <- prune(lm_big, type = "AIC")
lm_bic <- prune(lm_big, type = "BIC")
width(lm_big)
width(lm_aic)
width(lm_bic)
glm_aic <- prune(glm_big, type = "AIC")
glm_bic <- prune(glm_big, type = "BIC")
width(glm_big)
width(glm_aic)
width(glm_bic)