From: Bayesian Models for Astrophysical Data, Cambridge Univ. Press

(c) 2017,  Joseph M. Hilbe, Rafael S. de Souza and Emille E. O. Ishida  

 

you are kindly asked to include the complete citation if you used this material in a publication

Code 6.2 Synthetic Poisson data and model in R: binary and continuous predictors

============================================================

set.seed(18472)
nobs <- 750 

x1_2 <- rbinom(nobs,size=1,prob=0.7)
x2 <- rnorm(nobs,0,1)
xb <- 1 - 1.5*x1_2 - 3.5*x2

exb <- exp(xb)
py <- rpois(nobs, exb)
pois <- data.frame(py, x1_2, x2)


poi <- glm(py ~ x1_2 + x2, family=poisson, data=pois)

summary(poi)

============================================================

Output on screen:

Call:

glm(formula = py ~ x1_2 + x2, family = poisson, data = pois)

 

Deviance Residuals:

     Min             1Q       Median             3Q          Max

-3.5920      -0.5973      -0.1834       0.2879       3.5145

 

Coefficients:

                         Estimate      Std. Error          z value                  Pr(>|z|)

(Intercept)       1.003426       0.010634            94.36                   <2e-16 ***

x1_2               -1.507078      0.004833          -311.81                  <2e-16 ***

x2                   -3.500726      0.004228          -828.00                  <2e-16 ***

---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

 

(Dispersion parameter for poisson family taken to be 1)

 

       Null deviance: 1821132.15 on 749 degrees of freedom

Residual deviance:         598.59 on 747 degrees of freedom

AIC: 2439.6

 

Number of Fisher Scoring iterations: 4