Bayesian Poisson Regression
Use the Poisson regression model if the observations of your dependent variable represents the number of independent events that occur during a fixed period of time. The model is fit using a random walk Metropolis algorithm. For a maximum-likelihood estimation of this model see poisson.
With reference classes:
z5 <- zpoissonbayes$new()
z5$zelig(Y ~ X1 + X2, weights = w, data = mydata)
z5$setx()
z5$sim()
With the Zelig 4 compatibility wrappers:
z.out <- zelig(Y ~ X1 + X2, model = "poisson.bayes", weights = w, data = mydata)
x.out <- setx(z.out)
s.out <- sim(z.out, x = x.out)
Use the following argument to monitor the Markov chain:
Use the following parameters to specify the model’s priors:
Zelig users may wish to refer to help(MCMCpoisson) for more information.
Attaching the sample dataset:
data(sanction)
Estimating the Poisson regression using poisson.bayes:
z.out <- zelig(num ~ target + coop, model = "poisson.bayes",
data = sanction, verbose = FALSE)
## Warning in readLines(zeligmixedmodels): incomplete final line found on
## '/usr/lib64/R/library/ZeligMultilevel/JSON/zelig5mixedmodels.json'
## How to cite this model in Zelig:
## Ben Goodrich, and Ying Lu. 2013.
## poisson-bayes: Bayesian Poisson Regression
## in Christine Choirat, Christopher Gandrud, James Honaker, Kosuke Imai, Gary King, and Olivia Lau,
## "Zelig: Everyone's Statistical Software," http://zeligproject.org/
You can check for convergence before summarizing the estimates with three diagnostic tests. See the section Diagnostics for Zelig Models for examples of the output with interpretation:
z.out$geweke.diag()
z.out$heidel.diag()
z.out$raftery.diag()
summary(z.out)
## Model:
##
## Iterations = 1001:11000
## Thinning interval = 1
## Number of chains = 1
## Sample size per chain = 10000
##
## 1. Empirical mean and standard deviation for each variable,
## plus standard error of the mean:
##
## Mean SD Naive SE Time-series SE
## (Intercept) -0.9798 0.1746 0.001746 0.00559
## target -0.0176 0.0567 0.000567 0.00189
## coop 1.2109 0.0470 0.000470 0.00152
##
## 2. Quantiles for each variable:
##
## 2.5% 25% 50% 75% 97.5%
## (Intercept) -1.33 -1.0934 -0.9777 -0.8612 -0.6456
## target -0.13 -0.0566 -0.0195 0.0203 0.0944
## coop 1.12 1.1789 1.2101 1.2415 1.3066
##
## Next step: Use 'setx' method
Setting values for the explanatory variables to their sample averages:
x.out <- setx(z.out)
Simulating quantities of interest from the posterior distribution given x.out.
s.out1 <- sim(z.out, x = x.out)
summary(s.out1)
##
## sim x :
## -----
## ev
## mean sd 50% 2.5% 97.5%
## [1,] 3.24 0.238 3.23 2.78 3.7
## pv
## mean sd 50% 2.5% 97.5%
## [1,] 3.23 1.8 3 0 7
Estimating the first difference in the number of countries imposing sanctions when the number of targets is set to be its maximum versus its minimum :
x.max <- setx(z.out, target = max(sanction$target))
x.min <- setx(z.out, target = min(sanction$target))
s.out2 <- sim(z.out, x = x.max, x1 = x.min)
summary(s.out2)
##
## sim x :
## -----
## ev
## mean sd 50% 2.5% 97.5%
## [1,] 3.19 0.294 3.18 2.64 3.8
## pv
## mean sd 50% 2.5% 97.5%
## [1,] 3.21 1.8 3 0 7
##
## sim x1 :
## -----
## ev
## mean sd 50% 2.5% 97.5%
## [1,] 3.31 0.306 3.3 2.73 3.94
## pv
## mean sd 50% 2.5% 97.5%
## [1,] 3.33 1.85 3 0 7
## fd
## mean sd 50% 2.5% 97.5%
## [1,] 0.115 0.367 0.127 -0.607 0.834
Let be the number of independent events that occur during a fixed time period.
The stochastic component is given by
where is the mean and variance parameter.
The systematic component is given by
where is the vector of explanatory variables for observation and is the vector of coefficients.
The prior for is given by
where is the vector of means for the explanatory variables and is the precision matrix (the inverse of a variance-covariance matrix).
The expected values (qi$ev) for the Poisson model are calculated as following:
given the posterior draws of based on the MCMC iterations.
The predicted values (qi$pr) are draws from the Poisson distribution with parameter .
The first difference (qi$fd) for the Poisson model is defined as
In conditional prediction models, the average expected treatment effect (qi$att.ev) for the treatment group is
where is a binary explanatory variable defining the treatment () and control () groups.
In conditional prediction models, the average predicted treatment effect (qi$att.pr) for the treatment group is
where is a binary explanatory variable defining the treatment () and control () groups.
The output of each Zelig command contains useful information which you may view. For example, if you run:
z.out <- zelig(y ~ x, model = "poisson.bayes", data)
you may examine the available information in z.out by using names(z.out), see the draws from the posterior distribution of the coefficients by using z.out$coefficients, and view a default summary of information through summary(z.out). Other elements available through the $ operator are listed below.
Bayesian poisson regression is part of the MCMCpack library by Andrew D. Martin and Kevin M. Quinn . The convergence diagnostics are part of the CODA library by Martyn Plummer, Nicky Best, Kate Cowles, and Karen Vines.
Martin AD, Quinn KM and Park JH (2011). “MCMCpack: Markov Chain Monte Carlo in R.” Journal of Statistical Software, 42 (9), pp. 22. <URL: http://www.jstatsoft.org/v42/i09/>.