ggobi/ggally

"No tidy method for objects of class glmerMod" in ggcoef_model

Closed this issue · 3 comments

I noticed that ggcoef_model() does not manage to handle lme4::glmer objects without the user having to load the broom.mixed package first. This is probably a bug caused by tidy methods for mixed-type models being moved to the broom.mixed package lately.

The solution would be to add one more dependency and importing broom.mixed::tidy in ggcoef_model()

library(GGally)
#> Loading required package: ggplot2
#> Registered S3 method overwritten by 'GGally':
#>   method from   
#>   +.gg   ggplot2
library(lme4)
#> Loading required package: Matrix

gm1 <- lme4::glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
                   data = cbpp, family = binomial)

GGally::ggcoef_model(gm1)
#> x There was an error calling `tidy_fun()`. Most likely, this is because the
#> function supplied in `tidy_fun=` was misspelled, does not exist, is not
#> compatible with your object, or was missing necessary arguments (e.g. `conf.level=` or `conf.int=`). See error message below.
#> Error: Error: No tidy method for objects of class glmerMod
library(GGally)
#> Loading required package: ggplot2
#> Registered S3 method overwritten by 'GGally':
#>   method from   
#>   +.gg   ggplot2
library(lme4)
#> Loading required package: Matrix
library(broom.mixed)

gm1 <- lme4::glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
                   data = cbpp, family = binomial)

GGally::ggcoef_model(gm1)

Created on 2021-12-09 by the reprex package (v2.0.1)

ggcoef_model() relies on broom.helpers package. The solution should be to rely on broom.helpers::tidy_with_broom_or_parameters tidier, who checks already if broom.mixed is available if required.

cf. https://github.com/larmarange/broom.helpers/blob/2259c8263308f59673226cce8c698dfcd6d89771/R/tidiers.R#L39

Change has been added in #431

library(GGally)
#> Le chargement a nécessité le package : ggplot2
#> Registered S3 method overwritten by 'GGally':
#>   method from   
#>   +.gg   ggplot2
library(lme4)
#> Le chargement a nécessité le package : Matrix

mod <- lme4::glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
                   data = cbpp, family = binomial)

mod %>% ggcoef_model()

mod %>% ggcoef_model(include = -broom.helpers::all_ran_pars())

Created on 2021-12-09 by the reprex package (v2.0.1)

Thanks! And thank you for a great package :) I'll close the issue. Reopen if needed.