Search code examples
rlme4mixed-modelsstatistics-bootstrap

How to bootstrap R-squared of a mixed model?


I'm trying to obtain bootstrapped R^2 for a mixed effect model. As there is already only a workaround to obtain the conditional and marginal R^2, I tried to bootstrap these statistic based on an example given by statmethods for bootstrapping a single statistic. The code works but the bias and standard error are always zero.

library(lme4)
library(boot)
data(Dyestuff, package = "lme4")
model <- lmer(Yield ~ 1|Batch, data=Dyestuff)
summary(model)
r.squaredGLMM(model)

rsq <- function(formula, data, indices) {
  d <- data[indices,] 
  model.fit <- lmer(Yield ~ 1|Batch, data=Dyestuff)
  fit.r.squared <- r.squaredGLMM(model.fit)
  return(summary(fit.r.squared[,2]))
}

set.seed(101)
results <- boot(data=Dyestuff, statistic=rsq,
                R=1000, formula=Yield ~ 1|Batch)

results


Bootstrap Statistics :
     original  bias    std. error
t1* 0.4184874       0           0
t2* 0.4184874       0           0
t3* 0.4184874       0           0
t4* 0.4184874       0           0
t5* 0.4184874       0           0
t6* 0.4184874       0           0

Shouldn't the conditional and marginal R^2 also change when I bootstrap a model? And is there any other way to obtain bootstrapped conditional and marginal R^2?


Solution

  • rsq <- function(formula, data, indices) {
      d <- data[indices,] 
      model.fit <- lmer(Yield ~ 1|Batch, data = d)
      fit.r.squared <- r.squaredGLMM(model.fit)
      return(fit.r.squared[,2])
    }