[R-sig-ME] bug in refit function?

Ben Bolker bbolker at gmail.com
Thu Oct 10 18:51:42 CEST 2013


Ben Bolker <bbolker at ...> writes:

> 
> Alexandra Kuznetsova <alku <at> ...> writes:
> 
> > 
> > 
> > Hi all,
> > 
> > If I apply update function on the refit function, 
> then the refitted model
> becomes the initial model. The example:
> > 
> > > set.seed(101)
> > > Y <- matrix(rnorm(1000),ncol=2)
> > > d <- data.frame(y1=Y[,1],  x=rnorm(100), f=rep(1:10,10))
> > > fit1 <- lmer(y1 ~ x+(1|f),data=d)
> > > fit2 <- refit(fit1, newresp = Y[,2])
> > > all.equal(fit1, update(fit2))
> > [1] TRUE
> > 
> 
>   Thanks.  The problem is that update() works by evaluating
> the  <at> call slot, which doesn't get updated by refit.  We'll work
> on this.
> 

  Conversation continues at https://github.com/lme4/lme4/issues/142

My last update on the subject:

This is a little trickier than I thought. It's easy enough to update
the response column in the internal model frame slot, but the question
is whether one should try to update all references to y1 (in the
example above) to Y[,2] -- this is necessary if we want the results to
work with update(), which just goes to the environment (not to the
stored model frame) to re-evaluate the whole model ... otherwise, we
can replace the relevant slot in the model matrix, but unless we
update the formula to Y[,2] ~ ..., updating will just re-evaluate the
whole model, pulling y1 from d (where it hasn't changed, and where we
wouldn't want to change it!) and hence getting the old value, rather
than from model.frame(fit2)



More information about the R-sig-mixed-models mailing list