---
title: "Informed Bayesian Model-Averaged Meta-Analysis with Binary Outcomes"
author: "František Bartoš"
date: "`r Sys.Date()`"
output:
  rmarkdown::html_vignette:
    self_contained: yes
bibliography: ../inst/REFERENCES.bib
csl: ../inst/apa.csl
vignette: >
  %\VignetteIndexEntry{Informed Bayesian Model-Averaged Meta-Analysis with Binary Outcomes}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
  %\VignetteEngine{knitr::rmarkdown_notangle}
---

```{r setup, include = FALSE}
is_check <- ("CheckExEnv" %in% search()) ||
              any(c("_R_CHECK_TIMINGS_", "_R_CHECK_LICENSE_") %in% names(Sys.getenv())) ||
              !file.exists("../models/MedicineBiBMA/fit.RDS")
knitr::opts_chunk$set(
  collapse  = TRUE,
  comment   = "#>",
  eval      = !is_check,
  dev      = "png")
if(.Platform$OS.type == "windows"){
  knitr::opts_chunk$set(dev.args = list(type = "cairo"))
}
```
```{r include = FALSE}
library(RoBMA)
# we pre-load the RoBMA models, the fitting time is around 2-5 minutes
fit <- readRDS(file = "../models/MedicineBiBMA/fit.RDS")
```

```{r include = FALSE, eval = FALSE}
# R package version updating
library(RoBMA)

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

# p. 73 in https://www.cochranelibrary.com/cdsr/doi/10.1002/14651858.CD007094.pub5/epdf/full
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")

# domain specific prior distributions: Acute Respiratory Infections
fit <- BiBMA(
  x1          = events_experimental,
  x2          = events_control,
  n1          = observations_experimental,
  n2          = observations_control,
  study_names = study_names,
  priors_effect        = prior_informed("Acute Respiratory Infections", type = "logOR", parameter = "effect"),
  priors_heterogeneity = prior_informed("Acute Respiratory Infections", type = "logOR", parameter = "heterogeneity"),
  seed = 1
)

saveRDS(fit,  file = "../models/MedicineBiBMA/fit.RDS")
```

Bayesian model-averaged meta-analysis can be specified using the binomial likelihood and applied to data with dichotomous outcomes. This vignette illustrates how to do this with an example from @bartos2023empirical, who implemented a binomial-normal Bayesian model-averaged meta-analytic model and developed informed prior distributions for meta-analyses of binary and time-to-event outcomes based on the Cochrane database of systematic reviews (see @bartos2021bayesian for informed prior distributions for meta-analyses of continuous outcomes highlighted in [Informed Bayesian Model-Averaged Meta-Analysis in Medicine](MedicineBMA.html) vignette.


### Binomial-Normal Bayesian Model-Averaged Meta-Analysis

We illustrate how to fit the binomial-normal Bayesian model-averaged meta-analysis using the `RoBMA` R package. For this purpose, we reproduce the example of adverse effects of honey in treating acute cough in children from @bartos2023empirical, who reanalyzed two studies with adverse events of nervousness, insomnia, or hyperactivity in the honey vs. no treatment condition that were subjected to a meta-analysis by @oduwole2018honey. 

We load the RoBMA package and specify the number of adverse events and sample sizes in each arm as described on p. 73 [@oduwole2018honey].
```{r}
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")
``` 
Notice that both studies reported no adverse events in the control group. Using a normal-normal meta-analytic model with log odds ratios would require a continuity correction, which might result in bias. Binomial-normal models allow us to circumvent the issue by modeling the observed proportions directly (see @bartos2023empirical for more details).

First, we fit the binomial-normal Bayesian model-averaged meta-analysis using informed prior distributions based on the `Acute Respiratory Infections` subfield. We use the `BiBMA` function and specify the observed events (`x1` and `x2`) and sample size (`n1` and `n2`) of adverse events and sample sizes in each arm. We use the `prior_informed` function to specify the informed prior distributions for the individual medical subfields automatically.

```r
fit <- BiBMA(
  x1          = events_experimental,
  x2          = events_control,
  n1          = observations_experimental,
  n2          = observations_control,
  study_names = study_names,
  priors_effect        = prior_informed("Acute Respiratory Infections", type = "logOR", parameter = "effect"),
  priors_heterogeneity = prior_informed("Acute Respiratory Infections", type = "logOR", parameter = "heterogeneity"),
  seed = 1
)
```
with `priors_effect` and `priors_heterogeneity` corresponding to the $\mu \sim T(0,0.48,3)$ and $\tau \sim InvGamma(1.67, 0.45)$ prior distributions (see `?prior_informed` for more details regarding the informed prior distributions).

We obtain the output with the `summary` function. Adding the `conditional = TRUE` argument allows us to inspect the conditional estimates, i.e., the effect size estimate assuming that the models specifying the presence of the effect are true, and the heterogeneity estimates assuming that the models specifying the presence of heterogeneity are true. We also set the `output_scale = "OR"` argument to display the effect size estimates on the odds ratio scale.

```{r}
summary(fit, conditional = TRUE, output_scale = "OR")
```

The output from the `summary.RoBMA()` function has three parts. The first part, under the 'Robust Bayesian Meta-Analysis' heading provides a basic summary of the fitted models by component types (presence of the Effect and Heterogeneity). The results show that the inclusion Bayes factor for the effect corresponds to the one reported in @bartos2023empirical, $\text{BF}_{10} = 2.63$ and $\text{BF}_{\text{rf}} = 1.30$ (up to an MCMC error)---weak/undecided evidence for the presence of the effect and heterogeneity. 

The second part, under the 'Model-averaged estimates' heading displays the parameter estimates model-averaged across all specified models (i.e., including models specifying the effect size to be zero). These estimates are shrunk towards the null hypotheses of null effect or no heterogeneity in accordance with the posterior uncertainty about the presence of the effect or heterogeneity. We find the model-averaged mean effect OR = 3.39, 95% CI [0.84, 15.14], and a heterogeneity estimate $\tau_\text{logOR} = 0.42$, 95% CI [0.00, 2.59].

The third part, under the 'Conditional estimates' heading displays the conditional effect size and heterogeneity estimates (i.e., estimates assuming presence of the effect or heterogeneity) corresponding to the one reported in @bartos2023empirical, OR = 4.24, 95% CI [0.78, 17.61], and a heterogeneity estimate $\tau_\text{logOR} = 0.75$, 95% CI [0.10, 3.23].

We can also visualize the posterior distributions of the effect size and heterogeneity parameters using the `plot()` function. Here, we set the `conditional = TRUE` argument to display the conditional effect size estimate and `prior = TRUE` to include the prior distribution in the plot.

```{r fig_mu_BMA, dpi = 300, fig.width = 6, fig.height = 4, out.width = "75%", fig.align = "center"}
plot(fit, parameter = "mu", prior = TRUE, conditional = TRUE)
```

Additional visualizations and summaries are demonstrated in the [Reproducing BMA](ReproducingBMA.html) and [Informed Bayesian Model-Averaged Meta-Analysis in Medicine](MedicineBMA.html) vignettes.


### References
