---
title: "dreamer Methods"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{dreamer Methods}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

# Bayesian Model Averaging in dreamer

Bayesian model averaging is a general mixture distribution, where each
mixture component is a different parametric model. Prior weights are placed
on each model and the posterior model weights are updated based on how well
each model fits the data.  Let $\mu(d)$ represent the mean of the dose response
curve at dose $d$, $y = \{y_1, \ldots, y_n\}$ be the observed data, and 
$m \in \{1, \ldots, M\}$ be an index on the $M$ parametric models.  Then the
posterior of the dose response curve, $\mu(d)$, of the Bayesian model
averaging model is

\begin{eqnarray*}
p(\mu(d) \mid y) &=& \sum_{m=1}^M p(\mu(d) \mid y, m) p(m \mid y) \\
p(m \mid y) &=& \frac{p(y \mid m) p(m)}{\sum_{m^* } p(y \mid m^* )p(m^*)}
\end{eqnarray*}

where $p(\mu(d) \mid y, m)$ is the posterior mean dose response curve from 
model $m$, $p(m \mid y)$ is the posterior weight of model $m$, $p(y \mid m)$
is the marginal likelihood of the data under model $m$, and $p(m)$ is the prior
weight assigned to model $m$. In cases where $p(y \mid m)$ is difficult to
compute, Gould (2019) proposed using the observed data's fit to the posterior
predictive distribution as a surrogate in calculating the posterior weights;
this is the approach used by dreamer.

dreamer supports a number of models including linear, quadratic, 
log-linear, log-quadratic, EMAX, exponential, for use as models that
can be included in the model averaging approach.  In addition, several
longitudinal models are also supported (see the dreamer vignette).  All of the above
models are available for both continuous and binary endpoints.

## Reference
Gould, A. Lawrence. "BMA‐Mod: A Bayesian model averaging strategy for determining dose‐response relationships in the presence of model uncertainty." *Biometrical Journal* 61.5 (2019): 1141-1159.