rconfidence-intervalmumin

Confidence intervals from model-averaged objects - error with MuMIn


I've been trying to obtain model-averaged confidence intervals, but MuMIn::confint() throws the error:

Error en get(name, envir = asNamespace(pkg), inherits = FALSE): objeto 'format.perc' no encontrado – the Spanish bit translates to object 'format.perc' not found.

My workflow involves fitting binomial GLMs with glmmTMB::glmmTMB(), with parallelization (need for speed), then using MuMIn::dredge(). The dredge process is lenghty, so I run it once, store it as a .Rds, and load it; so I don't have to wait 3 hours every time. I use the loaded .Rds object to perform model averaging, and use the resulting object to calculate coefficients, confidence intervals, and estimated marginal means. So far, the problem has arisen when I apply the confint() function to the model-averaged object obtained with MuMIn::model.avg().

This is quite surprising, as I have used the same method this year without conflicts. If I can't solve it, I will multiply the standard errors by 1.96 to obtain the 95% confidence intervals. But I would prefer to know the root cause.

I've created a reproducible example below, representative of my workflow in some ways. Apparently, it will throw this error with generalized linear models and linear models, even when no parallelization is there, and when .Rds are not loaded in session. Therefore, the problem appears to be more general.

library(glmmTMB)
library(MuMIn)
library(parallel)
library(tidyverse)

# Initiate cluster, with as many cores - 1
cl  <-  parallel::makeCluster((parallel::detectCores() - 1))

# Set options for dredge()
options(na.action = "na.fail")

# dataset
mtcars
#>                      mpg cyl  disp  hp drat    wt  qsec vs am gear carb
#> Mazda RX4           21.0   6 160.0 110 3.90 2.620 16.46  0  1    4    4
#> Mazda RX4 Wag       21.0   6 160.0 110 3.90 2.875 17.02  0  1    4    4
#> Datsun 710          22.8   4 108.0  93 3.85 2.320 18.61  1  1    4    1
#> Hornet 4 Drive      21.4   6 258.0 110 3.08 3.215 19.44  1  0    3    1
#> Hornet Sportabout   18.7   8 360.0 175 3.15 3.440 17.02  0  0    3    2
#> Valiant             18.1   6 225.0 105 2.76 3.460 20.22  1  0    3    1
#> Duster 360          14.3   8 360.0 245 3.21 3.570 15.84  0  0    3    4
#> Merc 240D           24.4   4 146.7  62 3.69 3.190 20.00  1  0    4    2
#> Merc 230            22.8   4 140.8  95 3.92 3.150 22.90  1  0    4    2
#> Merc 280            19.2   6 167.6 123 3.92 3.440 18.30  1  0    4    4
#> Merc 280C           17.8   6 167.6 123 3.92 3.440 18.90  1  0    4    4
#> Merc 450SE          16.4   8 275.8 180 3.07 4.070 17.40  0  0    3    3
#> Merc 450SL          17.3   8 275.8 180 3.07 3.730 17.60  0  0    3    3
#> Merc 450SLC         15.2   8 275.8 180 3.07 3.780 18.00  0  0    3    3
#> Cadillac Fleetwood  10.4   8 472.0 205 2.93 5.250 17.98  0  0    3    4
#> Lincoln Continental 10.4   8 460.0 215 3.00 5.424 17.82  0  0    3    4
#> Chrysler Imperial   14.7   8 440.0 230 3.23 5.345 17.42  0  0    3    4
#> Fiat 128            32.4   4  78.7  66 4.08 2.200 19.47  1  1    4    1
#> Honda Civic         30.4   4  75.7  52 4.93 1.615 18.52  1  1    4    2
#> Toyota Corolla      33.9   4  71.1  65 4.22 1.835 19.90  1  1    4    1
#> Toyota Corona       21.5   4 120.1  97 3.70 2.465 20.01  1  0    3    1
#> Dodge Challenger    15.5   8 318.0 150 2.76 3.520 16.87  0  0    3    2
#> AMC Javelin         15.2   8 304.0 150 3.15 3.435 17.30  0  0    3    2
#> Camaro Z28          13.3   8 350.0 245 3.73 3.840 15.41  0  0    3    4
#> Pontiac Firebird    19.2   8 400.0 175 3.08 3.845 17.05  0  0    3    2
#> Fiat X1-9           27.3   4  79.0  66 4.08 1.935 18.90  1  1    4    1
#> Porsche 914-2       26.0   4 120.3  91 4.43 2.140 16.70  0  1    5    2
#> Lotus Europa        30.4   4  95.1 113 3.77 1.513 16.90  1  1    5    2
#> Ford Pantera L      15.8   8 351.0 264 4.22 3.170 14.50  0  1    5    4
#> Ferrari Dino        19.7   6 145.0 175 3.62 2.770 15.50  0  1    5    6
#> Maserati Bora       15.0   8 301.0 335 3.54 3.570 14.60  0  1    5    8
#> Volvo 142E          21.4   4 121.0 109 4.11 2.780 18.60  1  1    4    2

