butcher icon indicating copy to clipboard operation
butcher copied to clipboard

Add butcher support for multilevelmod / lme4

Open bshor opened this issue 3 years ago • 5 comments

I am trying to use the butcher package to cut down on the size of fitted objects, in my case fits using lme4::lmer. That led me to parsnip, then here!

I would have thought this would work, but it doesn't.

library(multilevelmod)
#> Loading required package: parsnip
data(sleepstudy, package = "lme4")

mixed_model_spec <- linear_reg() %>% set_engine("lmer")

mixed_model_fit <- 
  mixed_model_spec %>% 
  fit(Reaction ~ Days + (Days | Subject), data = sleepstudy)

mixed_model_fit

Checking the size of the fits:

> object.size(mixed_model_fit)
67120 bytes
> object.size(butcher(mixed_model_fit))
67120 bytes

What am I missing?

bshor avatar May 25 '21 19:05 bshor

Hi @bshor ! I think you don't see any changes because butcher does not have methods for models from lme4: The documentation for butcher says

The current axe methods have been tested on all parsnip model objects as listed here. If you are working with a new model object that could benefit from any kind of axing, we would love for you to make a pull request!

and your model is a not listed there, neither did I see anything in the butcher repo.

@DavisVaughan is that in scope for butcher?

hfrick avatar May 26 '21 12:05 hfrick

Yes I think so!

DavisVaughan avatar May 26 '21 14:05 DavisVaughan

Thanks! I had thought by using multilevelmod it would somehow automatically add lmer to the list. I may have to do it manually (never having done it before!).

bshor avatar May 26 '21 14:05 bshor

I would be willing to help with this but would have to familiarize myself with the package - would need to do some careful tests to know which components could be removed with what loss of functionality.

bbolker avatar Apr 03 '23 22:04 bbolker

That would be super helpful @bbolker! 🙌 This package has a vignette on how to add a new model, and I feel like the tests for GAMs are a pretty good example to look at.

juliasilge avatar Apr 03 '23 23:04 juliasilge