postmix {RBesT} | R Documentation |
Conjugate Posterior Analysis
Description
Calculates the posterior distribution for data data
given a prior
priormix
, where the prior is a mixture of conjugate distributions.
The posterior is then also a mixture of conjugate distributions.
Usage
postmix(priormix, data, ...)
## S3 method for class 'betaMix'
postmix(priormix, data, n, r, ...)
## S3 method for class 'normMix'
postmix(priormix, data, n, m, se, ...)
## S3 method for class 'gammaMix'
postmix(priormix, data, n, m, ...)
Arguments
priormix |
prior (mixture of conjugate distributions). |
data |
individual data. If the individual data is not given, then summary data has to be provided (see below). |
... |
includes arguments which depend on the specific case, see description below. |
n |
sample size. |
r |
Number of successes. |
m |
Sample mean. |
se |
Sample standard error. |
Details
A conjugate prior-likelihood pair has the convenient property that the posterior is in the same distributional class as the prior. This property also applies to mixtures of conjugate priors. Let
denote a conjugate mixture prior density for data
where is the likelihood. Then the posterior is
again a mixture with each component
equal to the respective
posterior of the
th prior component and updated weights
,
The weight for
th component is determined by the
marginal likelihood of the new data
under the
th prior
distribution which is given by the predictive distribution of the
th component,
The final weight is then given by appropriate
normalization,
. In other words, the weight of
component
is proportional to the likelihood that data
is generated from the respective component, i.e. the
marginal probability; for details, see for example Schmidli
et al., 2015.
Note: The prior weights are fixed, but the
posterior weights
still change due to the
changing normalization.
The data can either be given as individual data or as
summary data (sufficient statistics). See below for details for the
implemented conjugate mixture prior densities.
Methods (by class)
-
postmix(betaMix)
: Calculates the posterior beta mixture distribution. The individual data vector is expected to be a vector of 0 and 1, i.e. a series of Bernoulli experiments. Alternatively, the sufficient statisticsn
andr
can be given, i.e. number of trials and successes, respectively. -
postmix(normMix)
: Calculates the posterior normal mixture distribution with the sampling likelihood being a normal with fixed standard deviation. Either an individual data vectordata
can be given or the sufficient statistics which are the standard errorse
and sample meanm
. If the sample sizen
is used instead of the sample standard error, then the reference scale of the prior is used to calculate the standard error. Should standard errorse
and sample sizen
be given, then the reference scale of the prior is updated; however it is recommended to use the commandsigma
to set the reference standard deviation. -
postmix(gammaMix)
: Calculates the posterior gamma mixture distribution for Poisson and exponential likelihoods. Only the Poisson case is supported in this version.
Supported Conjugate Prior-Likelihood Pairs
Prior/Posterior | Likelihood | Predictive | Summaries |
Beta | Binomial | Beta-Binomial | n , r |
Normal | Normal (fixed ) | Normal | n , m , se |
Gamma | Poisson | Gamma-Poisson | n , m |
Gamma | Exponential | Gamma-Exp (not supported) | n , m
|
References
Schmidli H, Gsteiger S, Roychoudhury S, O'Hagan A, Spiegelhalter D, Neuenschwander B. Robust meta-analytic-predictive priors in clinical trials with historical control information. Biometrics 2014;70(4):1023-1032.
Examples
# binary example with individual data (1=event,0=no event), uniform prior
prior.unif <- mixbeta(c(1, 1, 1))
data.indiv <- c(1,0,1,1,0,1)
posterior.indiv <- postmix(prior.unif, data.indiv)
print(posterior.indiv)
# or with summary data (number of events and number of patients)
r <- sum(data.indiv); n <- length(data.indiv)
posterior.sum <- postmix(prior.unif, n=n, r=r)
print(posterior.sum)
# binary example with robust informative prior and conflicting data
prior.rob <- mixbeta(c(0.5,4,10),c(0.5,1,1))
posterior.rob <- postmix(prior.rob, n=20, r=18)
print(posterior.rob)
# normal example with individual data
sigma <- 88
prior.mean <- -49
prior.se <- sigma/sqrt(20)
prior <- mixnorm(c(1,prior.mean,prior.se),sigma=sigma)
data.indiv <- c(-46,-227,41,-65,-103,-22,7,-169,-69,90)
posterior.indiv <- postmix(prior, data.indiv)
# or with summary data (mean and number of patients)
mn <- mean(data.indiv); n <- length(data.indiv)
posterior.sum <- postmix(prior, m=mn, n=n)
print(posterior.sum)