## ----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    = "v35-bma-glmm-medicine",
  objects = c("fit_BMA")
)

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

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

events_experimental        <- c(5, 2)
events_control             <- c(0, 0)
observations_experimental  <- c(35, 40)
observations_control       <- c(39, 40)
study_names                <- c("Paul 2007", "Shadkam 2010")

vignette_cache_load(cached_fits)

## ----include = FALSE, eval = [encoded data, 9969 characters]
# # R package version updating
# library(RoBMA)
# 
# events_experimental        <- c(5, 2)
# events_control             <- c(0, 0)
# observations_experimental  <- c(35, 40)
# observations_control       <- c(39, 40)
# study_names                <- c("Paul 2007", "Shadkam 2010")
# 
# fit_BMA <- BMA.glmm(
#   ai = events_experimental, n1i = observations_experimental,
#   ci = events_control, n2i = observations_control,
#   slab = study_names, measure = "OR",
#   prior_informed_field    = "medicine",
#   prior_informed_subfield = "Acute Respiratory Infections",
#   seed = 1, parallel = TRUE
# )
# 
# vignette_cache_save(cached_fits)

## [encoded data, 9997 characters]
library(RoBMA)

events_experimental        <- c(5, 2)
events_control             <- c(0, 0)
observations_experimental  <- c(35, 40)
observations_control       <- c(39, 40)
study_names                <- c("Paul 2007", "Shadkam 2010")

## [encoded data, 9997 characters]
summary(fit_BMA, conditional = TRUE, include_mcmc_diagnostics = FALSE)

## [encoded data, 9997 characters]
pooled_effect(fit_BMA, conditional = TRUE, transform = "EXP")
pooled_heterogeneity(fit_BMA, conditional = TRUE)

## ----fig_mu_BMA, fig.width = 6, fig.height = 4, out.width = "75%", fig.align = "center"[encoded data, 9911 characters]
par(mar = c(4, 4, 0, 4))
plot(fit_BMA, parameter = "mu", prior = TRUE, conditional = TRUE, lwd = 2)

