rmixed-modelsrobust

How to obtain R^2 for robust mixed effect model (rlmer command; robustlmm)?


I estimated a robust mixed effect model with the rlmercommand from the robustlmmpackage. Is there a way to obtain the marginal and conditional R^2 values?


Solution

  • Just going to answer that myself. I could not find a package or rather a function in R that is equivalent to e.g. r.squaredGLMM in the case of lmerMod objects but I found a quick workaround that works with rlmerMod objects. Basically you just have to extract the variance components for the fixed effects, random effects and residuals and then manually calcualte the marginal and conditional R^2 based on the formula provided by Nakagawa & Schielzeth (2013).

    library(robustlmm)
    library(insight)
    library(lme4)
    data(Dyestuff, package = "lme4")
    robust.model <- rlmer(Yield ~ 1|Batch, data=Dyestuff)
    var.fix <- get_variance_fixed(robust.model)
    var.ran <- get_variance_random(robust.model)
    var.res <- get_variance_residual(robust.model)
    R2m = var.fix/(var.fix+var.ran+var.res)
    R2c = (var.fix+var.ran)/(var.fix+var.ran+var.res)
    

    Literature:
    Nakagawa, S. and Schielzeth, H. (2013), A general and simple method for obtaining R2 from generalized linear mixed‐effects models. Methods Ecol Evol, 4: 133-142. doi:10.1111/j.2041-210x.2012.00261.x