r - 将列表中的 probitmfx 输出提供给 Stargazer
问题描述
与此处类似,我正在使用 tidyr 对子组(年份和组的所有组合)进行一系列回归。
year <- rep(2014:2015, length.out = 10000)
group <- sample(c(0,1,2,3,4,5,6), replace=TRUE, size=10000)
value <- sample(10000, replace = T)
female <- sample(c(0,1), replace=TRUE, size=10000)
smoker <- sample(c(0,1), replace=TRUE, size=10000)
dta <- data.frame(year = year, group = group, value = value, female=female, smoker = smoker)
library(dplyr)
library(broom)
library(stargazer)
# create list of dfs
table_list <- dta %>%
group_by(year, group) %>%
group_split()
# apply the model to each df and produce stargazer result
model_list <- lapply(table_list, function(x) probitmfx(smoker ~ female, data = x))
stargazer(model_list, type = "text")
我收到一条错误消息
% Error: Unrecognized object type.
有人知道我该如何解决这个问题吗?
解决方案
正如 Colin 在评论中指出的那样,这种类型的模型似乎不受stargazer
. 但是,它由modelsummary
包提供开箱即用的支持(免责声明:我是作者)。
您可以完全省略该output
参数以获得漂亮的 HTML 表格,或更改它以将表格保存为 LaTeX、Word 或许多其他格式。
# Code from the original question
library(mfx)
library(dplyr)
year <- rep(2014:2015, length.out = 10000)
group <- sample(c(0,1,2,3,4,5,6), replace=TRUE, size=10000)
value <- sample(10000, replace = T)
female <- sample(c(0,1), replace=TRUE, size=10000)
smoker <- sample(c(0,1), replace=TRUE, size=10000)
dta <- data.frame(year = year, group = group, value = value, female=female, smoker = smoker)
table_list <- dta %>%
group_by(year, group) %>%
group_split()
model_list <- lapply(table_list, function(x) probitmfx(smoker ~ female, data = x))
# New code
library(modelsummary)
modelsummary(model_list, output = "markdown")
模型 1 | 模型 2 | 模型 3 | 模型 4 | 型号 5 | 型号 6 | 型号 7 | 型号 8 | 型号 9 | 型号 10 | 型号 11 | 型号 12 | 型号 13 | 型号 14 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
女性 | 0.022 | -0.026 | -0.033 | 0.013 | -0.030 | -0.001 | -0.003 | -0.073 | 0.006 | -0.041 | 0.075 | -0.006 | -0.009 | 0.023 |
(0.039) | (0.038) | (0.036) | (0.037) | (0.037) | (0.038) | (0.037) | (0.038) | (0.036) | (0.038) | (0.037) | (0.038) | (0.037) | (0.038) | |
数量。 | 670 | 688 | 761 | 727 | 740 | 675 | 739 | 688 | 751 | 703 | 733 | 710 | 737 | 678 |
AIC | 932.4 | 957.3 | 1058.1 | 1009.6 | 1029.2 | 939.7 | 1027.6 | 953.8 | 1044.9 | 977.4 | 1016.0 | 988.2 | 1025.6 | 943.5 |
BIC | 941.4 | 966.4 | 1067.4 | 1018.8 | 1038.4 | 948.7 | 1036.8 | 962.9 | 1054.1 | 986.5 | 1025.2 | 997.4 | 1034.8 | 952.5 |
日志。 | -464.206 | -476.648 | -527.074 | -502.806 | -512.588 | -467.837 | -511.809 | -474.924 | -520.425 | -486.682 | -506.004 | -492.123 | -510.810 | -469.740 |
推荐阅读
- python-3.x - 在 python 中解码时,85 位编码的字符串没有被正确处理
- ios - 相关的 ViewController 应该显示来自 Cell 的标签
- rust - 如何在我的源代码之外存储格式字符串模板?
- html - 带顺序的引导响应 div
- css - 试图让这个开关改变页面的背景颜色
- delphi - 展开该节点时如何更改 TVirtualStringTree 节点图标
- javascript - Asp.net MVC ajax 在模态中提交表单
- c++ - 如何找出二进制文件中使用的 C++ 标准?
- wxpython - RichTextCtrl 的 PositionToCoords
- c - 与零进行比较的 64 位整数更快的方法