[R] how to store lme/lmer fit result

tingtingzhan tingting.zhan at jefferson.edu
Fri Mar 4 05:29:22 CET 2011


Hi All,

I'm experiencing difficulties in saving a model fit by gls().  

Basically if I just save() a gls object "gls.fit" in my workspace into an
.RData file and later reload this .RData file, I get error when running
script such as 
summary(gls.fit)$coefficients

Dr. Bates's reply (quoted below) is the latest info I could find by Google.  
Would any one suggest if there is any modern way to save an gls object?

Many thanks,
Tingting





Re: how to store lme/lmer fit result
Nov 03, 2008; 11:51am — by   Douglas Bates-2
On Thu, Oct 9, 2008 at 8:51 PM, liujb <[hidden email]> 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. 

--
View this message in context: http://r.789695.n4.nabble.com/how-to-store-lme-lmer-fit-result-tp869777p3334663.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list