# full model
m <- glmmTMB::glmmTMB(gear ~ mpg + cyl + hp, family = poisson(link = "log"), data = mtcars, control = glmmTMBControl(parallel = length(cl)))

# dredge (all variable combinations) - not essential to get the error, but representative of my workflow
md <- MuMIn::dredge(m, rank = "AICc")
#> Fixed terms are "cond((Int))" and "disp((Int))"

# Model averaging of the "bset subset" of the dredge output
ma <- md %>% 
  subset(delta <= 6) %>% 
  MuMIn::model.avg(revised.var = TRUE,
                   fit = TRUE)

# Model averaging of a manually declared set of models
ma2 <- list(glmmTMB::glmmTMB(gear ~ cyl + hp, family = poisson(link = "log"), data = mtcars, control = glmmTMBControl(parallel = length(cl))),
            glmmTMB::glmmTMB(gear ~ mpg + hp, family = poisson(link = "log"), data = mtcars, control = glmmTMBControl(parallel = length(cl))),
            glmmTMB::glmmTMB(gear ~ mpg + cyl, family = poisson(link = "log"), data = mtcars, control = glmmTMBControl(parallel = length(cl)))) %>% 
  MuMIn::model.avg(revised.var = TRUE,
                   fit = TRUE)

# Model averaging of a manually declared set of models, but change to linear models
ma3 <- list(lm(gear ~ cyl + hp, data = mtcars),
            lm(gear ~ cyl, data = mtcars),
            lm(gear ~ hp, data = mtcars)) %>% 
  MuMIn::model.avg(revised.var = TRUE,
                   fit = TRUE)

