Bayesian Poisson analysis | R Documentation |
Generates random draws from the posterior for a Poisson likelihood and gamma prior.
Bpoisson(y, n, priors=NULL, draws=10000, ...)
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. |
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.
Returns an object of class mcmcOutput
.
Mike Meredith.
# 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)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.