## ----vignette-nowrap-options, include = FALSE, eval = [encoded data, 9944 characters]
options(width = 10000)

## ----setup, include = [encoded data, 9976 characters]
source("vignette-cache.R", local = knitr::knit_global())

cached_fits <- vignette_cache(
  name    = "v32-robma-multilevel",
  objects = c("fit", "fit_simple")
)

knitr::opts_chunk$set(
  collapse    = TRUE,
  comment     = "#>",
  eval        = vignette_cache_eval(cached_fits),
  message     = FALSE,
  warning     = FALSE,
  fig.width   = 7,
  fig.height  = 3.5,
  dev         = "png",
  fig.retina  = 3
)
if (.Platform$OS.type == "windows") {
  knitr::opts_chunk$set(dev.args = list(type = "cairo"))
}

## ----load-models, include = [encoded data, 9970 characters]
library("RoBMA")

data("Johnides2025", package = "RoBMA")

vignette_cache_load(cached_fits)

## ----precompute-models, include = FALSE, eval = [encoded data, 9950 characters]
# library("RoBMA")
# 
# data("Johnides2025", package = "RoBMA")
# 
# prior_effect_361        <- prior("normal",   list(mean = 0, sd = 1))
# prior_heterogeneity_361 <- prior("invgamma", list(shape = 1, scale = 0.15))
# 
# fit <- RoBMA(
#   yi = d, sei = se, measure = "SMD", cluster = study,
#   prior_effect        = prior_effect_361,
#   prior_heterogeneity = prior_heterogeneity_361,
#   adapt = 5000, burnin = 5000, sample = 10000,
#   parallel  = TRUE, seed = 1, data = Johnides2025
# )
# 
# fit_simple <- RoBMA(
#   yi = d, sei = se, measure = "SMD",
#   prior_effect        = prior_effect_361,
#   prior_heterogeneity = prior_heterogeneity_361,
#   adapt = 5000, burnin = 5000, sample = 10000,
#   parallel  = TRUE, seed = 1, data = Johnides2025
# )
# 
# vignette_cache_save(cached_fits)

## [encoded data, 9997 characters]
library(RoBMA)
data("Johnides2025", package = "RoBMA")

## [encoded data, 9997 characters]
head(Johnides2025)

## [encoded data, 9997 characters]
prior_effect_361        <- prior("normal",   list(mean = 0, sd = 1))
prior_heterogeneity_361 <- prior("invgamma", list(shape = 1, scale = 0.15))

## ----eval = [encoded data, 9986 characters]
# fit <- RoBMA(
#   yi = d, sei = se, measure = "SMD", cluster = study,
#   prior_effect        = prior_effect_361,
#   prior_heterogeneity = prior_heterogeneity_361,
#   adapt = 5000, burnin = 5000, sample = 10000,
#   parallel  = TRUE, seed = 1, data = Johnides2025
# )

## [encoded data, 9997 characters]
summary(fit)

## [encoded data, 9997 characters]
summary_heterogeneity(fit)

## [encoded data, 9997 characters]
summary_models(fit)

## ----fig.width = 6, fig.height = [encoded data, 9965 characters]
plot_weightfunction(fit)

## ----eval = [encoded data, 9986 characters]
# fit_simple <- RoBMA(
#   yi = d, sei = se, measure = "SMD",
#   prior_effect        = prior_effect_361,
#   prior_heterogeneity = prior_heterogeneity_361,
#   adapt = 5000, burnin = 5000, sample = 10000,
#   parallel  = TRUE, seed = 1, data = Johnides2025
# )

## [encoded data, 9997 characters]
summary(fit_simple)

