Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce model object size #959

Open
acircleda opened this issue Oct 30, 2023 · 1 comment
Open

Reduce model object size #959

acircleda opened this issue Oct 30, 2023 · 1 comment

Comments

@acircleda
Copy link

acircleda commented Oct 30, 2023

I am building a production level pipeline using around 60 different models all fit with a relatively simple formula :y ~ x + z + (1 | id) , however some of the model files are massive (~2gb) because of the number of observations I use.

I need the model object to predict on new data. I am wondering what are the basic elements of the model object necessary for predict? I'd like to place them into a new, slimmer object and work from that. I have already taken a deductive approach, nullifying elements that contribute to a high object size (I got the 2gb file down to 119 mb) but wondering if I could take a better approach.

@bbolker
Copy link
Contributor

bbolker commented Oct 31, 2023

Depending on what you need to do, you could make a very slim pipeline by saving only the coefficients and implementing your own predict method, i.e.

beta <- fixef(model)$cond
b <- getME(model, "b")  ## needs development version of the package
X <- model.matrix(~x + z, newdata)
Z <- model.matrix(~0+id, newdata)
pred <- X %*% beta + Z %*% b

... but of course that doesn't get you things like back-transformation via the inverse link in a GLMM, standard errors of predictions, etc etc etc ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants