Modelsummary:估计和统计的不同格式
Modelsummary: Different formats for estimates and statistics
首先感谢 modelsummary 包的创建者 -- 非常有用!
我对统计和估计的不同 fmt
有疑问?这是一个代表:
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)
modelsummary(models, output = "flextable", estimate=glue_col("{estimate}{stars}"),
statistic = 'statistic', stars = c('*' = .1, '**' = .05, '***'=0.01))
如何使系数下的 t 统计量具有 2 位有效数字和 3 位估计值?因此,第一个系数统计对将是:
7948.667
(2078.27)
我仔细阅读了文档,但没有找到答案。提前致谢!
从版本 0.9.4 开始,没有 直接 方法来实现这一点
只是他 fmt
参数或 glue
字符串。
但是,利用 tidy_custom
和
glance_custom
机制 在 modelsummary
中描述
网站
对您的估计和统计数据进行任何 post 处理。
这为用户提供了无限的可能性来自定义输出
格式。
例如,
library(modelsummary)
library(broom)
tidy_custom.lm <- function(x) {
out <- broom::tidy(x)
out$statistic <- sprintf("%.2f", out$statistic)
out$estimate <- sprintf("%.3f", out$estimate)
return(out)
}
mod <- lm(mpg ~ hp + drat, mtcars)
modelsummary(mod, statistic = "statistic", stars = TRUE)
Model 1
(Intercept)
10.790*
(2.12)
hp
-0.052***
(-5.57)
drat
4.698***
(3.94)
Num.Obs.
32
R2
0.741
R2 Adj.
0.723
AIC
169.5
BIC
175.4
Log.Lik.
-80.752
F
41.522
注:^^ + p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001
我打开了 an issue on Github. 如果你愿意,可以随时到那里 post
为对话做出贡献。
首先感谢 modelsummary 包的创建者 -- 非常有用!
我对统计和估计的不同 fmt
有疑问?这是一个代表:
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)
modelsummary(models, output = "flextable", estimate=glue_col("{estimate}{stars}"),
statistic = 'statistic', stars = c('*' = .1, '**' = .05, '***'=0.01))
如何使系数下的 t 统计量具有 2 位有效数字和 3 位估计值?因此,第一个系数统计对将是: 7948.667 (2078.27)
我仔细阅读了文档,但没有找到答案。提前致谢!
从版本 0.9.4 开始,没有 直接 方法来实现这一点
只是他 fmt
参数或 glue
字符串。
但是,利用 tidy_custom
和
glance_custom
机制 在 modelsummary
中描述
网站
对您的估计和统计数据进行任何 post 处理。
这为用户提供了无限的可能性来自定义输出
格式。
例如,
library(modelsummary)
library(broom)
tidy_custom.lm <- function(x) {
out <- broom::tidy(x)
out$statistic <- sprintf("%.2f", out$statistic)
out$estimate <- sprintf("%.3f", out$estimate)
return(out)
}
mod <- lm(mpg ~ hp + drat, mtcars)
modelsummary(mod, statistic = "statistic", stars = TRUE)
Model 1 | |
---|---|
(Intercept) | 10.790* |
(2.12) | |
hp | -0.052*** |
(-5.57) | |
drat | 4.698*** |
(3.94) | |
Num.Obs. | 32 |
R2 | 0.741 |
R2 Adj. | 0.723 |
AIC | 169.5 |
BIC | 175.4 |
Log.Lik. | -80.752 |
F | 41.522 |
注:^^ + p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001
我打开了 an issue on Github. 如果你愿意,可以随时到那里 post 为对话做出贡献。