larmarange / broom.helpers

A set of functions to facilitate manipulation of tibbles produced by broom
https://larmarange.github.io/broom.helpers/
GNU General Public License v3.0
21 stars 8 forks source link

Avg_comparisons and nlme::lme() models #244

Closed mprimbs closed 6 months ago

mprimbs commented 6 months ago

Dear Team,

I'm estimated a mixed-effects model with nlme::lme() and want to use marginaleffects::avg_predictions() on the lme object.

After running the code:

ModelWeek1 <- nlme::lme(IAT_Score ~ BeginProtests_f + age_centred + genderIdentity_f, random = (~ 1 | STATE), data = df_propensity_wts, na.action = "na.omit", control = lmerControl(optimizer = "bobyqa", calc.derivs = FALSE), weights = ~1/wts)

avg_predictions(ModelWeek1, variables = "BeginProtests_f", wts = "wts", vcov = "HC3")

I get the following warning message:

Warning message: Unable to extract a variance-covariance matrix using this vcov argument. Standard errors are computed using the default variance instead. Perhaps the model or argument is not supported by the sandwich or clubSandwich packages. If you believe that the model is supported by one of these two packages, you can open a feature request on Github.

I looked at the sandwich help pages and it seems that lme objects are supported (https://rdrr.io/cran/clubSandwich/man/vcovCR.lme.html).

Hence, I`m contacting you here to see whether I'm doing something wrong and/or how to use avg_predictions() successfully with robust standard errors.

Best Regards,

Max

larmarange commented 6 months ago

Hi. It seems that the problem you encountered was with marginaleffects::avg_predictions(). Therefore, you should post your issue on the marginaleffects repository: https://github.com/vincentarelbundock/marginaleffects

Best regards