# summary() works fine
summary(ma)
#> 
#> Call:
#> model.avg(object = get.models(object = ., subset = NA), revised.var = TRUE)
#> 
#> Component model call: 
#> glmmTMB::glmmTMB(formula = gear ~ <8 unique rhs>, data = mtcars, family 
#>      = poisson(link = "log"), ziformula = ~0, dispformula = ~1, control = 
#>      glmmTMBControl(parallel = length(cl)))
#> 
#> Component models: 
#>        df logLik   AICc delta weight
#> (Null)  1 -52.97 108.07  0.00   0.31
#> 1       2 -52.41 109.24  1.17   0.17
#> 3       2 -52.45 109.31  1.25   0.17
#> 2       2 -52.93 110.27  2.21   0.10
#> 12      3 -51.81 110.47  2.40   0.09
#> 23      3 -52.11 111.08  3.02   0.07
#> 13      3 -52.39 111.63  3.56   0.05
#> 123     4 -51.68 112.85  4.78   0.03
#> 
#> Term codes: 
#> cond(cyl)  cond(hp) cond(mpg) 
#>         1         2         3 
#> 
#> Model-averaged coefficients:  
#> (full average) 
#>               Estimate Std. Error Adjusted SE z value Pr(>|z|)  
#> cond((Int))  1.3017380  0.5586412   0.5743889   2.266   0.0234 *
#> cond(cyl)   -0.0277628  0.0651526   0.0666382   0.417   0.6770  
#> cond(mpg)    0.0054787  0.0150962   0.0155148   0.353   0.7240  
#> cond(hp)     0.0004185  0.0014665   0.0015018   0.279   0.7805  
#>  
#> (conditional average) 
#>              Estimate Std. Error Adjusted SE z value Pr(>|z|)  
#> cond((Int))  1.301738   0.558641    0.574389   2.266   0.0234 *
#> cond(cyl)   -0.079717   0.089704    0.092785   0.859   0.3903  
#> cond(mpg)    0.017258   0.022685    0.023557   0.733   0.4638  
#> cond(hp)     0.001419   0.002424    0.002496   0.569   0.5696  
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(ma2)
#> 
#> Call:
#> model.avg(object = ., fit = TRUE, revised.var = TRUE)
#> 
#> Component model call: 
#> glmmTMB::glmmTMB(formula = gear ~ <3 unique rhs>, data = mtcars, family 
#>      = poisson(link = "log"), control = glmmTMBControl(parallel = 
#>      length(cl)), ziformula = ~0, dispformula = ~1)
#> 
#> Component models: 
#>    df logLik   AICc delta weight
#> 12  3 -51.81 110.47  0.00   0.44
#> 23  3 -52.11 111.08  0.61   0.32
#> 13  3 -52.39 111.63  1.16   0.24
#> 
#> Term codes: 
#> cond(cyl)  cond(hp) cond(mpg) 
#>         1         2         3 
#> 
#> Model-averaged coefficients:  
#> (full average) 
#>              Estimate Std. Error Adjusted SE z value Pr(>|z|)
#> cond((Int))  1.248304   0.947478    0.973135   1.283    0.200
#> cond(cyl)   -0.070397   0.101803    0.104493   0.674    0.501
#> cond(hp)     0.001731   0.002221    0.002296   0.754    0.451
#> cond(mpg)    0.011477   0.023670    0.024373   0.471    0.638
#>  
#> (conditional average) 
#>              Estimate Std. Error Adjusted SE z value Pr(>|z|)
#> cond((Int))  1.248304   0.947478    0.973135   1.283    0.200
#> cond(cyl)   -0.103594   0.108683    0.112377   0.922    0.357
#> cond(hp)     0.002289   0.002291    0.002387   0.959    0.337
#> cond(mpg)    0.020336   0.028505    0.029536   0.689    0.491
summary(ma3)
#> 
#> Call:
#> model.avg(object = ., fit = TRUE, revised.var = TRUE)
#> 
#> Component model call: 
#> lm(formula = <3 unique values>, data = mtcars)
#> 
#> Component models: 
#>    df logLik  AICc delta weight
#> 12  4 -23.88 57.23  0.00      1
#> 1   3 -30.72 68.29 11.06      0
#> 2   3 -34.91 76.68 19.45      0
#> 
#> Term codes: 
#> cyl  hp 
#>   1   2 
#> 
#> Model-averaged coefficients:  
#> (full average) 
#>              Estimate Std. Error Adjusted SE z value Pr(>|z|)    
#> (Intercept)  5.453755   0.371881    0.387923  14.059  < 2e-16 ***
#> cyl         -0.520839   0.099292    0.103433   5.036 4.77e-07 ***
#> hp           0.009929   0.002607    0.002714   3.659 0.000253 ***
#>  
#> (conditional average) 
#>              Estimate Std. Error Adjusted SE z value Pr(>|z|)    
#> (Intercept)  5.453755   0.371881    0.387923  14.059  < 2e-16 ***
#> cyl         -0.520870   0.099214    0.103358   5.039 4.67e-07 ***
#> hp           0.009968   0.002536    0.002646   3.768 0.000165 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

# coef() works fine
coef(ma)
#> cond((Int))   cond(cyl)   cond(mpg)    cond(hp) 
#>  1.30173798 -0.07971734  0.01725817  0.00141934
coef(ma2)
#>  cond((Int))    cond(cyl)     cond(hp)    cond(mpg) 
#>  1.248303658 -0.103594099  0.002289204  0.020336401
coef(ma3)
#> (Intercept)         cyl          hp 
#>  5.45375475 -0.52087034  0.00996822

