[R-sig-ME] Decreasing size of gamm4 model output (multiple GB when saved to .rds)

Ben Bolker bbo|ker @end|ng |rom gm@||@com
Tue Sep 19 17:12:50 CEST 2023


   You could take a look at the `strip_gamm4_env()` function here: 
https://github.com/bbolker/mmd_utils/blob/master/gamm4_utils.R ; it 
definitely reduces the sizes of stored objects, but you'll have to check 
which model methods actually work on the stripped object ...

   cheers
    Ben Bolker


On 2023-09-19 3:21 a.m., David Duffy wrote:
> ________________________________________
> From: R-sig-mixed-models <r-sig-mixed-models-bounces using r-project.org> on behalf of David Winsemius <dwinsemius using comcast.net>
> Sent: Tuesday, 19 September 2023 12:24 PM
> To: Meaghan Rupprecht
> Cc: R-SIG-Mixed-Models using r-project.org
> Subject: Re: [R-sig-ME]  Decreasing size of gamm4 model output (multiple GB when saved to .rds)
> 
>> I was puzzled by the fact that you save the output as an rds file. I suspect but am unable to confirm, that your result(s) include some representation of the data.
>> You might instead return the models with the data omitted
>> David.
> 
>>> On Sep 17, 2023, at 10:11 PM, Meaghan Rupprecht <rupprecht using unbc.ca> wrote:
>>>
>>> I am running a Generalized Additive Mixed Model with the R package, gamm4. Each model output includes a mer object and a gam object.
>>> I need to compare 26 model structures based on a combination of variables and then conduct model averaging on the best models based on AIC.
>>> The problem is, each .rds file with model output is approximately 5GB. For all 26 models, there is no way I can load them into my R environment
>>> for any kind of model comparison or averaging. Similar models run with mgcv::gamm() were only 5.7 MB, which is a much more manageable size for comparisons.
>>> (Note: unfortunately I have to stay within the gamm4 package based on model structure, otherwise I would use the mgcv model outputs).
>>> Is there a way to decrease the size of the .rds file to a more reasonable size? Are there arguments within gamm4 or lme4 that could reduce the amount of
>>> extra information retained within the model?
> 
> I presume this is because gamm4's gam contains "model", which a copy of the data frame. Having little memory on my machine, I was
> save()'ing then removing each gamm4 model, while tabulating summaries for each model by hand (can run deviance(), AIC() etc for each).
> Do you have the same random effects fitted in each model? I have no idea if these models can be compared if the cross-validation selected gams
> have different edf's with different REs in the mer part. Maybe use gam to choose roughly equivalent polynomial fixed effects, then just do in lmer?
> 
> hth, David Duffy
> _______________________________________________
> R-sig-mixed-models using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models



More information about the R-sig-mixed-models mailing list