[R-sig-ME] Bootstrapping an lmer model

Hugo Mildenberger Hugo.Mildenberger at web.de
Fri Nov 4 22:11:57 CET 2011


Dear Christoph,

I think I've finally fixed the bootstrap code. The output is reasonably
close to the output one gets from sim() when bootstrap was set to false,
and is also close to the original version. I think the observable small
differences may be explained by the state of the random number
generator. Anyway, please see the attached patch. I did comment my changes.

Prof. Bate's suggestion to use "getCall(object)" instead of
"object at call" did not work because the left assignment operator is
apparently not available then.

Plotting the results returned by sim() aborts somewhere after the first
plot. This is not related to my patch. Another pre-existing Zelig defect
consist in the intercept always being included.

Lastly, you may wish to set cite=F [as in zelig(...,cite=F)] before
running sim with bootstrap=T. Else zelig() will tell you one thousand
times how to cite Zelig. This had irritated me very much, because I
thought I may  had triggered unwittingly a package reinitialization
during each simulation step. However, this is documented behaviour.


Kind regards

Hugo



Am 03.11.2011 22:14, schrieb Christoph Scherber:
> Dear Hugo & all,
> 
> Many thanks for this suggestion; I now temporarily replaced $ by @ in all
> relevant functions from Zelig. The problem is that Zelig uses many small
> subfunctions that all need to be checked for S4 compatibility (I´ve
> contacted the package authors on that).
> 
> The missing information was indeed the t.star code in boot(). This should
> do the job - I´ll get back to you once I´ve tried it out!
> 
> Thanks again for this great help. I guess quite a few users might be
> interested in that (given the recent posts about predictions from lmer
> models).
> 
> All the best
> Christoph
> 
> 
> 
>> Christoph,
>>
>>
>> it appears as if lme4 had dropped the $ operator. A first step to cope
>> with that is to replace "object$call" with "object at call" in
>> "Zelig/R/bootfn.default.R" (i.e. in Zelig package sources), another
>> involves editing "param.mixed.R" at the same place. But that still isn't
>> enough, because then boot::boot runs into an array index error. I'm
>> attaching a patch against the source tree contained in
>> Zelig_3.5.1.tar.gz, but I almost sure that the param.mixed.R patch is
>> not the right solution, whereas the patch against bootfn.default.R may
>> interfere with other packages. I'd contact the package's authors at this
>> point. The remaining
>>
>>   Error in t.star[r, ] <- res[[r]] :
>>     incorrect number of subscripts on matrix
>>
>> stems from boot::boot:
>>
>>  120     t.star <- matrix(, RR, length(t0))
>>  121     for (r in seq_len(RR)) t.star[r, ] <- res[[r]]
>>
>> res[[r]] is the list returned by param.mer() as defined in
>> Zelig/R/param.mixed.R  I'd think it can't be correct to assign a nested
>> list to  t.star. t.star is a matrix with dimensions 100, 3.
>>
>>
>> I hope this still helps a bit.
>>
>>
>> Best regards,
>>
>> Hugo
>>
>>
>>
>> Am 03.11.2011 14:55, schrieb Christoph Scherber:
>>> Dear all,
>>>
>>> Has anyone written some code to get predicted values from an lmer model
>>> using bootstrapping?
>>>
>>> The only available method seems to be the sim() function in package
>>> "Zelig". This works well if you don´t do bootstrapping. However, it
>>> doesn´t seem
>>> to work for bootstrap=TRUE:
>>>
>>> ##
>>> require(Zelig)
>>> data(voteincome)
>>>
>>> z.out1 <- zelig(vote ~ education + age + female + tag(1 | state),
>>> data = voteincome, model = "logit.mixed")
>>>
>>> x <- setx(z.out1, education = 4)
>>> s.out1 <- sim(z.out1, x = x, bootstrap=TRUE)
>>>
>>> #Error in `*tmp*`$call : $ operator not defined for this S4 class
>>>
>>> ##
>>>
>>> I´ve tried to modify some of the internal code from the sim() function,
>>> but couldn´t get it to work until now.
>>>
>>> I would greatly appreciate any help, ideas or suggestions.
>>>
>>> Best wishes,
>>> Christoph
>>>
>>> (using R 2.13.2 on Windows 7 64-Bit)
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> R-sig-mixed-models at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>>
> 
> 
> 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Zelig_3.5.1.fix-boot.patch
URL: <https://stat.ethz.ch/pipermail/r-sig-mixed-models/attachments/20111104/7496d986/attachment-0004.pl>


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