rlmmodelsummarybrms

modelsummary display output from lm and brms concurrently with statistics


models <- list(
"Linear" = lm(outcome ~ week * food data = df ),
"Bayesian" = brm(outcome ~ s(week, k = 4, fx = TRUE, by = food) + food, data = df, family = "zero_one_inflated_beta")
)

The following code works when I run it

modelsummary(models,
             estimate = "{estimate}[{conf.low}, {conf.high}]",
             statistic = NULL)

The problem is that when I attempt to also get the p-value, t-value and standard error of the linear model with the following code, the error comes up as Error: std.error is not available. The estimate and statistic arguments must correspond to column names in the output of this command: get_estimates(model)

modelsummary(models,
             estimate = "estimate[{conf.low}, {conf.high}]",
             statistic = c("Std.Error" = "std.error", 
                           "t-value" = "statistic", 
                           "p-value" = "p.value"))

How can I enable modelsummary() to ignore the display of statistics when there is none like in the case of the brms model instead of throwing an error?


Solution

  • This is a common use-case which is not well supported in the CRAN version of modelsummary. Instead of suggesting a complicated hack, I pushed a change to the development version which makes this much easier. You can install it now with:

    remotes::install_github("vincentarelbundock/modelsummary")
    

    Restart R completely for the changes to take effect.

    Then, you can do things like:

    library(brms)
    library(modelsummary)
    
    mod1 <- lm(mpg ~ hp + qsec, data = mtcars)
    mod2 <- brm(mpg ~ hp + qsec, data = mtcars)
    models <- list(mod1, mod2)
    
    modelsummary(
        models,
        statistic = c("std.error", "conf.int"),
        # clean-up coefficient names
        coef_rename = \(x) gsub("b_", "", x),
        coef_omit = "Intercept")
    
    (1) (2)
    hp -0.085 -0.084
    (0.014)
    [-0.113, -0.056] [-0.112, -0.055]
    qsec -0.887 -0.867
    (0.535)
    [-1.980, 0.207] [-1.944, 0.239]
    sigma 3.815
    [3.000, 4.991]
    Num.Obs. 32 32
    R2 0.637 0.631
    R2 Adj. 0.612 0.553
    AIC 180.3
    BIC 186.2
    Log.Lik. -86.170
    F 25.431
    ELPD -91.1
    ELPD s.e. 4.9
    LOOIC 182.3
    LOOIC s.e. 9.8
    WAIC 181.9
    RMSE 3.57 3.57