MCpoissongamma | R Documentation |
This function generates a sample from the posterior distribution of a Poisson likelihood with a Gamma prior.
MCpoissongamma(y, alpha, beta, mc = 1000, ...)
y |
A vector of counts (must be non-negative). |
alpha |
Gamma prior distribution shape parameter. |
beta |
Gamma prior distribution scale parameter. |
mc |
The number of Monte Carlo draws to make. |
... |
further arguments to be passed |
MCpoissongamma
directly simulates from the posterior distribution.
This model is designed primarily for instructional use.
\lambda
is the parameter of interest of the Poisson
distribution. We assume a conjugate Gamma prior:
\lambda \sim \mathcal{G}amma(\alpha, \beta)
y
is a vector of counts.
An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package.
plot.mcmc
, summary.mcmc
## Not run:
data(quine)
posterior <- MCpoissongamma(quine$Days, 15, 1, 5000)
summary(posterior)
plot(posterior)
grid <- seq(14,18,0.01)
plot(grid, dgamma(grid, 15, 1), type="l", col="red", lwd=3, ylim=c(0,1.3),
xlab="lambda", ylab="density")
lines(density(posterior), col="blue", lwd=3)
legend(17, 1.3, c("prior", "posterior"), lwd=3, col=c("red", "blue"))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.