# confint does not work
confint(ma)
#> Error in get(name, envir = asNamespace(pkg), inherits = FALSE): objeto 'format.perc' no encontrado
confint(ma2)
#> Error in get(name, envir = asNamespace(pkg), inherits = FALSE): objeto 'format.perc' no encontrado
confint(ma3)
#> Error in get(name, envir = asNamespace(pkg), inherits = FALSE): objeto 'format.perc' no encontrado

sessionInfo()
#> R version 4.5.1 (2025-06-13 ucrt)
#> Platform: x86_64-w64-mingw32/x64
#> Running under: Windows 11 x64 (build 26100)
#> 
#> Matrix products: default
#>   LAPACK version 3.12.1
#> 
#> locale:
#> [1] LC_COLLATE=Spanish_Spain.utf8  LC_CTYPE=Spanish_Spain.utf8   
#> [3] LC_MONETARY=Spanish_Spain.utf8 LC_NUMERIC=C                  
#> [5] LC_TIME=Spanish_Spain.utf8    
#> 
#> time zone: Europe/Madrid
#> tzcode source: internal
#> 
#> attached base packages:
#> [1] parallel  stats     graphics  grDevices utils     datasets  methods  
#> [8] base     
#> 
#> other attached packages:
#>  [1] lubridate_1.9.4 forcats_1.0.0   stringr_1.5.1   dplyr_1.1.4    
#>  [5] purrr_1.1.0     readr_2.1.5     tidyr_1.3.1     tibble_3.3.0   
#>  [9] ggplot2_3.5.2   tidyverse_2.0.0 MuMIn_1.46.0    glmmTMB_1.1.11 
#> 
#> loaded via a namespace (and not attached):
#>  [1] gtable_0.3.6        TMB_1.9.17          xfun_0.52          
#>  [4] lattice_0.22-7      tzdb_0.5.0          numDeriv_2016.8-1.1
#>  [7] vctrs_0.6.5         tools_4.5.1         Rdpack_2.6.4       
#> [10] generics_0.1.4      stats4_4.5.1        sandwich_3.1-1     
#> [13] pkgconfig_2.0.3     Matrix_1.7-3        RColorBrewer_1.1-3 
#> [16] lifecycle_1.0.4     compiler_4.5.1      farver_2.1.2       
#> [19] codetools_0.2-20    htmltools_0.5.8.1   yaml_2.3.10        
#> [22] pillar_1.11.0       nloptr_2.2.1        MASS_7.3-65        
#> [25] reformulas_0.4.1    boot_1.3-31         multcomp_1.4-28    
#> [28] nlme_3.1-168        tidyselect_1.2.1    digest_0.6.37      
#> [31] mvtnorm_1.3-3       stringi_1.8.7       splines_4.5.1      
#> [34] fastmap_1.2.0       grid_4.5.1          cli_3.6.5          
#> [37] magrittr_2.0.3      survival_3.8-3      TH.data_1.1-3      
#> [40] withr_3.0.2         scales_1.4.0        timechange_0.3.0   
#> [43] estimability_1.5.1  rmarkdown_2.29      emmeans_1.11.2     
#> [46] lme4_1.1-37         zoo_1.8-14          hms_1.1.3          
#> [49] coda_0.19-4.1       evaluate_1.0.4      knitr_1.50         
#> [52] rbibutils_2.3       mgcv_1.9-3          rlang_1.1.6        
#> [55] Rcpp_1.1.0          xtable_1.8-4        glue_1.8.0         
#> [58] reprex_2.1.1        rstudioapi_0.17.1   minqa_1.2.8        
#> [61] R6_2.6.1            fs_1.6.6

Created on 2025-08-06 with reprex v2.1.1


Solution

  • tl;dr update to a more recent version of MuMIn (preferably the current CRAN version ...)

    This is a bug that has been fixed in more recent versions of MuMIn. When I couldn't replicate the problem with the current CRAN version of MuMIn (1.48.11), I went to look at the NEWS file for MuMIn linked from its CRAN page. Searching for "format.perc":

    Changes in version 1.47.4 (2023-03-13)

    • (fixed) removed remaining references to stats:::format.perc.

    More generally, "update to the most recent version of the package if possible" is a valuable step in any debugging workflow ...