0

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?

StupidWolf
  • 45,075
  • 17
  • 40
  • 72
Julian
  • 240
  • 1
  • 8

1 Answers1

1
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])
}
Roland
  • 127,288
  • 10
  • 191
  • 288
  • 1
    You can bootstrap the marginal R² too (but it's always 0). Just remove `[,2]`. – Roland Oct 15 '19 at 14:20
  • How can I obtain confidence intervals for the conditional R²? I tried the command `boot.ci(results, type="bca")` but it only shows me the results for the marginal R². Also when I try it with an example where the conditional R² is not 0. – Julian Nov 27 '19 at 17:44