1

I'm attempting to report the model summary from mgcv::gam() using the modelsummary package. The flextable package provides a summary that is consistent with the summary output in R and what is often presented in publications. 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.). 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().

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)

flextable output

My first step at getting the summary for parametric terms using 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)

modelsummary gam output

I want to drop the smooth terms and include those in a different table or group, so I tried the coef_omit argument:

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. I might be approaching formatting this summary completely wrong and am open to suggestions.

mpschramm
  • 520
  • 6
  • 12
  • 1
    Thanks for this question. I believe you hit a road block because of a combination of two minor bugs which, together, are showstoppers. I'll try to fix this in the next few days. Follow developments here: https://github.com/vincentarelbundock/modelsummary/issues/558 – Vincent Sep 27 '22 at 23:49

0 Answers0