insight icon indicating copy to clipboard operation
insight copied to clipboard

Revise get_variance.lme()?

Open strengejacke opened this issue 5 years ago • 0 comments

Maybe related to this, we could use this code:

function (mod) 
{
  sigma_sq <- mod$sigma^2
  RE_params <- coef(mod$modelStruct$reStruct, FALSE)
  Tau_params <- RE_params * RE_params^(as.numeric(grepl("sd", 
    attr(RE_params, "names")))) * sigma_sq
  names(Tau_params) <- mapply(gsub, ".sd", ".var", names(Tau_params), 
    USE.NAMES = FALSE)
  cor_params <- as.double(coef(mod$modelStruct$corStruct, 
    FALSE))
  var_params <- as.double(coef(mod$modelStruct$varStruct, 
    FALSE))
  group_names <- names(mod$groups)
  Tau_param_list <- sapply(group_names, function(x) Tau_params[grep(x, 
    names(Tau_params))], simplify = FALSE, USE.NAMES = TRUE)
  fixed_sigma <- attr(mod$modelStruct, "fixedSigma")
  sigma_sq <- if (fixed_sigma) 
    NULL
  else sigma_sq
  varcomp <- list(Tau = Tau_param_list, cor_params = cor_params, 
    var_params = var_params, sigma_sq = sigma_sq)
  class(varcomp) <- "varcomp"
  return(varcomp)
}

Originally posted by @strengejacke in https://github.com/easystats/insight/issues/188#issuecomment-646970825

strengejacke avatar Jun 28 '20 12:06 strengejacke