简体   繁体   English

使用 modelsummary 报告 mgcv::gam 摘要

[英]Reporting mgcv::gam summary with modelsummary

I'm attempting to report the model summary from mgcv::gam() using the modelsummary package.我正在尝试使用模型摘要 package 从mgcv::gam()报告 model 摘要。 The flextable package provides a summary that is consistent with the summary output in R and what is often presented in publications.灵活表 package 提供的摘要与 R 中的摘要 output 以及出版物中经常出现的内容一致。 It separates out reporting for the fixed/parametric effects and the smooth terms.它将固定/参数效应和平滑项的报告分开。 Although flextable works well, I'd like to use modelsummary (mainly for it's ability to output to gt, kable, etc.).虽然 flextable 效果很好,但我还是想用 modelsummary(主要是因为它能够 output 到 gt、kable 等)。 My plan was to produce two separate tables and report the appropriate data for parametric and smooth terms separately (there might be a better way?).我的计划是生成两个单独的表格,并分别报告参数和平滑项的适当数据(可能有更好的方法?)。 However, I get hung up trying to omit coefficients in modelsummary() .但是,我在尝试省略modelsummary()中的系数时挂断了电话。

Flextable example:弹性表示例:

library(mgcv)
library(flextable)
library(modelsummary)

dat <- gamSim(1, n = 4000, dist = "normal", scale = 2)
mod <- gam(y ~ s(x0) + s(x1) + s(x2), data = dat)
flextable::as_flextable(mod)

灵活的输出

My first step at getting the summary for parametric terms using modelsummary() :我使用modelsummary()获取参数项摘要的第一步:

modelsummary(mod,
             estimate = "estimate",
             statistic = c("Std.Error" = "std.error", 
                           "t-value" = "statistic", 
                           "p-value" = "p.value"),
             shape = term ~ model + statistic,
             gof_map = NA)

模型总结游戏输出

I want to drop the smooth terms and include those in a different table or group, so I tried the coef_omit argument:我想删除平滑术语并将它们包含在不同的表或组中,所以我尝试了 coef_omit 参数:

modelsummary(mod,
             estimate = "estimate",
             statistic = c("Std.Error" = "std.error", 
                           "t-value" = "statistic", 
                           "p-value" = "p.value"),
             coef_omit = "^(?!.*Intercept)", #this should retain the intercept term
             omit = ".*",
             shape = term ~ model + statistic,
             gof_map = NA)

Error in if (dat$part[i] == "estimates" && dat[[column]][i - 1] == dat[[column]][i]) { : 
  missing value where TRUE/FALSE needed

Interestingly, if I remove the shape argument to report statistics in "long format" the error goes away.有趣的是,如果我删除 shape 参数以“长格式”报告统计信息,错误就会消失。 I might be approaching formatting this summary completely wrong and am open to suggestions.我可能正在接近完全错误地格式化此摘要,并且愿意接受建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM