1

我正在尝试预测结果的频率,并且我有很多数据。我已经为数据安装了 glm,现在我正在尝试使用 ctree 来了解我可能错过的数据集中任何复杂的交互。

我没有直接预测残差,而是尝试将 ctree 模型偏移到 glm 预测。但是,当我执行以下操作时,我似乎得到了相同的结果:(a) 根本不使用偏移量,(b) 在函数中指定偏移量,以及 (c) 在 ctree 方程中使用偏移量。

我曾尝试查看文档(此处此处),但没有发现它有帮助。

我创建了一些虚拟数据来模仿我正在做的事情:

library(partykit)

# Set random number seed
set.seed(15)

# Create Dataset
freq <- rpois(10000, 1.2)
example_df <- data.frame(var_1 = rnorm(10000, 180, 20) * freq / 10,
                        var_2 = runif(10000, 1, 8),
                        var_3 = runif(10000, 1, 2.5) + freq / 1000)
example_df$var_4 = example_df$var_1 * example_df$var_3 + rnorm(10000, 0.1, 0.5)
example_df$var_5 = example_df$var_2 * example_df$var_3 + rnorm(10000, 2, 50)

# Create GLM
base_mod <- glm(freq ~ ., family="poisson", data=example_df)
base_pred <- predict(base_mod)

# Create trees
exc_offset <- ctree(freq ~ ., data = example_df, control = ctree_control(alpha = 0.01, minbucket = 1000))
func_offset <- ctree(freq ~ ., data = example_df, offset = base_pred, control = ctree_control(alpha = 0.01, minbucket = 1000))
equ_offset <- ctree(freq ~ . + offset(base_pred), data = example_df, control = ctree_control(alpha = 0.01, minbucket = 1000))

我预计当包含偏移量和不包含偏移量时,树的结果会有所不同。但是,输出似乎是相同的:

# Predict outcomes
summary(predict(exc_offset, example_df))
summary(predict(func_offset, example_df))
summary(predict(equ_offset, example_df))

# Show trees
exc_offset
func_offset
equ_offset

有谁知道发生了什么?我应该使用偏移量吗?

4

1 回答 1

0

ctree()算法不是基于线性预测器,因此不可能直接包含偏移量。ytrafo不过,可以使用基于模型的分数来包含偏移量。有关vignette("ctree", package = "partykit")更多详细信息,请参阅(也可在 CRAN 上的https://CRAN.R-project.org/web/packages/partykit/vignettes/ctree.pdf获得)。

然而,更自然的解决方案是使用带有glmtree()函数的基于 GLM 模型的树。我认为您尝试适应这棵树:

glmtree(freq ~ ., data = example_df, offset = base_pred, family = poisson,
  alpha = 0.01, minsize = 1000)

有关vignette("mob", package = "partykit")详细信息,请参阅(也可在 CRAN 上的https://CRAN.R-project.org/web/packages/partykit/vignettes/mob.pdf获得)。

但是,与其先估计偏移量然后再估计树一次,还可以很容易地迭代这个过程以获得更好的拟合。我们将这种 PALM 树(部分加性线性树)称为palmtree包中提供的 ( https://doi.org/10.1007/s11634-018-0342-1 )。

最后,我鼓励您探索哪些可用的协变量被用作:

  • 偏移量中的回归量(全局回归量)
  • 每个节点中的回归器(本地回归器)
  • 分裂变量

可能,当每个协变量的正确部分时,生成的模型可能更容易解释。

于 2019-07-18T23:36:43.537 回答