r-模型摘要:用于估计和统计的不同格式



首先感谢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(

我仔细阅读了文件,但没有找到答案。提前谢谢!

编辑:fmt参数现在接受一个命名列表,如:list(estimate = 3, p.value = 4)

从0.9.4版本起,没有直接的方法可以通过只有fmt参数或glue字符串。

然而,利用tidy_custommodelsummary上描述的glance_custom机制网站对您的估计和统计数据进行任何后期处理。这为用户自定义输出提供了无限的可能性总体安排

例如,

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)
模型1(截距(10.790*(2.12(hp-0.052***(-5.57(drat4.698***(3.94(Num.Obs.32R20.741R2调整AIC169.5BIC175.4Log.Like。-80.752F41.522

最新更新