#' heterogeneity_metrics_for_forest
#'
#' This function converts a metafor metaanalysis fit object to a string that contains the I^2 and H^2 heterogeneity statistics so that it can easily be added to a metafor forest plot.
#' @param fit The meta analysis fit object outputted by sced_meta_analysis()
#' @export
#' @examples
#' # calculate participant level results
#' results <- sced_analysis(data = data)
#'
#' # fit meta
#' sced_meta_fit <- sced_meta_analysis(results = results, effect_size = "ruscios_A")
#'
#' # forest plot
#' metafor::forest(sced_meta_fit$model_fit,
#' xlab = "Probability of superiority",
#' transf = boot::inv.logit, # convert logits back to probabilities (ie Ruscio's A)
#' mlab = heterogeneity_metrics_for_forest(sced_meta_fit$model_fit),
#' digits = 2,
#' addcred = TRUE,
#' refline = 0.5)
#'
heterogeneity_metrics_for_forest <- function(fit) {
if(!is.null(fit$I2) & !is.null(fit$H2)){
bquote(paste("RE Model (",
italic('I')^"2", " = ", .(formatC(format(round(fit$I2, 1), nsmall = 1))),
"%, ", italic('H')^"2", " = ", .(formatC(format(round(fit$H2, 1), nsmall = 1))), ")"))
} else {
stop("I2 and/or H2 do not exist in the model object")
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.