[R] how to store lme/lmer fit result

Douglas Bates bates at stat.wisc.edu
Mon Nov 3 17:51:34 CET 2008

On Thu, Oct 9, 2008 at 8:51 PM, liujb <liujulia7 at yahoo.com> 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.

More information about the R-help mailing list