Bpoisson: Bayesian analysis of count data

View source: R/Bpoisson.R

Bayesian Poisson analysisR Documentation

Bayesian analysis of count data

Description

Generates random draws from the posterior for a Poisson likelihood and gamma prior.

Usage

Bpoisson(y, n, priors=NULL, draws=10000, ...)

Arguments

y

the count

n

the sample size

priors

an optional list with elements specifying the priors for the mode and SD of the gamma prior distribution; see Details.

draws

the number of MCMC draws to be returned.

...

additional arguments to pass to the function.

Details

The function generates a vector of random draws from the posterior distribution of the probability of the observed count. It uses conjugacy to determine the parameters of the posterior gamma distribution, and draws independent values from this.

A prior can be specified with the priors argument. A gamma prior is used, specified by mode, mode, and SD, sd.

When priors = NULL (the default), a uniform prior corresponding to gamma(1, 0) is used.

Value

Returns an object of class mcmcOutput.

Author(s)

Mike Meredith.

Examples

# Generate a sample from a Poisson distribution, maybe the number of ticks
#   observed on a sample of rodents:
n <- 10  # number of trials (rodents examined)
( y <- rpois(n, 1.2) ) # number of ticks on each rodent
Bpoisson(sum(y), n)  # with uniform prior
plot(Bpoisson(sum(y), n))
Bpoisson(sum(y), n, priors=list(mode=1, sd=3))  # with informative prior
plot(Bpoisson(sum(y), n, priors=list(mode=1, sd=3)))

wiqid documentation built on Nov. 18, 2022, 1:07 a.m.