## ----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     = "v36-zplot",
  objects  = c(
    "fit_RE_Weingarten2018",
    "fit_RoBMA_Weingarten2018",
    "fit_RE_Hoppen2025",
    "fit_RoBMA_Hoppen2025",
    "fit_RE_Wang2025",
    "fit_RoBMA_Wang2025",
    "fit_RE_ManyLabs16",
    "fit_RoBMA_ManyLabs16"
  ),
  packages = c("metafor")
)

knitr::opts_chunk$set(
  collapse   = TRUE,
  comment    = "#>",
  eval       = vignette_cache_eval(cached_fits),
  message    = FALSE,
  warning    = FALSE,
  fig.width  = 7,
  fig.height = 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")
vignette_cache_load(cached_fits)

## ----precompute-models, include = FALSE, eval = [encoded data, 9950 characters]
# library("RoBMA")
# 
# # Ease of retrieval - Weingarten2018
# data("Weingarten2018", package = "RoBMA")
# Weingarten2018 <- Weingarten2018[Weingarten2018$standard_paradigm & Weingarten2018$proximal_dataset, ]
# Weingarten2018_z <- metafor::escalc(
#   ri = r_xy, ni = round(N), measure = "ZCOR", data = Weingarten2018
# )
# fit_RE_Weingarten2018 <- brma(
#   yi = yi, vi = vi, measure = "ZCOR",
#   cluster = paper_id, data = Weingarten2018_z,
#   sample = 10000, burnin = 10000, adapt = 10000,
#   chains = 5, parallel = TRUE, seed = 1
# )
# fit_RoBMA_Weingarten2018 <- RoBMA(
#   yi = yi, vi = vi, measure = "ZCOR",
#   cluster = paper_id, data = Weingarten2018_z,
#   sample = 10000, burnin = 10000, adapt = 10000,
#   chains = 5, parallel = TRUE, seed = 1
# )
# 
# # Social comparison - Hoppen2025
# data("Hoppen2025", package = "RoBMA")
# fit_RE_Hoppen2025 <- brma(
#   yi = d, sei = sqrt(v), measure = "SMD",
#   data = Hoppen2025,
#   sample = 10000, burnin = 5000, adapt = 5000,
#   chains = 5, parallel = TRUE, seed = 1
# )
# fit_RoBMA_Hoppen2025 <- RoBMA(
#   yi = d, sei = sqrt(v), measure = "SMD",
#   data = Hoppen2025,
#   sample = 10000, burnin = 5000, adapt = 5000,
#   chains = 5, parallel = TRUE, seed = 1
# )
# 
# # ChatGPT - Wang2025
# data("Wang2025", package = "RoBMA")
# Wang2025 <- Wang2025[Wang2025$Learning_effect == "Learning performance", ]
# fit_RE_Wang2025 <- brma(
#   yi = g, sei = se, measure = "SMD",
#   data = Wang2025,
#   sample = 10000, burnin = 5000, adapt = 5000,
#   chains = 5, parallel = TRUE, seed = 1
# )
# fit_RoBMA_Wang2025 <- RoBMA(
#   yi = g, sei = se, measure = "SMD",
#   data = Wang2025,
#   sample = 10000, burnin = 5000, adapt = 5000,
#   chains = 5, parallel = TRUE, seed = 1
# )
# 
# # Many Labs 2 - ManyLabs16
# data("ManyLabs16", package = "RoBMA")
# fit_RE_ManyLabs16 <- brma(
#   yi = y, sei = se, measure = "SMD",
#   data = ManyLabs16,
#   sample = 10000, burnin = 5000, adapt = 5000,
#   chains = 5, parallel = TRUE, seed = 1
# )
# fit_RoBMA_ManyLabs16 <- RoBMA(
#   yi = y, sei = se, measure = "SMD",
#   data = ManyLabs16,
#   sample = 10000, burnin = 5000, adapt = 5000,
#   chains = 5, parallel = TRUE, seed = 1
# )
# 
# vignette_cache_save(cached_fits)

## ----message = [encoded data, 9983 characters]
library("RoBMA")

## [encoded data, 9997 characters]
data("Weingarten2018", package = "RoBMA")
Weingarten2018 <- Weingarten2018[Weingarten2018$standard_paradigm & Weingarten2018$proximal_dataset, ]
head(Weingarten2018)

## ----eval = [encoded data, 9986 characters]
# Weingarten2018_z <- metafor::escalc(
#   ri = r_xy, ni = round(N), measure = "ZCOR", data = Weingarten2018
# )
# 
# fit_RE_Weingarten2018 <- brma(
#   yi = yi, vi = vi, measure = "ZCOR",
#   cluster = paper_id, data = Weingarten2018_z,
#   sample = 10000, burnin = 10000, adapt = 10000,
#   chains = 5, parallel = TRUE, seed = 1)
# 
# fit_RoBMA_Weingarten2018 <- RoBMA(
#   yi = yi, vi = vi, measure = "ZCOR",
#   cluster = paper_id, data = Weingarten2018_z,
#   sample = 10000, burnin = 10000, adapt = 10000,
#   chains = 5, parallel = TRUE, seed = 1)

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

summary(fit_RoBMA_Weingarten2018)

## ----fig.cap="Ease-of-Retrieval Effect: Model Fit Assessment"[encoded data, 9937 characters]
hist(as_zplot(fit_RoBMA_Weingarten2018), from = -3, to = 6, by = 0.25)

lines(as_zplot(fit_RE_Weingarten2018),    from = -3, to = 6, col = "black", lty = 2, lwd = 2)
lines(as_zplot(fit_RoBMA_Weingarten2018), from = -3, to = 6, col = "blue",  lty = 2, lwd = 2)

legend(
  "topright",
  legend = c("Random-Effects", "RoBMA"),
  col = c("black", "blue"),
  lty = 2, lwd = 2)

## ----fig.cap="Ease-of-Retrieval Effect: Extrapolation Analysis"[encoded data, 9935 characters]
zplot(fit_RoBMA_Weingarten2018, from = -3, to = 6, by.hist = 0.25)

## [encoded data, 9997 characters]
summary(as_zplot(fit_RoBMA_Weingarten2018))

## [encoded data, 9997 characters]
data("Hoppen2025", package = "RoBMA")
head(Hoppen2025)

## ----eval = [encoded data, 9986 characters]
# fit_RE_Hoppen2025 <- brma(
#   yi = d, sei = sqrt(v), measure = "SMD",
#   data = Hoppen2025,
#   sample = 10000, burnin = 5000, adapt = 5000,
#   chains = 5, parallel = TRUE, seed = 1)
# 
# fit_RoBMA_Hoppen2025 <- RoBMA(
#   yi = d, sei = sqrt(v), measure = "SMD",
#   data = Hoppen2025,
#   sample = 10000, burnin = 5000, adapt = 5000,
#   chains = 5, parallel = TRUE, seed = 1)

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

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

## ----fig.cap="Social Comparison: Model Fit Assessment"[encoded data, 9944 characters]
hist(as_zplot(fit_RoBMA_Hoppen2025))

lines(as_zplot(fit_RE_Hoppen2025),    col = "black", lty = 2, lwd = 2)
lines(as_zplot(fit_RoBMA_Hoppen2025), col = "blue",  lty = 2, lwd = 2)

legend(
  "topright",
  legend = c("Random-Effects", "RoBMA"),
  col = c("black", "blue"),
  lty = 2, lwd = 2)

## ----fig.cap="Social Comparison: Extrapolation Analysis"[encoded data, 9942 characters]
zplot(fit_RoBMA_Hoppen2025)

## [encoded data, 9997 characters]
summary(as_zplot(fit_RoBMA_Hoppen2025))

## [encoded data, 9997 characters]
data("Wang2025", package = "RoBMA")
Wang2025 <- Wang2025[Wang2025$Learning_effect == "Learning performance", ]
head(Wang2025)

## ----eval = [encoded data, 9986 characters]
# fit_RE_Wang2025 <- brma(
#   yi = g, sei = se, measure = "SMD",
#   data = Wang2025,
#   sample = 10000, burnin = 5000, adapt = 5000,
#   chains = 5, parallel = TRUE, seed = 1)
# fit_RoBMA_Wang2025 <- RoBMA(
#   yi = g, sei = se, measure = "SMD",
#   data = Wang2025,
#   sample = 10000, burnin = 5000, adapt = 5000,
#   chains = 5, parallel = TRUE, seed = 1)

## ----fig.cap="ChatGPT: Model Fit Assessment"[encoded data, 9954 characters]
hist(as_zplot(fit_RoBMA_Wang2025), from = -2, to = 8)
lines(as_zplot(fit_RE_Wang2025),    col = "black", lty = 2, lwd = 2, from = -2, to = 8)
lines(as_zplot(fit_RoBMA_Wang2025), col = "blue",  lty = 2, lwd = 2, from = -2, to = 8)
legend(
  "topright",
  legend = c("Random-Effects", "RoBMA"),
  col = c("black", "blue"),
  lty = 2, lwd = 2)

## ----fig.cap="ChatGPT: Extrapolation Analysis"[encoded data, 9952 characters]
zplot(fit_RoBMA_Wang2025, from = -2, to = 8)

## [encoded data, 9997 characters]
summary(fit_RE_Wang2025)
summary(fit_RoBMA_Wang2025)

## [encoded data, 9997 characters]
summary(as_zplot(fit_RoBMA_Wang2025))

## [encoded data, 9997 characters]
data("ManyLabs16", package = "RoBMA")
head(ManyLabs16)

## ----eval = [encoded data, 9986 characters]
# fit_RE_ManyLabs16 <- brma(
#   yi = y, sei = se, measure = "SMD",
#   data = ManyLabs16,
#   sample = 10000, burnin = 5000, adapt = 5000,
#   chains = 5, parallel = TRUE, seed = 1)
# fit_RoBMA_ManyLabs16 <- RoBMA(
#   yi = y, sei = se, measure = "SMD",
#   data = ManyLabs16,
#   sample = 10000, burnin = 5000, adapt = 5000,
#   chains = 5, parallel = TRUE, seed = 1)

## ----fig.cap="Framing Effects: Model Fit Assessment"[encoded data, 9946 characters]
hist(as_zplot(fit_RoBMA_ManyLabs16))
lines(as_zplot(fit_RE_ManyLabs16),    col = "black", lty = 2, lwd = 2)
lines(as_zplot(fit_RoBMA_ManyLabs16), col = "blue",  lty = 2, lwd = 2)
legend(
  "topleft",
  legend = c("Random-Effects", "RoBMA"),
  col = c("black", "blue"),
  lty = 2, lwd = 2)

## ----fig.cap="Framing Effects: Extrapolation Analysis"[encoded data, 9944 characters]
zplot(fit_RoBMA_ManyLabs16)

## ----eval = [encoded data, 9986 characters]
# summary(fit_RE_ManyLabs16)
# summary(fit_RoBMA_ManyLabs16)

## [encoded data, 9997 characters]
summary(as_zplot(fit_RoBMA_ManyLabs16))

