Skip to content
Back to formatted view

Raw Message

Message-ID: <538140F1.7040407@gmail.com>
Date: 2014-05-25T01:01:37Z
From: Ben Bolker
Subject: Getting each bootstrapped data frame from bootMer
In-Reply-To: <B21F9ED4-84C5-446A-A9F8-A54A735437A9@wildcats.unh.edu>

On 14-05-22 11:26 AM, Daniel J Hocking wrote:
> I am trying to get bootstrapped predictions from a logistic glmer
> (lme4) object and compare them to the ?observed? independent variable
> from each bootstrap iteration. I can use bootMer to get the
> bootstrapped predictions:
> 
> bb <- bootMer(glmm.M35,
> FUN=function(x)predict(x,re.form=NA,newdata=df.fit,type="response"),
> nsim=10) # test with just 10 draws
> 
> but it doesn?t appear that bootMer saves the replicate datasets. Can
> anyone help me modify the bootMer function to output the bootstrap
> data frames or at least the independent variable (y) from each? Also
> any advice on handling the occasions when an iteration fails to
> converge in bootMer would be appreciated.

  I would be tempted just to re-invent the guts of bootMer, which are
not actually very complicated -- they're just a simulate/refit loop.  So
I might do something like

nsim <- 10
bootData <- simulate(glmm.M35,nsim)  ## data frame of sim data sets
predvals <- matrix(NA,nrow=length(df.fit),ncol=nsim)
set.seed(101)
for (i  in 1:10) {
   predvals[,i] <- predict(refit(glmm.M35,bootData[[i]]),
                     ...)
}

I also suspect (although haven't tried to check) that bootMer doesn't
use any random numbers other than the ones it uses to generate the
simulations, so you would *probably* be able to retrieve the response
values used if you just did this:

bootMer(...,seed=101)
bootData <- simulate(...,seed=101)

(slightly inefficient, but simulating the data is the smallest part of
the problem)

 hope that helps
    Ben Bolker




}

> 
> Thanks, Dan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Daniel
> Hocking Department of Environmental Conservation Northeast Climate
> Science Center University of Massachusetts
> 
> http://www.danieljhocking.wordpress.com 
> dhocking at umass.edu<mailto:dhocking at umass.edu> 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> [[alternative HTML version deleted]]
> 
> 
> 
> _______________________________________________ 
> R-sig-mixed-models at r-project.org mailing list 
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>