#' Visualise between-study variability from a multinma model
#'
#' @param nma_mod A multinma model object.
#'
#' @export
tau <- function(nma_mod) {
tau_vals <-
summary(nma_mod) %>%
as.data.frame() %>%
dplyr::filter(parameter == "tau")
tau_quantiles <- tau_vals %>%
dplyr::select(4:8)
tau_quant_labs <-
tau_quantiles %>%
names() %>%
paste(collapse = ", ")
tibble::tibble(
x = rstan::extract(nma_mod$stanfit, pars = "tau")$tau %>% as.numeric()
) %>%
ggplot2::ggplot() +
ggplot2::geom_density(ggplot2::aes(x = x), alpha = 0.6) +
ggplot2::geom_vline(
xintercept = tau_quantiles %>% t(),
linetype = "dotted",
alpha = 0.6
) +
ggplot2::xlim(tau_vals$mean - 3*tau_vals$sd, tau_vals$mean + 3*tau_vals$sd) +
ggthemes::theme_tufte(
base_size = 17
) +
ggplot2::theme(
axis.text.y = ggplot2::element_blank(),
axis.ticks.y = ggplot2::element_blank()
) +
ggplot2::labs(
title = "Between-study variation",
subtitle = latex2exp::TeX(glue::glue("Mean $\\tau^2$ of {round(tau_vals$mean, 2)} across {nma_mod$network$studies %>% length()} studies")),
y = "",
x = "",
caption = glue::glue(
"Dotted lines indicate quantiles:
{tau_quant_labs}")
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.