【问题标题】:partykit: Modify terminal node to include standard deviation and significance of regressorspartykit:修改终端节点以包括回归量的标准差和显着性
【发布时间】:2021-04-06 06:29:10
【问题描述】:

在使用partykit::mob() 函数后,我希望能够个性化显示的图,以包括回归变量的标准差和统计显着性。

以下代码来自partykitdocumentation

library("partykit")
if(require("mlbench")) {
  ## Pima Indians diabetes data
  data("PimaIndiansDiabetes", package = "mlbench")
  ## a simple basic fitting function (of type 1) for a logistic regression
  logit <- function(y, x, start = NULL, weights = NULL, offset = NULL, ...) {
    glm(y ~ 0 + x, family = binomial, start = start, ...)
  }
  ## set up a logistic regression tree
  pid_tree <- mob(diabetes ~ glucose | pregnant + pressure + triceps + insulin +
                    mass + pedigree + age, data = PimaIndiansDiabetes, fit = logit)
  ## see lmtree() and glmtree() for interfaces with more efficient fitting functions
  ## print tree
  print(pid_tree)
  ## print information about (some) nodes
  print(pid_tree, node = 3:4)
  ## visualization
  plot(pid_tree,terminal_panel = NULL)
}

它是这样产生的:

这就是我想要得到的(对于所有节点)。

提前致谢。

【问题讨论】:

    标签: r tree decision-tree party


    【解决方案1】:

    当使用node_terminal() 函数来可视化终端节点内的信息时,您可以插入一个函数FUN 来自定义和格式化信息。 FUN 的输入是来自各自终端节点的 $info,对于 mob 树包括拟合模型 $object。输出应该是一个字符向量。作为示例,请考虑以下自定义摘要:

    mysummary <- function(info, digits = 2) {
      n <- info$nobs
      na <- format(names(coef(info$object)))
      cf <- format(coef(info$object), digits = digits)
      se <- format(sqrt(diag(vcov(info$object))), digits = digits)
      c(paste("n =", n),
        "Estimated parameters:",
        paste(na, cf, se)
      )
    }
    

    基于此你得到:

    plot(pid_tree,
      terminal_panel = node_terminal,
      tp_args = list(FUN = mysummary))
    

    这仅显示系数和标准误差 - 但您可以添加重要性星或您喜欢的任何其他信息。但是,您需要在自定义 FUN 中自行完成所有格式设置。

    【讨论】:

    • 这是一个非常好的答案@AchimZeileis,非常感谢你。我想我将包括 t 比率,以避免与星星内含物发生不必要的并发症。不幸的是,在我的例子中,我的回归量具有非常不同的名称长度。您认为有可能证明文本的合理性,以便为端节点提供更 table-like 视图?我创建了another question,在那里我更好地解释了我想要的输出,以防你能帮助我。非常感谢您的宝贵时间。
    猜你喜欢
    • 2015-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-23
    • 2022-10-09
    • 2021-04-06
    • 1970-01-01
    相关资源
    最近更新 更多