Add fallback for lmer objects in pool() without requiring broom.mixed#728
Add fallback for lmer objects in pool() without requiring broom.mixed#728stefvanbuuren merged 1 commit intoamices:masterfrom
Conversation
Problem: pool() fails when used with lmer/lmerMod objects unless the broom.mixed package is installed. This forces users to install an entire additional package just to extract coefficients that are already accessible through lme4's built-in fixef() and vcov() methods. Solution: Added a tryCatch wrapper in summary.mira() that detects when tidy() fails for lmerMod objects and falls back to manual coefficient extraction using: - lme4::fixef() for fixed effects estimates - stats::vcov() for variance-covariance matrix - Standard error calculation via sqrt(diag(vcov())) This produces identical results to broom.mixed (verified in test_verify_accuracy.R with zero numerical difference) while eliminating the dependency. Benefits: - Reduces package dependencies and installation overhead - Improves security by avoiding unnecessary package installations - Maintains backward compatibility (still works with broom.mixed if installed) - Uses only built-in methods already present in lme4 and base R Testing: Run test_lmer_fix.R to verify pool() works without broom.mixed Run test_verify_accuracy.R to verify results match broom.mixed exactly Fixes common error: 'No tidy method for objects of class lmerMod' Related to issues about broom.mixed dependency requirements
|
Thanks for the work you put into preparing this PR. The solution is technically correct, but I will not incorporate it into Your approach bypasses the standard pooling mechanism implemented via The introduction of Thanks again for your contribution and for engaging with the package. |
|
Hey Stef, Your current setup: pool() throws a hard error the moment any user fits the most common mixed model in existence (lmer) unless they install a completely separate package (broom.mixed) that 99% of them have never heard of. This isn’t 2015 anymore. Requiring an extra dependency just to call pool() on an lmerMod object is indefensible in 2025. The methods I’m using (fixef() and vcov()) have been stable, exported, and documented for 15+ years. This isn’t some hacky internal scraping; it’s the official API. |
|
I agree that we can reasonably make an exception for For reference, the current behaviour is: If we paste this into ChatGPT, we get various suggestions, with That said, I appreciate you raising this point so clearly. Improving the user experience is important, and your patch highlights a real tension between convenience and long-term maintainability. I will take a careful look at whether a narrowly scoped exception for |
|
OK, I spoke with a few people and decided to reconsider my earlier position. The PR is a useful addition to enhance user experience, and - contrary to what I'd thought - no new imports are required. Given the popularity of I’m not entirely certain the PR is fully CRAN-compliant as submitted. After merging I will add: so that Thanks for pressing on and representing the user voice. |
|
thanks, I needed this..really appreciate this. I can't explain how much it means to me, all I've wanted is to contribute clean eloquent software, I live and breathe for it, and intelligent os is my only hope. Thank you for giving me hope. |
Problem:
pool() fails when used with lmer/lmerMod objects unless the broom.mixed package is installed. This forces users to install an entire additional package just to extract coefficients that are already accessible through lme4's built-in fixef() and vcov() methods.
Solution:
Added a tryCatch wrapper in summary.mira() that detects when tidy() fails for lmerMod objects and falls back to manual coefficient extraction using:
This produces identical results to broom.mixed (verified in test_verify_accuracy.R with zero numerical difference) while eliminating the dependency.
Benefits:
Testing:
Run test_lmer_fix.R to verify pool() works without broom.mixed Run test_verify_accuracy.R to verify results match broom.mixed exactly
Fixes common error: 'No tidy method for objects of class lmerMod' Related to issues about broom.mixed dependency requirements