#' get_icc() it reurns the intra class correlation of an mlm model
#'
#' @param mlm_model it requires an mlm_model, generated by lme4. If this is a null, is the percentage of variance between clusters.
#'
#' @return a numeric object.
#'
#' @details if the mlm_model is a null model it returns the ICC. If is a mlm_model with covariates, it returns the conditional variance between clusters.
#'
#' @examples
#'
#' lme4::lmer(y ~ 1 + (1|id_j), data = clustered_data, REML = FALSE) %>%
#' get_icc(.)
#'
#'
#' @export
get_icc <- function(x){
var_com <- broom.mixed::tidy(x) %>%
dplyr::filter(effect == 'ran_pars') %>%
dplyr::mutate(var = estimate^2) %>%
dplyr::mutate(per = var/sum(var))
icc <- as.numeric(dplyr::select(var_com, per)[1,])
return(icc)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.