Re: [R] how to store lme/lmer fit result

From: Douglas Bates <>
Date: Mon, 03 Nov 2008 10:51:34 -0600

On Thu, Oct 9, 2008 at 8:51 PM, liujb <> wrote:

> Dear R users,

> I am building a hierarchical model on a large data set. It can take quite
> some time to finish one fit, I was just wondering whether it is possible to
> store the fit object (the result) to a file for later (offline) analysis.

As others have suggested, you can use save/load to save and restore the fitted model.

However, there is a problem with trying to save and load a model fit by lmer. These are S4 classed objects and can only be reloaded in a version of the lme4 package with the same definition of the S4 class. Unfortunately, as I develop the computing methods I change the class definition to reflect the newer approach. This can mean that you can restore a model fit with a previous version of the lme4 package but you can't do anything with it.

I regret that this happens but I do feel that the changes ultimately are beneficial. The best advice is that, in addition to saving the fitted model, you should also save the original data and a copy of the code that was used to fit the model.

An alternative is to save a copy of the lme4 package and the Matrix package along with the saved model so you can downdate those packages if necessary. This may be tricky because of dependencies between packages that may prevent downdating some but not all packages. mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Mon 03 Nov 2008 - 16:54:53 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 03 Nov 2008 - 17:30:38 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive