繁体   English   中英

在 R 中显示置信区间和非标准化系数

[英]displaying confidence intervals and not standardized coefficients in R

我有这段代码显示标准化系数而不是置信区间。 我怎样才能显示 CI? 我看到的一些例子与图表有点不同


library(nycflights13)
library(dplyr)
library(dotwhisker)
library(MASS)

flights <- nycflights13::flights
flights<- sample_n (flights, 500)

m1<- glm(formula = arr_delay ~ dep_time + origin+ air_time+ distance , data = flights)
#m1<- glm(formula = arr_delay ~ . , data = flights)

m1<- stepAIC(m1)
  p<- dotwhisker::dwplot(m1)
  z<- p + 
    geom_vline(xintercept=0, linetype="dashed")+
    geom_segment(aes(x=conf.low,y=term,xend=conf.high,
                     yend=term,col=p.value<0.05)) + 
    geom_point(aes(x=estimate,y=term,col=p.value<0.05)) +
  xlab("standardized coefficient") + 
  ylab("coefficient") +
  ggtitle("coefficients in the model and significance")
  print(z)

我想您可以直接从 model 获得您正在寻找的东西,而无需使用dotwhisker 问题在于,由于它们没有标准化,原始置信区间相差几个数量级,并且在单个 plot 上显示效果不佳。

df1 <- as.data.frame(coefficients(summary(m1)))
df1$variable <- rownames(df1)
df1$lower <- df1$Estimate - 1.96 * df1$`Std. Error`
df1$upper <- df1$Estimate + 1.96 * df1$`Std. Error`

ggplot(df1, aes(Estimate, variable, color = `Pr(>|t|)` < 0.05)) +
  geom_segment(aes(yend = variable, x = lower, xend = upper)) +
  geom_point() +
  geom_vline(xintercept = 0, lty = 2)

在此处输入图像描述

dotwhisker采用标准化系数和置信区间的by_2sd参数; 将其设置为FALSE会给出未标准化的系数。 由于许多人对此行为感到困惑,package (0.6) 的最新版本默认执行此操作

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM