partykit:修改终端节点以包括标准偏差和回归变量的重要性 [英] partykit: Modify terminal node to include standard deviation and significance of regressors

查看:44
本文介绍了partykit:修改终端节点以包括标准偏差和回归变量的重要性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

以下代码来自 partykit

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

谢谢.

解决方案

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

  mysummary<-函数(信息,数字= 2){n<-info $标记na<-format(名称(coef(info $ object)))cf<-format(coef(info $ object),digits = digits)se<-format(sqrt(diag(vcov(info $ object))),数字=数字)c(paste("n =",n),估计的参数:",粘贴(na,cf,se))} 

基于此,您将得到:

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

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

I would like to be able to personalize the plot that it is displayed to include standard deviation and statistical significance of the regressors after using the partykit::mob() function.

The following code is from partykit documentation.

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)
}

This is what it is produced:

And this is what I would like to get (for all the nodes).

Thanks in advance.

解决方案

When using the node_terminal() function for visualizing the information within the terminal nodes, you can plug in a function FUN that customizes and formats the information. The input to FUN is the $info from the respective terminal node which for mob trees includes the fitted model $object. The output should be a character vector. As an example consider this custom summary:

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)
  )
}

Based on this you get:

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

This just shows coefficients and standard errors - but you can add significance stars or any other information you like. However, you need to do all the formatting yourself in the custom FUN.

这篇关于partykit:修改终端节点以包括标准偏差和回归变量的重要性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