r - R Stargazer 将 p 值放入一行
问题描述
stargazer(model1, model2, title = "Models", header=FALSE,
dep.var.labels.include = FALSE,
column.labels = c("Count", "Percentage"),
style = "ajs",
report = "vcp*",
single.row = TRUE)
这是我用 stargazer 创建回归表的代码。但是,p 值仍然低于系数估计值。如何让 p 值显示在系数估计值旁边?
解决方案
您可以用 p 值替换标准误差。将模型放入列表中,这样您就可以使用lapply
.
model1 <- lm(mpg ~ hp, mtcars)
model2 <- lm(mpg ~ hp + cyl, mtcars)
model.lst <- list(model1, model2)
stargazer::stargazer(model.lst, title = "Models", header=FALSE,
dep.var.labels.include = FALSE,
column.labels = c("Count", "Percentage"),
style = "ajs",
report = "vcs*",
single.row = TRUE, type="text",
se=lapply(model.lst, function(x) summary(x)$coef[,4]))
# Models
# =================================================================
# Count Percentage
# 1 2
# -----------------------------------------------------------------
# hp -.068 (0.000)*** -.019 (.213)
# cyl -2.265 (0.000)***
# Constant 30.099 (0.000)*** 36.908 (0.000)***
# Observations 32 32
# R2 .602 .741
# Adjusted R2 .589 .723
# Residual Std. Error 3.863 (df = 30) 3.173 (df = 29)
# F Statistic 45.460*** (df = 1; 30) 41.422*** (df = 2; 29)
# -----------------------------------------------------------------
# Notes: *P < .05
# **P < .01
# ***P < .001
请注意,这也是可能的,texreg
它可能看起来更干净一些,并且包装维护得很好。
texreg::screenreg(model.lst, single.row=TRUE,
reorder.coef=c(2:3, 1),
custom.model.names=c("Count", "Percentage"),
override.se=lapply(model.lst, function(x) summary(x)$coef[,4]),
override.pvalues=lapply(model.lst, function(x) summary(x)$coef[,4]),
digits=3
)
# ===================================================
# Count Percentage
# ---------------------------------------------------
# hp -0.068 (0.000) *** -0.019 (0.213)
# cyl -2.265 (0.000) ***
# (Intercept) 30.099 (0.000) *** 36.908 (0.000) ***
# ---------------------------------------------------
# R^2 0.602 0.741
# Adj. R^2 0.589 0.723
# Num. obs. 32 32
# ===================================================
# *** p < 0.001; ** p < 0.01; * p < 0.05
推荐阅读
- python-3.x - Matplotlib 修复 y 轴
- java - 尝试在 Java 中实现 HTML 文件比较,但在 saxon 开始元素中出现 NULL 指针异常
- javascript - 如何在电子 + 反应环境中使用使用对话框?
- amazon-web-services - AWS CLI:描述没有“p-”前缀的策略
- javascript - 如何从 i18next 中获取更多调试信息?
- python - AttributeError:模块'cv2.cv2'在OpenCV中没有属性'faces'
- python - 如何用 Python AST 中的值替换变量名?
- python - 限制 Biopython NCBIWWW 搜索中的命中数
- java - 关闭应用程序时使用 WorkManager 不工作/不安排作业
- linux - bash,如何在出现 N 次分隔符后检索值?