top of page

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

​

​

# Data from code 6.9

library(MASS)

​

set.seed(141)
nobs <- 2500

​

x1 <- rbinom(nobs,size=1, prob=0.6)
x2 <- runif(nobs)
xb <- 1 + 2.0*x1 - 1.5*x2


a <- 3.3

theta <- 0.303                                                                 # 1/a


exb <- exp(xb)

nby <- rnegbin(n=nobs, mu=exb, theta=theta)
negbml <- data.frame(nby, x1, x2)

 

 

Code 6.10 Negative binomial model in R using COUNT

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

library(COUNT)

​

nb3 <- nbinomial(nby ~ x1 + x2, data=negbml)
summary(nb3)

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

Anchor 1

Output on screen:

​

​

Call:

nbinomial(formula1 = nby ~ x1 + x2,   data = negbml)

 

Deviance Residuals:

       Min.          1st Qu.        Median          Mean         3rd Qu.             Max.

-1.58697       -1.12176       -0.78956     -0.48925        0.06661         3.05031

​

Pearson Residuals:

         Min.         1st Qu.         Median          Mean            3rd Qu.              Max.

-0.539910      -0.510899     -0.445391      0.000391      0.069375      10.176786

​

Coefficients (all in linear predictor):

                     Estimate             SE           Z                     p        LCL       UCL

(Intercept)         0.986       0.0901       10.9        7.32e-28       0.809        1.16

x1                      2.040       0.0807       25.3      8.08e-141       1.882        2.20

x2                     -1.613       0.1373      -11.7        7.26e-32     -1.882      -1.34

(Intercept)_s      3.382       0.1232       27.4      7.53e-166      3.140        3.62

​

Null deviance:      3030.919     on     2498     d.f.

Residual deviance:     2355.517     on     2496     d.f.

Null Pearson:     4726.694     on   2498     d.f.

Residual Pearson:     2474.729     on     2496     d.f.

Dispersion:     0.9914778

AIC:     11552.61

​

Number of optimizer iterations:     88

bottom of page