rmodelsummaryglmmtmb

Print glmmTMB conditional and zero-inflated model side-by-side with modelsummary


I'm trying to print the conditional and zero-inflated model of a zero-inflated Poisson model estimated with glmmTMB with modelsummary, but I'm unable to do so.

Here is my attempt so far, following the syntax described here

Owls <- transform(Owls,
                  Nest=reorder(Nest,NegPerChick),
                  NCalls=SiblingNegotiation,
                  FT=FoodTreatment)

fit_zipoisson <- glmmTMB(NCalls~(FT+ArrivalTime)*SexParent+
                           offset(log(BroodSize))+(1|Nest),
                         data=Owls,
                         ziformula=~1,
                         family=poisson)

ti <- list(
  broom.mixed::tidy(fit_zipoisson) |>
    filter(effect=="fixed" & component=="cond"),
  broom.mixed::tidy(fit_zipoisson) |>
    filter(effect=="fixed" & component=="zi")
)

gl <- list(
  broom.mixed::glance(fit_zipoisson),
  broom.mixed::glance(fit_zipoisson)
)

mod <- list(
  tidy = ti,
  glance = gl)
class(mod) <- "modelsummary_list"

modelsummary(mod)

which returns:

Error: `estimate` is not available. The `estimate` and `statistic` arguments must correspond to column names in the output of this command: `get_estimates(model)`

I guess this syntax doesn't support passing a list?


Solution

  • The catch is that a custom modelsummary list needs named items ("tidy" and "glance").

    
        library(glmmTMB)  
        ## your example data and model ...
    
    
    
        get_modsum_list <- function(model, effects = "fixed", component = "cond"){
          mod <- list(
            ## list needs named items ('tidy' and 'glance')
            tidy = broom.mixed::tidy(model, effects = effects, component = component),
            glance = broom.mixed::glance(model)
          )
          class(mod) <- "modelsummary_list"
          mod
        }
    
    
    
        list(
          'conditional' = get_modsum_list(fit_zipoisson),
          'zero-inflated' = get_modsum_list(fit_zipoisson, component = "zi")
        ) |>
          modelsummary()
        
    

    combine model summaries