Skip to contents

Given a set of event data for multiple sites, fit a Bayesian hierarchical Poisson model to the site-specific event rates.

Usage

fitBayesPoissonModel(
  data,
  events = NULL,
  exposure = NULL,
  model = NULL,
  inits = NULL,
  nChains = ifelse(is.null(inits), 2, length(inits)),
  ...
)

Arguments

data

the data frame containing the eventVar and exposureVar columns

events

The number of events per site. If NULL the "posterior" distribution will be MCMC samples from the prior.

exposure

The exposure per site. If NULL the "posterior" distribution will be MCMC samples from the prior.

model

The character string containing the JAGS model to be fitted. If NULL, obtained from getModelString("binomial).

inits

A list of JAGS inits lists suitable for use with this model. If NULL (the default), nChains random inits are generated by .createPoissonInit.

nChains

The number of chains to use. Default 2. If inits is not NULL, must equal length(inits) or be NULL.

...

passed to .createPoissonInit or .autorunJagsAndCaptureOutput

Value

A tibble with four columns

lambda

Simulated values from the posterior distribution of the rates.

shape

Simulated values from the posterior distribution of the shape.

scale

Simulated values from the posterior distribution of the scale.

q

Percentile in each which lambda value falls.

Details

Adverse events at a given site are assumed to follow a Poisson distribution, a standard statistical distribution that expresses the probability of a given number of events in a fixed time interval. The probability depends on a site-specific rate parameter \(\lambda_i\) multiplied by the exposure (total time on treatment for all patients at that site). The site-specific event rates, \(\lambda_i\), are assumed to follow a Gamma distribution; a positive continuous distribution with two parameters, shape and scale, that determine the average rate and how spread the probability of different rates is around that average. Uncertainty in the shape and scale of this distribution is accounted for by specifying prior distributions on these parameters. These "hyper-priors" are also specified as Gamma distributions.

The parameters of the hyper-priors are specified by shape and scale. The default settings specify Gamma(1, 1) distributions which are equivalent to Exp(1) distributions.

The Bayesian Hierarchical Model then estimates the posterior distribution for the unknown parameters \(\lambda_i\), scale and shape, given the observed events. Under Bayes Theorem this is proportional to the likelihood of the observed data given the parameters multiplied by the prior for the parameters. The prior can be informed by historical data and/or expert knowledge. As more data are available, the posterior is less influenced by the prior and more influenced by the data.

The exact posterior distribution cannot be computed directly, hence a Markov Chain Monte Carlo (MCMC) method is used to simulate values of \(\lambda_i\), scale and shape from the posterior distribution. Two Markov chains are used, with a minimum of 10,000 values simulated after 4000 burn-in iterations and 1000 adaptive iterations. The chains are checked for convergence and the simulation is extended if required to meet convergence diagnostics. The samples from both chains are combined in the returned value.

Examples


# load example site rates
data(siteRates)

# fit MCMC Poisson model with default hyperpriors (basis 1 month)
results <- siteRates %>% fitBayesPoissonModel(Events, Exposure)
#> INFO [2024-11-01 09:30:51] Status of model fitting: OK