R Programming/Count Data Models
Appearance
The Poisson model
[edit | edit source]Fake data simulations
[edit | edit source]We assume that y follows a poisson distribution with mean exp(1 + 1 * x). We store the data in the "df" dataframe.
N <- 1000
x <- rnorm(N)
alpha <- c(1,1)
y <- rpois(N,exp(alpha[1] + alpha[2] * x))
df <- data.frame(x,y)
plot(x,y)
Maximum likelihood
[edit | edit source]We estimate this simple model using the glm() function with family = poisson as option.
fit <- glm(y ~ x, family = poisson, data = df)
summary(fit)
Bayesian estimation
[edit | edit source]The model can also be estimated using bayesian methods with the MCMCpoisson()
function which is provided in the MCMCpack.
library("MCMCpack")
posterior <- MCMCpoisson(y ~ x, data = df)
plot(posterior)
summary(posterior)
Overdispersion test
[edit | edit source]- dispersiontest() (AER package) provides a test for equidispersion.
Zero inflated model
[edit | edit source]See the zic package[1]
Bivariate poisson regression
[edit | edit source]- bivpois package for bivariate poisson regression.
References
[edit | edit source]- See UCLA website for an example
- Zeileis, A., Kleiber, C. and Jackman, S. Regression Models for Count Data in R
- Replication files for Cameron and Trivedi's 1998 book[2] are provided in the AER package[3]. You can simply type ?CameronTrivedi1998 and you will find the source code.
- ↑ Markus Jochmann (2010). zic: Bayesian Inference for Zero-Inflated Count Models. R package version 0.5-3. http://CRAN.R-project.org/package=zic
- ↑ Cameron, A.C. and Trivedi, P.K. (1998). Regression Analysis of Count Data. Cambridge: Cambridge University Press.
- ↑ Christian Kleiber and Achim Zeileis (2008). Applied Econometrics with R. New York: Springer-Verlag. ISBN 978-0-387-77316-2. URL http://CRAN.R-project.org/package=AER