#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@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@agrsci.dk<mailto:Ulrich.Halekoh@agrsci.dk>

	[[alternative HTML version deleted]]


