型号摘要:DV 名称和型号名称同时在不同的行中?
Modelsummary: DV names and Model Names at the same time in differen rows?
我想知道如何使用 modelsummary 来组合模型名称和 DV 名称,就像在 Stata 的 outreg2 中一样?这是代表:
url <- 'https://vincentarelbundock.github.io/Rdatasets/csv/HistData/Guerry.csv'
dat <- read.csv(url)
models <- list(
"OLS 1" = lm(Donations ~ Literacy + Clergy, data = dat),
"Poisson 1" = glm(Donations ~ Literacy + Commerce, family = poisson, data = dat),
"OLS 2" = lm(Crime_pers ~ Literacy + Clergy, data = dat),
"Poisson 2" = glm(Crime_pers ~ Literacy + Commerce, family = poisson, data = dat),
"OLS 3" = lm(Crime_prop ~ Literacy + Clergy, data = dat)
)
modelsummary(models)
#N: DV names
modelsummary(dvnames(models), output = "flextable", estimate="{estimate}{stars}",
statistic = 'statistic', stars = c('*' = .1, '**' = .05, '***'=0.01))
#N: Model names
modelsummary(models, output = "flextable", estimate="{estimate}{stars}",
statistic = 'statistic', stars = c('*' = .1, '**' = .05, '***'=0.01))
以下是 DV 和模型名称组合 table 在 Stata 中 outreg2
中的显示方式:
如有任何信息或建议,我们将不胜感激!
您可以 use the add_rows
argument 并创建自己的自定义函数来自动执行该过程:
library(modelsummary)
insert_row <- function(x) {
out <- c("DV:", names(dvnames(x)))
out <- data.frame(as.list(out))
attr(out, "position") <- 0
return(out)
}
mod <- list(
lm(mpg ~ hp, mtcars),
lm(vs ~ hp, mtcars))
modelsummary(mod, add_rows = insert_row(mod))
Model 1
Model 2
DV:
mpg
vs
(Intercept)
30.099
1.217
(1.634)
(0.150)
hp
-0.068
-0.005
(0.010)
(0.001)
Num.Obs.
32
32
R2
0.602
0.523
R2 Adj.
0.589
0.507
AIC
181.2
28.3
BIC
185.6
32.7
Log.Lik.
-87.619
-11.134
F
45.460
32.876
我想知道如何使用 modelsummary 来组合模型名称和 DV 名称,就像在 Stata 的 outreg2 中一样?这是代表:
url <- 'https://vincentarelbundock.github.io/Rdatasets/csv/HistData/Guerry.csv'
dat <- read.csv(url)
models <- list(
"OLS 1" = lm(Donations ~ Literacy + Clergy, data = dat),
"Poisson 1" = glm(Donations ~ Literacy + Commerce, family = poisson, data = dat),
"OLS 2" = lm(Crime_pers ~ Literacy + Clergy, data = dat),
"Poisson 2" = glm(Crime_pers ~ Literacy + Commerce, family = poisson, data = dat),
"OLS 3" = lm(Crime_prop ~ Literacy + Clergy, data = dat)
)
modelsummary(models)
#N: DV names
modelsummary(dvnames(models), output = "flextable", estimate="{estimate}{stars}",
statistic = 'statistic', stars = c('*' = .1, '**' = .05, '***'=0.01))
#N: Model names
modelsummary(models, output = "flextable", estimate="{estimate}{stars}",
statistic = 'statistic', stars = c('*' = .1, '**' = .05, '***'=0.01))
以下是 DV 和模型名称组合 table 在 Stata 中 outreg2
中的显示方式:
如有任何信息或建议,我们将不胜感激!
您可以 use the add_rows
argument 并创建自己的自定义函数来自动执行该过程:
library(modelsummary)
insert_row <- function(x) {
out <- c("DV:", names(dvnames(x)))
out <- data.frame(as.list(out))
attr(out, "position") <- 0
return(out)
}
mod <- list(
lm(mpg ~ hp, mtcars),
lm(vs ~ hp, mtcars))
modelsummary(mod, add_rows = insert_row(mod))
Model 1 | Model 2 | |
---|---|---|
DV: | mpg | vs |
(Intercept) | 30.099 | 1.217 |
(1.634) | (0.150) | |
hp | -0.068 | -0.005 |
(0.010) | (0.001) | |
Num.Obs. | 32 | 32 |
R2 | 0.602 | 0.523 |
R2 Adj. | 0.589 | 0.507 |
AIC | 181.2 | 28.3 |
BIC | 185.6 | 32.7 |
Log.Lik. | -87.619 | -11.134 |
F | 45.460 | 32.876 |