[R-sig-ME] update-function: frame problem with lmer-fit

Douglas Bates bates at stat.wisc.edu
Wed Jun 2 16:26:11 CEST 2010


I don't think it would be a good idea to use the model frame from the
previous fit because you may end up modifying the data in some way
during the update.  Also, a model frame is slightly different from a
data frame.

I agree that your initial attempt should work.  It is a matter of
determining in exactly which environment the revised call should be
evaluated and that is always tricky.

Because I am in the midst of a lot of development on glmer, nlmer,
etc.  and you were good enough to discover several workarounds, I
think I will leave this problem on the "To Do" list.

On Tue, Jun 1, 2010 at 8:16 AM, Ulrich Halekoh <Ulrich.Halekoh at agrsci.dk> wrote:
> #Dear
> # I got a framing problem with the update function
> # on a lmer-fit
> # if -data-generation,
> #    -lmer-fit,
> #    -call to update,
> # are called from within the same function.
>
> # Example:
> # Using update  on a lmer-fit 'gfit'
> # an the data 'ukkel' defined within
> # the function  fam1:
> # I get the error message
>
> # Error in inherits(x, "data.frame") : object 'ukkel' not found
>
> # I found several work around(s), but I wonder whether 'update' should not
> #  find the data.frame of the fitted object as it does for lm-objects.
>
>
> #Ulrich
>
>
> library(lme4)
> fam1<-function(){
> #data generation:
>  set.seed(89)
>  ukkel<- data.frame(y=rnorm(100),id=rep(c(1,2,3,4),25))
> #lmer fit:
>  gfit<- lmer(y ~  1 + (1|id), data=ukkel)
> #update:
>  update(gfit)
> }
>
> try(fam1())
>
> #providing the data frame explicitely in 'update' works:
> fam2<-function(){
> set.seed(89)
> #data generation:
> ukkel<- data.frame(y=rnorm(100),id=rep(c(1,2,3,4),25))
> #lmer fit:
>  gfit<- lmer(y ~  1 + (1|id), data=ukkel)
> #update:
>  update(gfit,data=gfit at frame)
> }
>
> try(fam2())
>
>
>
> #providing the data frame before calling the function works
>
> fam3<-function(){
>  g<- lmer(y ~  1 +(1|id), data=ukkel)
>  update(g)
> }
>
> set.seed(89)
> ukkel<- data.frame(y=rnorm(100),id=rep(c(1,2,3,4),25))
> fam3()
>
>
>
>
>
> ## The same like fam1 but with 'lm' instead of 'lmer'  works
> rm(ukkel)
> ham1<-function(){
>  ukkel<- data.frame(y=rnorm(100),id=rep(c(1,2,3,4),25))
>  set.seed(89)
>  g<- lm(y ~  1, data=ukkel)
>  update(g)
> }
>
> ham1()
>
>
>
> Package lme4 version 0.999375-33
> R-version:
> platform       i386-pc-mingw32
> arch           i386
> os             mingw32
> system         i386, mingw32
> status
> major          2
> minor          11.0
> year           2010
> month          04
> day            22
> svn rev        51801
> language       R
> version.string R version 2.11.0 (2010-04-22)
>
> Kind regards
> Ulrich Halekoh
> Dept. of Genetics and Biotechnology
> Faculty of Agricultural Sciences
> Aarhus University
> Email: Ulrich.Halekoh at agrsci.dk<mailto:Ulrich.Halekoh at agrsci.dk>
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-mixed-models at 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