Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: synthetic ZINB


From   jhilbe@aol.com
To   statalist@hsphsun2.harvard.edu
Subject   st: RE: synthetic ZINB
Date   Sun, 5 Jun 2011 19:31:50 -0400 (EDT)

Statalisters:

I happened to see a discussion of synthetic ZINB data on the StataList digest today. There is an entirely different way to approach this - one that creates a full synthetic ZINB model. I wrote about creating synthetic models in the first volume of the 2010 Stata Journal, and discuss them much more fully in my recently published, second edition of "Negative Binomial Regression" (Cambridge University Press, 572 pages). The book discusses most every count model in the literature, providing both Stata and R code for examples. Output is given in Stata, except for the final chapter on Bayesian NB models. I also develop a variety of synthetic count models where it is simple to write your chosen synthetic predictors as continuous predictors, as binary, or as multilevel categorical. You may employ as many predictors as you wish, from an intercept-only model to one with more than 10 predictors if you wish. The user specifes the desired coefficients for all predictors, as well as levels of predictor. For NB models you also declare the value of alpha you wish to model.

It was quite simple to convert the synthetic NB2-logit hurdle model I give in the book to a zero-inflated NB model, with a logit binary component. I am attaching it to this message, but provide it below my signature as well, together with a sample run. Note where the coefficient values are defined in the comment above active code, but the actual values are given in the code where indicated. I made the predictors here be simple normal variates, but more complex structures are described in the book, and in the Stata Journal article.

I find synthetic models like this very useful for testing model assumptions.

Best,  Joseph Hilbe

ZINB_SYN.DO
==================================================
* Zero inflated Negative binomial with logit as binary component
* Joseph Hilbe  5Jun2011   zinb_syn.do
* LOGIT: x1=-.9, x2=-.1, _c=-.2
* NB2  : x1=.75, n2=-1.25, _c=2, alpha=.5
clear
set obs 50000
set seed 1000
gen x1 = invnorm(runiform())
gen x2 = invnorm(runiform())
* NEGATIVE BINOMIAL- NB2
gen xb = 2 + 0.75*x1 - 1.25*x2
gen a = .5
gen ia = 1/a
gen exb = exp(xb)
gen xg = rgamma(ia, a)
gen xbg = exb * xg
gen nby = rpoisson(xbg)
* BERNOULLI
gen pi =1/(1+exp(-(.9*x1 + .1*x2+.2)))
gen bernoulli = runiform()>pi
gen zy = bernoulli*nby
rename zy y
* NB2-LOGIT HURDLE
zinb y x1 x2, inf(x1 x2) nolog
=================================



Zero-inflated negative binomial regression Number of obs = 50000 Nonzero obs = 19181 Zero obs = 30819

Inflation model = logit LR chi2(2) = 24712.97 Log likelihood = -88361.63 Prob > chi2 = 0.0000

-------------------------------------------------------------------------
-----
y | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+-----------------------------------------------------------
-----
y            |
x1 | .7407043 .0066552 111.30 0.000 .7276604 .7537483 x2 | -1.249479 .0067983 -183.79 0.000 -1.262804 -1.236155 _cons | 1.996782 .0069297 288.15 0.000 1.9832 2.010364
-------------+-----------------------------------------------------------
-----
inflate      |
x1 | .9047498 .0141011 64.16 0.000 .8771121 .9323875 x2 | .095477 .0125229 7.62 0.000 .0709326 .1200213 _cons | .2031966 .0121878 16.67 0.000 .179309 .2270841
-------------+-----------------------------------------------------------
-----
/lnalpha | -.6778044 .0153451 -44.17 0.000 -.7078803 -.6477286
-------------+-----------------------------------------------------------
-----
alpha | .5077305 .0077912 .4926874 .5232329
-------------------------------------------------------------------------
-----









Attachment: zinb_syn.do
Description: Binary data



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index