------------------------------------------------------------------------------------------------------------- log: d:\spost.stata8\do\st8ch7.log log type: text opened on: 26 May 2003, 12:51:02 . . // * . // * RM4STATA Ch 7: Models for Count Outcomes - 5/26/2003 . // * . . // * section 7.1: the poisson distribution . . * generate the graph from this section . clear . set obs 25 obs was 0, now 25 . gen ya = .8 . poisson ya, nolog note: you are responsible for interpretation of non-count dep. variable Poisson regression Number of obs = 25 LR chi2(0) = 0.00 Prob > chi2 = . Log likelihood = -22.685774 Pseudo R2 = 0.0000 ------------------------------------------------------------------------------ ya | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- _cons | -.2231435 .2236068 -1.00 0.318 -.6614048 .2151177 ------------------------------------------------------------------------------ . prcounts pya, plot max(20) . gen yb = 1.5 . poisson yb, nolog note: you are responsible for interpretation of non-count dep. variable Poisson regression Number of obs = 25 LR chi2(0) = 0.00 Prob > chi2 = . Log likelihood = -29.41213 Pseudo R2 = 0.0000 ------------------------------------------------------------------------------ yb | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- _cons | .4054651 .1632993 2.48 0.013 .0854043 .7255259 ------------------------------------------------------------------------------ . prcounts pyb, plot max(20) . gen yc = 2.9 . poisson yc, nolog note: you are responsible for interpretation of non-count dep. variable Poisson regression Number of obs = 25 LR chi2(0) = 0.00 Prob > chi2 = . Log likelihood = -36.997981 Pseudo R2 = 0.0000 ------------------------------------------------------------------------------ yc | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- _cons | 1.064711 .117444 9.07 0.000 .8345247 1.294897 ------------------------------------------------------------------------------ . prcounts pyc, plot max(20) . gen yd = 10.5 . poisson yd, nolog note: you are responsible for interpretation of non-count dep. variable Poisson regression Number of obs = 25 LR chi2(0) = 0.00 Prob > chi2 = . Log likelihood = -52.564007 Pseudo R2 = 0.0000 ------------------------------------------------------------------------------ yd | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- _cons | 2.351375 .0617213 38.10 0.000 2.230404 2.472347 ------------------------------------------------------------------------------ . prcounts pyd, plot max(20) . label var pyapreq "mu=0.8" . label var pybpreq "mu=1.5" . label var pycpreq "mu=2.9" . label var pydpreq "mu=10.5" . label var pyaval "y=# of Events" . graph twoway connected pyapreq pybpreq pycpreq pydpreq pyaval, /// > ytitle("Probability") ylabel(0(.1).5) xlabel(0(2)20) . graph export 07poisson.eps, replace (file 07poisson.eps written in .eps format) . . // * section 7.1.1: fitting the poisson distribution with -poisson- . . use couart2, clear (Academic Biochemists / S Long) . describe Contains data from couart2.dta obs: 915 Academic Biochemists / S Long vars: 6 30 Jan 2001 10:49 size: 11,895 (99.9% of memory free) (_dta has notes) ------------------------------------------------------------------------------- storage display value variable name type format label variable label ------------------------------------------------------------------------------- art byte %9.0g Articles in last 3 yrs of PhD fem byte %9.0g sexlbl Gender: 1=female 0=male mar byte %9.0g marlbl Married: 1=yes 0=no kid5 byte %9.0g Number of children < 6 phd float %9.0g PhD prestige ment byte %9.0g Article by mentor in last 3 yrs ------------------------------------------------------------------------------- Sorted by: art . summarize Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- art | 915 1.692896 1.926069 0 19 fem | 915 .4601093 .4986788 0 1 mar | 915 .6622951 .473186 0 1 kid5 | 915 .495082 .76488 0 3 phd | 915 3.103109 .9842491 .755 4.62 -------------+-------------------------------------------------------- ment | 915 8.767213 9.483916 0 77 . poisson art, nolog Poisson regression Number of obs = 915 LR chi2(0) = 0.00 Prob > chi2 = . Log likelihood = -1742.5735 Pseudo R2 = 0.0000 ------------------------------------------------------------------------------ art | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- _cons | .5264408 .0254082 20.72 0.000 .4766416 .57624 ------------------------------------------------------------------------------ . . // * section 7.1.3: plotting the poisson distribution with -prcounts- . prcounts psn, plot max(9) . label var psnobeq "Observed Proportion" . label var psnpreq "Poisson Prediction" . label var psnval "# of Articles" . list psnval psnobeq psnpreq in 1/10 +------------------------------+ | psnval psnobeq psnpreq | |------------------------------| 1. | 0 .3005464 .1839859 | 2. | 1 .2688525 .311469 | 3. | 2 .1945355 .2636423 | 4. | 3 .0918033 .148773 | 5. | 4 .073224 .0629643 | |------------------------------| 6. | 5 .0295082 .0213184 | 7. | 6 .0185792 .006015 | 8. | 7 .0131148 .0014547 | 9. | 8 .0010929 .0003078 | 10. | 9 .0021858 .0000579 | +------------------------------+ . graph twoway connected psnobeq psnpreq psnval, /// > ytitle("Probability") ylabel(0(.1).4) /// > xlabel(0(1)9) /// > ysize(2.7051) xsize(4.0421) . graph export 07psnpred.eps, replace (file 07psnpred.eps written in .eps format) . . // * section 7.2.1: prm - estimation . . * non-integer outcomes - note warning! . use couart2, clear (Academic Biochemists / S Long) . gen artx = art + .3 . poisson artx fem mar kid5 phd ment, nolog note: you are responsible for interpretation of non-count dep. variable Poisson regression Number of obs = 915 LR chi2(5) = 159.17 Prob > chi2 = 0.0000 Log likelihood = -1657.3518 Pseudo R2 = 0.0458 ------------------------------------------------------------------------------ artx | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- fem | -.1907107 .0502018 -3.80 0.000 -.2891043 -.092317 mar | .1316254 .0565474 2.33 0.020 .0207946 .2424562 kid5 | -.1554186 .0367014 -4.23 0.000 -.2273519 -.0834852 phd | .0087834 .024396 0.36 0.719 -.0390317 .0565986 ment | .0226683 .0019232 11.79 0.000 .0188988 .0264378 _cons | .5034301 .0946822 5.32 0.000 .3178564 .6890038 ------------------------------------------------------------------------------ . . * if and in conditions . poisson art mar kid5 phd ment if fem==1, nolog Poisson regression Number of obs = 421 LR chi2(4) = 48.15 Prob > chi2 = 0.0000 Log likelihood = -694.23756 Pseudo R2 = 0.0335 ------------------------------------------------------------------------------ art | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- mar | .1894715 .0872897 2.17 0.030 .0183869 .3605562 kid5 | -.2159446 .0840449 -2.57 0.010 -.3806697 -.0512196 phd | .0932871 .0435731 2.14 0.032 .0078853 .1786888 ment | .0243915 .0043326 5.63 0.000 .0158998 .0328832 _cons | -.1769219 .1468787 -1.20 0.228 -.4647989 .1109551 ------------------------------------------------------------------------------ . . // * section 7.2.2: prm - example . . use couart2, clear (Academic Biochemists / S Long) . poisson art fem mar kid5 phd ment, nolog Poisson regression Number of obs = 915 LR chi2(5) = 183.03 Prob > chi2 = 0.0000 Log likelihood = -1651.0563 Pseudo R2 = 0.0525 ------------------------------------------------------------------------------ art | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- fem | -.2245942 .0546138 -4.11 0.000 -.3316352 -.1175532 mar | .1552434 .0613747 2.53 0.011 .0349512 .2755356 kid5 | -.1848827 .0401272 -4.61 0.000 -.2635305 -.1062349 phd | .0128226 .0263972 0.49 0.627 -.038915 .0645601 ment | .0255427 .0020061 12.73 0.000 .0216109 .0294746 _cons | .3046168 .1029822 2.96 0.003 .1027755 .5064581 ------------------------------------------------------------------------------ . . // * section 7.2.3: prm - interpretation using the rate mu . . * factor changes . listcoef fem ment, help poisson (N=915): Factor Change in Expected Count Observed SD: 1.926069 ---------------------------------------------------------------------- art | b z P>|z| e^b e^bStdX SDofX -------------+-------------------------------------------------------- fem | -0.22459 -4.112 0.000 0.7988 0.8940 0.4987 ment | 0.02554 12.733 0.000 1.0259 1.2741 9.4839 ---------------------------------------------------------------------- b = raw coefficient z = z-score for test of b=0 P>|z| = p-value for z-test e^b = exp(b) = factor change in expected count for unit increase in X e^bStdX = exp(b*SD of X) = change in expected count for SD increase in X SDofX = standard deviation of X . . * percent change . listcoef fem ment, percent help poisson (N=915): Percentage Change in Expected Count Observed SD: 1.926069 ---------------------------------------------------------------------- art | b z P>|z| % %StdX SDofX -------------+-------------------------------------------------------- fem | -0.22459 -4.112 0.000 -20.1 -10.6 0.4987 ment | 0.02554 12.733 0.000 2.6 27.4 9.4839 ---------------------------------------------------------------------- b = raw coefficient z = z-score for test of b=0 P>|z| = p-value for z-test % = percent change in expected count for unit increase in X %StdX = percent change in expected count for SD increase in X SDofX = standard deviation of X . . * marginal change with -prchange- . prchange phd ment, rest(mean) poisson: Changes in Predicted Rate for art min->max 0->1 -+1/2 -+sd/2 MargEfct phd 0.0794 0.0200 0.0206 0.0203 0.0206 ment 7.9124 0.0333 0.0411 0.3910 0.0411 exp(xb): 1.6101 fem mar kid5 phd ment x= .460109 .662295 .495082 3.10311 8.76721 sd(x)= .498679 .473186 .76488 .984249 9.48392 . . * marginal change with -mfx compute- . mfx compute Marginal effects after poisson y = predicted number of events (predict) = 1.6100936 ------------------------------------------------------------------------------ variable | dy/dx Std. Err. z P>|z| [ 95% C.I. ] X ---------+-------------------------------------------------------------------- fem*| -.3591461 .08648 -4.15 0.000 -.528643 -.189649 .460109 mar*| .2439822 .09404 2.59 0.009 .059671 .428293 .662295 kid5 | -.2976785 .06414 -4.64 0.000 -.423393 -.171964 .495082 phd | .0206456 .04249 0.49 0.627 -.062635 .103926 3.10311 ment | .0411262 .00317 12.97 0.000 .034912 .04734 8.76721 ------------------------------------------------------------------------------ (*) dy/dx is for discrete change of dummy variable from 0 to 1 . . * discrete change . prchange fem ment, rest(mean) poisson: Changes in Predicted Rate for art min->max 0->1 -+1/2 -+sd/2 MargEfct fem -0.3591 -0.3591 -0.3624 -0.1804 -0.3616 ment 7.9124 0.0333 0.0411 0.3910 0.0411 exp(xb): 1.6101 fem mar kid5 phd ment x= .460109 .662295 .495082 3.10311 8.76721 sd(x)= .498679 .473186 .76488 .984249 9.48392 . prchange kid5, uncentered x(kid5=1) poisson: Changes in Predicted Rate for art min->max 0->1 +1 +sd MargEfct kid5 -0.7512 -0.2978 -0.2476 -0.1934 -0.2711 exp(xb): 1.4666 fem mar kid5 phd ment x= .460109 .662295 1 3.10311 8.76721 sd(x)= .498679 .473186 .76488 .984249 9.48392 . prchange kid5, uncentered x(kid5=1) delta(2) poisson: Changes in Predicted Rate for art (Note: delta = 2) min->max 0->1 +delta +sd MargEfct kid5 -0.7512 -0.2978 -0.4533 -0.1934 -0.2711 exp(xb): 1.4666 fem mar kid5 phd ment x= .460109 .662295 1 3.10311 8.76721 sd(x)= .498679 .473186 .76488 .984249 9.48392 . . // * section 7.2.4: prm - interpretation using predicted probabilities . . * -prvalue- . * single women without children . quietly prvalue, x(mar=0 fem=1 kid5=0) rest(mean) save . * compared to married women without children . prvalue, x(mar=1 fem=1 kid5=0) rest(mean) dif poisson: Change in Predictions for art Predicted rate: 1.65 95% CI [1.49 , 1.82] Saved: 1.41 Difference: .237 Predicted probabilities: Current Saved Difference Pr(y=0|x): 0.1926 0.2441 -0.0515 Pr(y=1|x): 0.3172 0.3442 -0.0270 Pr(y=2|x): 0.2613 0.2427 0.0186 Pr(y=3|x): 0.1434 0.1141 0.0293 Pr(y=4|x): 0.0591 0.0402 0.0188 Pr(y=5|x): 0.0195 0.0113 0.0081 Pr(y=6|x): 0.0053 0.0027 0.0027 Pr(y=7|x): 0.0013 0.0005 0.0007 Pr(y=8|x): 0.0003 0.0001 0.0002 Pr(y=9|x): 0.0000 0.0000 0.0000 fem mar kid5 phd ment Current= 1 1 0 3.1031093 8.7672131 Saved= 1 0 0 3.1031093 8.7672131 Diff= 0 1 0 0 0 . * effects of number of children . prvalue, x(mar=1 fem=1 kid5=0) rest(mean) brief Predicted rate: 1.65 Predicted probabilities: Pr(y=0|x): 0.1926 Pr(y=1|x): 0.3172 Pr(y=2|x): 0.2613 Pr(y=3|x): 0.1434 Pr(y=4|x): 0.0591 Pr(y=5|x): 0.0195 Pr(y=6|x): 0.0053 Pr(y=7|x): 0.0013 Pr(y=8|x): 0.0003 Pr(y=9|x): 0.0000 . prvalue, x(mar=1 fem=1 kid5=1) rest(mean) brief Predicted rate: 1.37 Predicted probabilities: Pr(y=0|x): 0.2544 Pr(y=1|x): 0.3482 Pr(y=2|x): 0.2384 Pr(y=3|x): 0.1088 Pr(y=4|x): 0.0372 Pr(y=5|x): 0.0102 Pr(y=6|x): 0.0023 Pr(y=7|x): 0.0005 Pr(y=8|x): 0.0001 Pr(y=9|x): 0.0000 . prvalue, x(mar=1 fem=1 kid5=2) rest(mean) brief Predicted rate: 1.14 Predicted probabilities: Pr(y=0|x): 0.3205 Pr(y=1|x): 0.3647 Pr(y=2|x): 0.2075 Pr(y=3|x): 0.0787 Pr(y=4|x): 0.0224 Pr(y=5|x): 0.0051 Pr(y=6|x): 0.0010 Pr(y=7|x): 0.0002 Pr(y=8|x): 0.0000 Pr(y=9|x): 0.0000 . prvalue, x(mar=1 fem=1 kid5=3) rest(mean) brief Predicted rate: .946 Predicted probabilities: Pr(y=0|x): 0.3883 Pr(y=1|x): 0.3673 Pr(y=2|x): 0.1737 Pr(y=3|x): 0.0548 Pr(y=4|x): 0.0130 Pr(y=5|x): 0.0025 Pr(y=6|x): 0.0004 Pr(y=7|x): 0.0001 Pr(y=8|x): 0.0000 Pr(y=9|x): 0.0000 . . * -prgen- . * for women . prgen kid5, x(fem=1 mar=1) rest(mean) from(0) to(3) gen(fprm) n(4) poisson: Predicted values as kid5 varies from 0 to 3. fem mar kid5 phd ment x= 1 1 .49508197 3.1031093 8.7672131 . * for men . prgen kid5, x(fem=0 mar=1) rest(mean) from(0) to(3) gen(mprm) n(4) poisson: Predicted values as kid5 varies from 0 to 3. fem mar kid5 phd ment x= 0 1 .49508197 3.1031093 8.7672131 . label var fprmp0 "Married Women" . label var mprmp0 "Married Men" . label var mprmx "Number of Children" . * graph predictions . graph twoway connected fprmp0 mprmp0 mprmx, /// > ylabel(0(.1).4) yline(.1 .2 .3) /// > xlabel(0(1)3) /// > ytitle("Probability of No Articles") /// > ysize(2.5051) xsize(4.0421) . graph export 07prmprob0.eps, replace (file 07prmprob0.eps written in .eps format) . . * list the predictions . list fprmp0 mprmp0 mprmx in 1/4 +-----------------------------+ | fprmp0 mprmp0 mprmx | |-----------------------------| 1. | .1926145 .1272223 0 | 2. | .2543503 .180182 1 | 3. | .320475 .2406279 2 | 4. | .3883428 .3060368 3 | +-----------------------------+ . . * -prcounts- . * for univariate poisson distribution . poisson art, nolog Poisson regression Number of obs = 915 LR chi2(0) = 0.00 Prob > chi2 = . Log likelihood = -1742.5735 Pseudo R2 = 0.0000 ------------------------------------------------------------------------------ art | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- _cons | .5264408 .0254082 20.72 0.000 .4766416 .57624 ------------------------------------------------------------------------------ . prcounts psn, plot max(9) . label var psnpreq "Univariate Poisson Dist." . poisson art fem mar kid5 phd ment, nolog Poisson regression Number of obs = 915 LR chi2(5) = 183.03 Prob > chi2 = 0.0000 Log likelihood = -1651.0563 Pseudo R2 = 0.0525 ------------------------------------------------------------------------------ art | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- fem | -.2245942 .0546138 -4.11 0.000 -.3316352 -.1175532 mar | .1552434 .0613747 2.53 0.011 .0349512 .2755356 kid5 | -.1848827 .0401272 -4.61 0.000 -.2635305 -.1062349 phd | .0128226 .0263972 0.49 0.627 -.038915 .0645601 ment | .0255427 .0020061 12.73 0.000 .0216109 .0294746 _cons | .3046168 .1029822 2.96 0.003 .1027755 .5064581 ------------------------------------------------------------------------------ . prcounts prm, plot max(9) . label var prmpreq "PRM" . label var prmobeq "Observed" . graph twoway connected prmobeq psnpreq prmpreq prmval, /// > ytitle("Probability of Count") ylabel(0(.1).4) /// > xlabel(0(1)9) /// > ysize(2.7051) xsize(4.0413) . graph export 07prmpred.eps, replace (file 07prmpred.eps written in .eps format) . . // * section 7.2.5: prm - exposure time . . * simulate data to illustrate exposure . * construct random integers . gen profage = round((1+10*uniform()),1) . label var profage "Professional Age" . gen lnage = ln(profage) . label var lnage "Log of Professional Age" . * let total articles equal artiles*exposure time . gen totalarts = art*profage . label var totalarts "Total Articles during Career" . . * PRM without including time . poisson totalarts fem mar kid5 phd ment, nolog Poisson regression Number of obs = 915 LR chi2(5) = 976.48 Prob > chi2 = 0.0000 Log likelihood = -7128.1833 Pseudo R2 = 0.0641 ------------------------------------------------------------------------------ totalarts | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- fem | -.2269265 .0225582 -10.06 0.000 -.2711397 -.1827132 mar | .0866516 .0250691 3.46 0.001 .0375171 .135786 kid5 | -.2248151 .017113 -13.14 0.000 -.2583561 -.1912742 phd | .0151535 .0109784 1.38 0.167 -.0063637 .0366708 ment | .024158 .000856 28.22 0.000 .0224803 .0258356 _cons | 2.1388 .0425172 50.30 0.000 2.055467 2.222132 ------------------------------------------------------------------------------ . . * PRM exposure time . poisson totalarts fem mar kid5 phd ment, nolog exposure(profage) Poisson regression Number of obs = 915 LR chi2(5) = 1045.95 Prob > chi2 = 0.0000 Log likelihood = -6006.936 Pseudo R2 = 0.0801 ------------------------------------------------------------------------------ totalarts | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- fem | -.2393499 .0226218 -10.58 0.000 -.2836877 -.195012 mar | .0998739 .0249208 4.01 0.000 .0510301 .1487177 kid5 | -.1948955 .017151 -11.36 0.000 -.2285109 -.1612801 phd | .0348152 .0108305 3.21 0.001 .0135878 .0560426 ment | .0244794 .0008179 29.93 0.000 .0228763 .0260824 _cons | .2866245 .0420771 6.81 0.000 .2041548 .3690942 profage | (exposure) ------------------------------------------------------------------------------ . . * PRM with exposure time as an independent variable with a constraint . constraint define 1 lnage=1 . poisson totalarts fem mar kid5 phd ment lnage, nolog constraint(1) Poisson regression Number of obs = 915 LR chi2(6) = 3218.97 Prob > chi2 = 0.0000 Log likelihood = -6006.936 Pseudo R2 = 0.2113 ( 1) [totalarts]lnage = 1 ------------------------------------------------------------------------------ totalarts | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- fem | -.2393499 .0226218 -10.58 0.000 -.2836877 -.195012 mar | .0998739 .0249208 4.01 0.000 .0510301 .1487177 kid5 | -.1948955 .017151 -11.36 0.000 -.2285109 -.1612801 phd | .0348152 .0108305 3.21 0.001 .0135878 .0560426 ment | .0244794 .0008179 29.93 0.000 .0228763 .0260824 lnage | 1 . . . . . _cons | .2866245 .0420771 6.81 0.000 .2041548 .3690942 ------------------------------------------------------------------------------ . . * PRM with offset() . poisson totalarts fem mar kid5 phd ment, nolog offset(lnage) Poisson regression Number of obs = 915 LR chi2(5) = 1045.95 Prob > chi2 = 0.0000 Log likelihood = -6006.936 Pseudo R2 = 0.0801 ------------------------------------------------------------------------------ totalarts | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- fem | -.2393499 .0226218 -10.58 0.000 -.2836877 -.195012 mar | .0998739 .0249208 4.01 0.000 .0510301 .1487177 kid5 | -.1948955 .017151 -11.36 0.000 -.2285109 -.1612801 phd | .0348152 .0108305 3.21 0.001 .0135878 .0560426 ment | .0244794 .0008179 29.93 0.000 .0228763 .0260824 _cons | .2866245 .0420771 6.81 0.000 .2041548 .3690942 lnage | (offset) ------------------------------------------------------------------------------ . . // * section 7.3.2: nbrm - estimation . . use couart2, clear (Academic Biochemists / S Long) . nbreg art fem mar kid5 phd ment, nolog Negative binomial regression Number of obs = 915 LR chi2(5) = 97.96 Prob > chi2 = 0.0000 Log likelihood = -1560.9583 Pseudo R2 = 0.0304 ------------------------------------------------------------------------------ art | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- fem | -.2164184 .0726724 -2.98 0.003 -.3588537 -.0739832 mar | .1504895 .0821063 1.83 0.067 -.0104359 .3114148 kid5 | -.1764152 .0530598 -3.32 0.001 -.2804105 -.07242 phd | .0152712 .0360396 0.42 0.672 -.0553652 .0859075 ment | .0290823 .0034701 8.38 0.000 .0222811 .0358836 _cons | .256144 .1385604 1.85 0.065 -.0154294 .5277174 -------------+---------------------------------------------------------------- /lnalpha | -.8173044 .1199372 -1.052377 -.5822318 -------------+---------------------------------------------------------------- alpha | .4416205 .0529667 .3491069 .5586502 ------------------------------------------------------------------------------ Likelihood-ratio test of alpha=0: chibar2(01) = 180.20 Prob>=chibar2 = 0.000 . . * combining poisson and nbreg . poisson art fem mar kid5 phd ment, nolog Poisson regression Number of obs = 915 LR chi2(5) = 183.03 Prob > chi2 = 0.0000 Log likelihood = -1651.0563 Pseudo R2 = 0.0525 ------------------------------------------------------------------------------ art | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- fem | -.2245942 .0546138 -4.11 0.000 -.3316352 -.1175532 mar | .1552434 .0613747 2.53 0.011 .0349512 .2755356 kid5 | -.1848827 .0401272 -4.61 0.000 -.2635305 -.1062349 phd | .0128226 .0263972 0.49 0.627 -.038915 .0645601 ment | .0255427 .0020061 12.73 0.000 .0216109 .0294746 _cons | .3046168 .1029822 2.96 0.003 .1027755 .5064581 ------------------------------------------------------------------------------ . estimates store PRM . nbreg art fem mar kid5 phd ment, nolog Negative binomial regression Number of obs = 915 LR chi2(5) = 97.96 Prob > chi2 = 0.0000 Log likelihood = -1560.9583 Pseudo R2 = 0.0304 ------------------------------------------------------------------------------ art | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- fem | -.2164184 .0726724 -2.98 0.003 -.3588537 -.0739832 mar | .1504895 .0821063 1.83 0.067 -.0104359 .3114148 kid5 | -.1764152 .0530598 -3.32 0.001 -.2804105 -.07242 phd | .0152712 .0360396 0.42 0.672 -.0553652 .0859075 ment | .0290823 .0034701 8.38 0.000 .0222811 .0358836 _cons | .256144 .1385604 1.85 0.065 -.0154294 .5277174 -------------+---------------------------------------------------------------- /lnalpha | -.8173044 .1199372 -1.052377 -.5822318 -------------+---------------------------------------------------------------- alpha | .4416205 .0529667 .3491069 .5586502 ------------------------------------------------------------------------------ Likelihood-ratio test of alpha=0: chibar2(01) = 180.20 Prob>=chibar2 = 0.000 . estimates store NBRM . estimates table PRM NBRM, b(%9.3f) t label varwidth(32) drop(lnalpha:_cons) stats(alpha N) ---------------------------------------------------------- Variable | PRM NBRM ---------------------------------+------------------------ Gender: 1=female 0=male | -0.225 -0.216 | -4.11 -2.98 Married: 1=yes 0=no | 0.155 0.150 | 2.53 1.83 Number of children < 6 | -0.185 -0.176 | -4.61 -3.32 PhD prestige | 0.013 0.015 | 0.49 0.42 Article by mentor in last 3 yrs | 0.026 0.029 | 12.73 8.38 Constant | 0.305 0.256 | 2.96 1.85 ---------------------------------+------------------------ alpha | 0.442 N | 915.000 915.000 ---------------------------------------------------------- legend: b/t . . // * section 7.3.4: nbrm - interpretation using the rate mu . . nbreg art fem mar kid5 phd ment, nolog Negative binomial regression Number of obs = 915 LR chi2(5) = 97.96 Prob > chi2 = 0.0000 Log likelihood = -1560.9583 Pseudo R2 = 0.0304 ------------------------------------------------------------------------------ art | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- fem | -.2164184 .0726724 -2.98 0.003 -.3588537 -.0739832 mar | .1504895 .0821063 1.83 0.067 -.0104359 .3114148 kid5 | -.1764152 .0530598 -3.32 0.001 -.2804105 -.07242 phd | .0152712 .0360396 0.42 0.672 -.0553652 .0859075 ment | .0290823 .0034701 8.38 0.000 .0222811 .0358836 _cons | .256144 .1385604 1.85 0.065 -.0154294 .5277174 -------------+---------------------------------------------------------------- /lnalpha | -.8173044 .1199372 -1.052377 -.5822318 -------------+---------------------------------------------------------------- alpha | .4416205 .0529667 .3491069 .5586502 ------------------------------------------------------------------------------ Likelihood-ratio test of alpha=0: chibar2(01) = 180.20 Prob>=chibar2 = 0.000 . listcoef fem ment, help nbreg (N=915): Factor Change in Expected Count Observed SD: 1.926069 ---------------------------------------------------------------------- art | b z P>|z| e^b e^bStdX SDofX -------------+-------------------------------------------------------- fem | -0.21642 -2.978 0.003 0.8054 0.8977 0.4987 ment | 0.02908 8.381 0.000 1.0295 1.3176 9.4839 -------------+-------------------------------------------------------- ln alpha | -0.81730 alpha | 0.44162 SE(alpha) = 0.05297 ---------------------------------------------------------------------- LR test of alpha=0: 180.20 Prob>=LRX2 = 0.000 ---------------------------------------------------------------------- b = raw coefficient z = z-score for test of b=0 P>|z| = p-value for z-test e^b = exp(b) = factor change in expected count for unit increase in X e^bStdX = exp(b*SD of X) = change in expected count for SD increase in X SDofX = standard deviation of X . listcoef fem ment, help percent nbreg (N=915): Percentage Change in Expected Count Observed SD: 1.926069 ---------------------------------------------------------------------- art | b z P>|z| % %StdX SDofX -------------+-------------------------------------------------------- fem | -0.21642 -2.978 0.003 -19.5 -10.2 0.4987 ment | 0.02908 8.381 0.000 3.0 31.8 9.4839 -------------+-------------------------------------------------------- ln alpha | -0.81730 alpha | 0.44162 SE(alpha) = 0.05297 ---------------------------------------------------------------------- LR test of alpha=0: 180.20 Prob>=LRX2 = 0.000 ---------------------------------------------------------------------- b = raw coefficient z = z-score for test of b=0 P>|z| = p-value for z-test % = percent change in expected count for unit increase in X %StdX = percent change in expected count for SD increase in X SDofX = standard deviation of X . . // * section 7.3.5: nbrm - interpretation using predicted probabilities . . * -prvalue- for prm and nbrm . quietly poisson art fem mar kid5 phd ment . prvalue poisson: Predictions for art Predicted rate: 1.61 95% CI [1.53 , 1.7] Predicted probabilities: Pr(y=0|x): 0.1999 Pr(y=1|x): 0.3218 Pr(y=2|x): 0.2591 Pr(y=3|x): 0.1390 Pr(y=4|x): 0.0560 Pr(y=5|x): 0.0180 Pr(y=6|x): 0.0048 Pr(y=7|x): 0.0011 Pr(y=8|x): 0.0002 Pr(y=9|x): 0.0000 fem mar kid5 phd ment x= .46010929 .66229508 .49508197 3.1031093 8.7672131 . quietly nbreg art fem mar kid5 phd ment . prvalue nbreg: Predictions for art Predicted rate: 1.6 Predicted probabilities: Pr(y=0|x): 0.2978 Pr(y=1|x): 0.2794 Pr(y=2|x): 0.1889 Pr(y=3|x): 0.1113 Pr(y=4|x): 0.0607 Pr(y=5|x): 0.0315 Pr(y=6|x): 0.0158 Pr(y=7|x): 0.0077 Pr(y=8|x): 0.0037 Pr(y=9|x): 0.0018 fem mar kid5 phd ment x= .46010929 .66229508 .49508197 3.1031093 8.7672131 . . * pr(y=0) for prm vs nbrm . quietly nbreg art fem mar kid5 phd ment, nolog . prgen ment, rest(mean) f(0) t(50) gen(nb) n(20) nbreg: Predicted values as ment varies from 0 to 50. fem mar kid5 phd ment x= .46010929 .66229508 .49508197 3.1031093 8.7672131 . quietly poisson art fem mar kid5 phd ment . prgen ment, rest(mean) f(0) t(50) gen(psn) n(20) poisson: Predicted values as ment varies from 0 to 50. fem mar kid5 phd ment x= .46010929 .66229508 .49508197 3.1031093 8.7672131 . label var psnp0 "Pr(0) for PRM" . label var nbp0 "Pr(0) for NBRM" . graph twoway connected psnp0 nbp0 nbx, /// > ylabel(0(.1).4) yline(.1 .2 .3) /// > ytitle("Probability of a Zero Count") /// > ysize(2.7051) xsize(4.0421) . graph export 07nbprm0.eps, replace (file 07nbprm0.eps written in .eps format) . . // * section 7.4.2: zip/zinb - example of estimating the zip and zinb models . . zip art fem mar kid5 phd ment, inf(fem mar kid5 phd ment) nolog Zero-inflated poisson regression Number of obs = 915 Nonzero obs = 640 Zero obs = 275 Inflation model = logit LR chi2(5) = 78.56 Log likelihood = -1604.773 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ art | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- art | fem | -.2091446 .0634047 -3.30 0.001 -.3334155 -.0848737 mar | .103751 .071111 1.46 0.145 -.035624 .243126 kid5 | -.1433196 .0474293 -3.02 0.003 -.2362793 -.0503599 phd | -.0061662 .0310086 -0.20 0.842 -.066942 .0546096 ment | .0180977 .0022948 7.89 0.000 .0135999 .0225955 _cons | .640839 .1213072 5.28 0.000 .4030814 .8785967 -------------+---------------------------------------------------------------- inflate | fem | .1097465 .2800813 0.39 0.695 -.4392028 .6586958 mar | -.3540107 .3176103 -1.11 0.265 -.9765155 .2684941 kid5 | .2171001 .196481 1.10 0.269 -.1679956 .6021958 phd | .0012702 .1452639 0.01 0.993 -.2834418 .2859821 ment | -.134111 .0452461 -2.96 0.003 -.2227918 -.0454302 _cons | -.5770618 .5093853 -1.13 0.257 -1.575439 .421315 ------------------------------------------------------------------------------ . estimates store ZIP . zinb art fem mar kid5 phd ment, inf(fem mar kid5 phd ment) nolog Zero-inflated negative binomial regression Number of obs = 915 Nonzero obs = 640 Zero obs = 275 Inflation model = logit LR chi2(5) = 67.97 Log likelihood = -1549.991 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ art | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- art | fem | -.1955068 .0755926 -2.59 0.010 -.3436655 -.0473481 mar | .0975826 .084452 1.16 0.248 -.0679402 .2631054 kid5 | -.1517325 .054206 -2.80 0.005 -.2579744 -.0454906 phd | -.0007001 .0362696 -0.02 0.985 -.0717872 .0703869 ment | .0247862 .0034924 7.10 0.000 .0179412 .0316312 _cons | .4167466 .1435962 2.90 0.004 .1353032 .69819 -------------+---------------------------------------------------------------- inflate | fem | .6359328 .8489175 0.75 0.454 -1.027915 2.299781 mar | -1.499469 .9386701 -1.60 0.110 -3.339228 .3402909 kid5 | .6284274 .4427825 1.42 0.156 -.2394105 1.496265 phd | -.0377153 .3080086 -0.12 0.903 -.641401 .5659705 ment | -.8822932 .3162276 -2.79 0.005 -1.502088 -.2624984 _cons | -.1916865 1.322821 -0.14 0.885 -2.784368 2.400995 -------------+---------------------------------------------------------------- /lnalpha | -.9763565 .1354679 -7.21 0.000 -1.241869 -.7108443 -------------+---------------------------------------------------------------- alpha | .3766811 .0510282 .288844 .4912293 ------------------------------------------------------------------------------ . estimates store ZINB . estimates table ZIP ZINB, b(%9.3f) t label varwidth(35) ------------------------------------------------------------- Variable | ZIP ZINB ------------------------------------+------------------------ art | Gender: 1=female 0=male | -0.209 -0.196 | -3.30 -2.59 Married: 1=yes 0=no | 0.104 0.098 | 1.46 1.16 Number of children < 6 | -0.143 -0.152 | -3.02 -2.80 PhD prestige | -0.006 -0.001 | -0.20 -0.02 Article by mentor in last 3 yrs | 0.018 0.025 | 7.89 7.10 Constant | 0.641 0.417 | 5.28 2.90 ------------------------------------+------------------------ inflate | Gender: 1=female 0=male | 0.110 0.636 | 0.39 0.75 Married: 1=yes 0=no | -0.354 -1.499 | -1.11 -1.60 Number of children < 6 | 0.217 0.628 | 1.10 1.42 PhD prestige | 0.001 -0.038 | 0.01 -0.12 Article by mentor in last 3 yrs | -0.134 -0.882 | -2.96 -2.79 Constant | -0.577 -0.192 | -1.13 -0.14 ------------------------------------+------------------------ lnalpha | Constant | -0.976 | -7.21 ------------------------------------------------------------- legend: b/t . . // * section 7.4.3: zip/zinb - interpretation of coefficients . . zip art fem mar kid5 phd ment, inf(fem mar kid5 phd ment) nolog Zero-inflated poisson regression Number of obs = 915 Nonzero obs = 640 Zero obs = 275 Inflation model = logit LR chi2(5) = 78.56 Log likelihood = -1604.773 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ art | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- art | fem | -.2091446 .0634047 -3.30 0.001 -.3334155 -.0848737 mar | .103751 .071111 1.46 0.145 -.035624 .243126 kid5 | -.1433196 .0474293 -3.02 0.003 -.2362793 -.0503599 phd | -.0061662 .0310086 -0.20 0.842 -.066942 .0546096 ment | .0180977 .0022948 7.89 0.000 .0135999 .0225955 _cons | .640839 .1213072 5.28 0.000 .4030814 .8785967 -------------+---------------------------------------------------------------- inflate | fem | .1097465 .2800813 0.39 0.695 -.4392028 .6586958 mar | -.3540107 .3176103 -1.11 0.265 -.9765155 .2684941 kid5 | .2171001 .196481 1.10 0.269 -.1679956 .6021958 phd | .0012702 .1452639 0.01 0.993 -.2834418 .2859821 ment | -.134111 .0452461 -2.96 0.003 -.2227918 -.0454302 _cons | -.5770618 .5093853 -1.13 0.257 -1.575439 .421315 ------------------------------------------------------------------------------ . listcoef, help zip (N=915): Factor Change in Expected Count Observed SD: 1.926069 Count Equation: Factor Change in Expected Count for Those Not Always 0 ---------------------------------------------------------------------- art | b z P>|z| e^b e^bStdX SDofX -------------+-------------------------------------------------------- fem | -0.20914 -3.299 0.001 0.8113 0.9010 0.4987 mar | 0.10375 1.459 0.145 1.1093 1.0503 0.4732 kid5 | -0.14332 -3.022 0.003 0.8665 0.8962 0.7649 phd | -0.00617 -0.199 0.842 0.9939 0.9939 0.9842 ment | 0.01810 7.886 0.000 1.0183 1.1872 9.4839 ---------------------------------------------------------------------- b = raw coefficient z = z-score for test of b=0 P>|z| = p-value for z-test e^b = exp(b) = factor change in expected count for unit increase in X e^bStdX = exp(b*SD of X) = change in expected count for SD increase in X SDofX = standard deviation of X Binary Equation: Factor Change in Odds of Always 0 ---------------------------------------------------------------------- Always0 | b z P>|z| e^b e^bStdX SDofX -------------+-------------------------------------------------------- fem | 0.10975 0.392 0.695 1.1160 1.0563 0.4987 mar | -0.35401 -1.115 0.265 0.7019 0.8458 0.4732 kid5 | 0.21710 1.105 0.269 1.2425 1.1806 0.7649 phd | 0.00127 0.009 0.993 1.0013 1.0013 0.9842 ment | -0.13411 -2.964 0.003 0.8745 0.2803 9.4839 ---------------------------------------------------------------------- b = raw coefficient z = z-score for test of b=0 P>|z| = p-value for z-test e^b = exp(b) = factor change in odds for unit increase in X e^bStdX = exp(b*SD of X) = change in odds for SD increase in X SDofX = standard deviation of X . zinb art fem mar kid5 phd ment, inf(fem mar kid5 phd ment) nolog Zero-inflated negative binomial regression Number of obs = 915 Nonzero obs = 640 Zero obs = 275 Inflation model = logit LR chi2(5) = 67.97 Log likelihood = -1549.991 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ art | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- art | fem | -.1955068 .0755926 -2.59 0.010 -.3436655 -.0473481 mar | .0975826 .084452 1.16 0.248 -.0679402 .2631054 kid5 | -.1517325 .054206 -2.80 0.005 -.2579744 -.0454906 phd | -.0007001 .0362696 -0.02 0.985 -.0717872 .0703869 ment | .0247862 .0034924 7.10 0.000 .0179412 .0316312 _cons | .4167466 .1435962 2.90 0.004 .1353032 .69819 -------------+---------------------------------------------------------------- inflate | fem | .6359328 .8489175 0.75 0.454 -1.027915 2.299781 mar | -1.499469 .9386701 -1.60 0.110 -3.339228 .3402909 kid5 | .6284274 .4427825 1.42 0.156 -.2394105 1.496265 phd | -.0377153 .3080086 -0.12 0.903 -.641401 .5659705 ment | -.8822932 .3162276 -2.79 0.005 -1.502088 -.2624984 _cons | -.1916865 1.322821 -0.14 0.885 -2.784368 2.400995 -------------+---------------------------------------------------------------- /lnalpha | -.9763565 .1354679 -7.21 0.000 -1.241869 -.7108443 -------------+---------------------------------------------------------------- alpha | .3766811 .0510282 .288844 .4912293 ------------------------------------------------------------------------------ . listcoef, help zinb (N=915): Factor Change in Expected Count Observed SD: 1.926069 Count Equation: Factor Change in Expected Count for Those Not Always 0 ---------------------------------------------------------------------- art | b z P>|z| e^b e^bStdX SDofX -------------+-------------------------------------------------------- fem | -0.19551 -2.586 0.010 0.8224 0.9071 0.4987 mar | 0.09758 1.155 0.248 1.1025 1.0473 0.4732 kid5 | -0.15173 -2.799 0.005 0.8592 0.8904 0.7649 phd | -0.00070 -0.019 0.985 0.9993 0.9993 0.9842 ment | 0.02479 7.097 0.000 1.0251 1.2650 9.4839 -------------+-------------------------------------------------------- ln alpha | -0.97636 alpha | 0.37668 SE(alpha) = 0.05103 ---------------------------------------------------------------------- b = raw coefficient z = z-score for test of b=0 P>|z| = p-value for z-test e^b = exp(b) = factor change in expected count for unit increase in X e^bStdX = exp(b*SD of X) = change in expected count for SD increase in X SDofX = standard deviation of X Binary Equation: Factor Change in Odds of Always 0 ---------------------------------------------------------------------- Always0 | b z P>|z| e^b e^bStdX SDofX -------------+-------------------------------------------------------- fem | 0.63593 0.749 0.454 1.8888 1.3732 0.4987 mar | -1.49947 -1.597 0.110 0.2232 0.4919 0.4732 kid5 | 0.62843 1.419 0.156 1.8747 1.6172 0.7649 phd | -0.03772 -0.122 0.903 0.9630 0.9636 0.9842 ment | -0.88229 -2.790 0.005 0.4138 0.0002 9.4839 ---------------------------------------------------------------------- b = raw coefficient z = z-score for test of b=0 P>|z| = p-value for z-test e^b = exp(b) = factor change in odds for unit increase in X e^bStdX = exp(b*SD of X) = change in odds for SD increase in X SDofX = standard deviation of X . . // * section 7.4.4: zip/zinb - interpretation of predicted probabilities . . * -prvalue- . zinb art fem mar kid5 phd ment, inf(fem mar kid5 phd ment) nolog Zero-inflated negative binomial regression Number of obs = 915 Nonzero obs = 640 Zero obs = 275 Inflation model = logit LR chi2(5) = 67.97 Log likelihood = -1549.991 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ art | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- art | fem | -.1955068 .0755926 -2.59 0.010 -.3436655 -.0473481 mar | .0975826 .084452 1.16 0.248 -.0679402 .2631054 kid5 | -.1517325 .054206 -2.80 0.005 -.2579744 -.0454906 phd | -.0007001 .0362696 -0.02 0.985 -.0717872 .0703869 ment | .0247862 .0034924 7.10 0.000 .0179412 .0316312 _cons | .4167466 .1435962 2.90 0.004 .1353032 .69819 -------------+---------------------------------------------------------------- inflate | fem | .6359328 .8489175 0.75 0.454 -1.027915 2.299781 mar | -1.499469 .9386701 -1.60 0.110 -3.339228 .3402909 kid5 | .6284274 .4427825 1.42 0.156 -.2394105 1.496265 phd | -.0377153 .3080086 -0.12 0.903 -.641401 .5659705 ment | -.8822932 .3162276 -2.79 0.005 -1.502088 -.2624984 _cons | -.1916865 1.322821 -0.14 0.885 -2.784368 2.400995 -------------+---------------------------------------------------------------- /lnalpha | -.9763565 .1354679 -7.21 0.000 -1.241869 -.7108443 -------------+---------------------------------------------------------------- alpha | .3766811 .0510282 .288844 .4912293 ------------------------------------------------------------------------------ . quietly prvalue, x(fem=0 mar=1 kid5=3 phd=3 ment=10) save . prvalue, x(fem=1 mar=1 kid5=3 phd=1 ment=0) dif zinb: Change in Predictions for art Predicted rate: .272 Saved: 1.36 Difference: -1.08 Predicted probabilities: Current Saved Difference Pr(y=0|x,z): 0.9290 0.3344 0.5945 Pr(y=1|x): 0.0593 0.3001 -0.2408 Pr(y=2|x): 0.0101 0.1854 -0.1754 Pr(y=3|x): 0.0015 0.0973 -0.0958 Pr(y=4|x): 0.0002 0.0465 -0.0463 Pr(y=5|x): 0.0000 0.0209 -0.0209 Pr(y=6|x): 0.0000 0.0090 -0.0090 Pr(y=7|x): 0.0000 0.0038 -0.0038 Pr(y=8|x): 0.0000 0.0015 -0.0015 Pr(y=9|x): 0.0000 0.0006 -0.0006 Pr(Always0|z): 0.6883 0.0002 0.6882 x values for count equation fem mar kid5 phd ment Current= 1 1 3 1 0 Saved= 0 1 3 3 10 Diff= 1 0 0 -2 -10 z values for binary equation fem mar kid5 phd ment Current= 1 1 3 1 0 Saved= 0 1 3 3 10 Diff= 1 0 0 -2 -10 . . * -prgen- . prgen ment, rest(mean) f(0) t(20) gen(zinb) n(21) zinb: Predicted values as ment varies from 0 to 20. base x values for count equation: fem mar kid5 phd ment x= .46010929 .66229508 .49508197 3.1031093 8.7672131 base z values for binary equation: fem mar kid5 phd ment z= .46010929 .66229508 .49508197 3.1031093 8.7672131 . gen zinbnb0 = zinbp0 - zinball0 (894 missing values generated) . label var zinbp0 "0's from Both Equations" . label var zinball0 "0's from Binary Equation" . label var zinbnb0 "0's from Count Equation" . label var zinbx"Mentor's Publications" . graph twoway connected zinball0 zinbnb0 zinbp0 zinbx, /// > xlabel(0(5)20) ylabel(0(.1).7) /// > ytitle(Probability of Zero) msymbol(Oh Sh O) /// > ysize(2.6541) xsize(3.9678) . graph export 07zinbpr0.eps, replace (file 07zinbpr0.eps written in .eps format) . . // * section 7.5.1: comparing mean probabilities . . * estimate various models and save predictions . use couart2, clear (Academic Biochemists / S Long) . quietly poisson art fem mar kid5 phd ment, nolog . prcounts prm, plot max(9) . label var prmpreq "Predicted: PRM" . label var prmobeq "Observed" . quietly nbreg art fem mar kid5 phd ment, nolog . prcounts nbrm, plot max(9) . label var nbrmpreq "Predicted: NBRM" . quietly zip art fem mar kid5 phd ment, /// > inf(fem mar kid5 phd ment) vuong nolog . prcounts zip, plot max(9) . label var zippreq "Predicted: ZIP" . quietly zinb art fem mar kid5 phd ment, /// > inf(fem mar kid5 phd ment) vuong nolog . prcounts zinb, plot max(9) . label var zinbpreq "Predicted: ZINB" . . * create deviations . gen obs = prmobeq (905 missing values generated) . gen dprm = obs - prmpreq (905 missing values generated) . label var dprm "PRM" . gen dnbrm = obs - nbrmpreq (905 missing values generated) . label var dnbrm "NBRM" . gen dzip = obs - zippreq (905 missing values generated) . label var dzip "ZIP" . gen dzinb = obs - zinbpreq (905 missing values generated) . label var dzinb "ZINB" . * plot deviations . graph twoway connected dprm dnbrm dzip dzinb prmval, /// > ytitle(Observed-Predicted) ylabel(-.10(.05).10) /// > xlabel(0(1)9) msymbol(Oh Sh O S) /// > ysize(2.7051) xsize(4.0413) . graph export 07compare.eps, replace (file 07compare.eps written in .eps format) . . // * section 6.5.2: tests to compare count models . . * LR test for -zip- and -zinb- . use couart2, clear (Academic Biochemists / S Long) . nbreg art fem mar kid5 phd ment, nolog Negative binomial regression Number of obs = 915 LR chi2(5) = 97.96 Prob > chi2 = 0.0000 Log likelihood = -1560.9583 Pseudo R2 = 0.0304 ------------------------------------------------------------------------------ art | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- fem | -.2164184 .0726724 -2.98 0.003 -.3588537 -.0739832 mar | .1504895 .0821063 1.83 0.067 -.0104359 .3114148 kid5 | -.1764152 .0530598 -3.32 0.001 -.2804105 -.07242 phd | .0152712 .0360396 0.42 0.672 -.0553652 .0859075 ment | .0290823 .0034701 8.38 0.000 .0222811 .0358836 _cons | .256144 .1385604 1.85 0.065 -.0154294 .5277174 -------------+---------------------------------------------------------------- /lnalpha | -.8173044 .1199372 -1.052377 -.5822318 -------------+---------------------------------------------------------------- alpha | .4416205 .0529667 .3491069 .5586502 ------------------------------------------------------------------------------ Likelihood-ratio test of alpha=0: chibar2(01) = 180.20 Prob>=chibar2 = 0.000 . quietly zip art fem mar kid5 phd ment, inf(fem mar kid5 phd ment) vuong nolog . scalar llzip = e(ll) . quietly zinb art fem mar kid5 phd ment, inf(fem mar kid5 phd ment) vuong nolog . scalar llzinb = e(ll) . scalar lr = -2*(llzip-llzinb) . scalar pvalue = chiprob(1,lr)/2 . scalar lnalpha = -.9763565 . if (lnalpha < -20) { . scalar pvalue= 1 . } . di as text "Likelihood-ratio test comparing ZIP to ZINB: " as res %8.3f /// > lr as text " Prob>=" as res %5.3f pvalue Likelihood-ratio test comparing ZIP to ZINB: 109.564 Prob>=0.000 . . * vuong test of non-nested models . zip art fem mar kid5 phd ment, inf(fem mar kid5 phd ment) vuong nolog Zero-inflated poisson regression Number of obs = 915 Nonzero obs = 640 Zero obs = 275 Inflation model = logit LR chi2(5) = 78.56 Log likelihood = -1604.773 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ art | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- art | fem | -.2091446 .0634047 -3.30 0.001 -.3334155 -.0848737 mar | .103751 .071111 1.46 0.145 -.035624 .243126 kid5 | -.1433196 .0474293 -3.02 0.003 -.2362793 -.0503599 phd | -.0061662 .0310086 -0.20 0.842 -.066942 .0546096 ment | .0180977 .0022948 7.89 0.000 .0135999 .0225955 _cons | .640839 .1213072 5.28 0.000 .4030814 .8785967 -------------+---------------------------------------------------------------- inflate | fem | .1097465 .2800813 0.39 0.695 -.4392028 .6586958 mar | -.3540107 .3176103 -1.11 0.265 -.9765155 .2684941 kid5 | .2171001 .196481 1.10 0.269 -.1679956 .6021958 phd | .0012702 .1452639 0.01 0.993 -.2834418 .2859821 ment | -.134111 .0452461 -2.96 0.003 -.2227918 -.0454302 _cons | -.5770618 .5093853 -1.13 0.257 -1.575439 .421315 ------------------------------------------------------------------------------ Vuong test of zip vs. standard Poisson: z = 4.18 Pr>z = 0.0000 . listcoef, help zip (N=915): Factor Change in Expected Count Observed SD: 1.926069 Count Equation: Factor Change in Expected Count for Those Not Always 0 ---------------------------------------------------------------------- art | b z P>|z| e^b e^bStdX SDofX -------------+-------------------------------------------------------- fem | -0.20914 -3.299 0.001 0.8113 0.9010 0.4987 mar | 0.10375 1.459 0.145 1.1093 1.0503 0.4732 kid5 | -0.14332 -3.022 0.003 0.8665 0.8962 0.7649 phd | -0.00617 -0.199 0.842 0.9939 0.9939 0.9842 ment | 0.01810 7.886 0.000 1.0183 1.1872 9.4839 ---------------------------------------------------------------------- b = raw coefficient z = z-score for test of b=0 P>|z| = p-value for z-test e^b = exp(b) = factor change in expected count for unit increase in X e^bStdX = exp(b*SD of X) = change in expected count for SD increase in X SDofX = standard deviation of X Binary Equation: Factor Change in Odds of Always 0 ---------------------------------------------------------------------- Always0 | b z P>|z| e^b e^bStdX SDofX -------------+-------------------------------------------------------- fem | 0.10975 0.392 0.695 1.1160 1.0563 0.4987 mar | -0.35401 -1.115 0.265 0.7019 0.8458 0.4732 kid5 | 0.21710 1.105 0.269 1.2425 1.1806 0.7649 phd | 0.00127 0.009 0.993 1.0013 1.0013 0.9842 ment | -0.13411 -2.964 0.003 0.8745 0.2803 9.4839 ---------------------------------------------------------------------- Vuong Test = 4.18 (p=0.000) favoring ZIP over PRM. ---------------------------------------------------------------------- b = raw coefficient z = z-score for test of b=0 P>|z| = p-value for z-test e^b = exp(b) = factor change in odds for unit increase in X e^bStdX = exp(b*SD of X) = change in odds for SD increase in X SDofX = standard deviation of X . zinb art fem mar kid5 phd ment, inf(fem mar kid5 phd ment) vuong nolog Zero-inflated negative binomial regression Number of obs = 915 Nonzero obs = 640 Zero obs = 275 Inflation model = logit LR chi2(5) = 67.97 Log likelihood = -1549.991 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ art | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- art | fem | -.1955068 .0755926 -2.59 0.010 -.3436655 -.0473481 mar | .0975826 .084452 1.16 0.248 -.0679402 .2631054 kid5 | -.1517325 .054206 -2.80 0.005 -.2579744 -.0454906 phd | -.0007001 .0362696 -0.02 0.985 -.0717872 .0703869 ment | .0247862 .0034924 7.10 0.000 .0179412 .0316312 _cons | .4167466 .1435962 2.90 0.004 .1353032 .69819 -------------+---------------------------------------------------------------- inflate | fem | .6359328 .8489175 0.75 0.454 -1.027915 2.299781 mar | -1.499469 .9386701 -1.60 0.110 -3.339228 .3402909 kid5 | .6284274 .4427825 1.42 0.156 -.2394105 1.496265 phd | -.0377153 .3080086 -0.12 0.903 -.641401 .5659705 ment | -.8822932 .3162276 -2.79 0.005 -1.502088 -.2624984 _cons | -.1916865 1.322821 -0.14 0.885 -2.784368 2.400995 -------------+---------------------------------------------------------------- /lnalpha | -.9763565 .1354679 -7.21 0.000 -1.241869 -.7108443 -------------+---------------------------------------------------------------- alpha | .3766811 .0510282 .288844 .4912293 ------------------------------------------------------------------------------ Vuong test of zinb vs. standard negative binomial: z = 2.24 Pr>z = 0.0125 . listcoef, help zinb (N=915): Factor Change in Expected Count Observed SD: 1.926069 Count Equation: Factor Change in Expected Count for Those Not Always 0 ---------------------------------------------------------------------- art | b z P>|z| e^b e^bStdX SDofX -------------+-------------------------------------------------------- fem | -0.19551 -2.586 0.010 0.8224 0.9071 0.4987 mar | 0.09758 1.155 0.248 1.1025 1.0473 0.4732 kid5 | -0.15173 -2.799 0.005 0.8592 0.8904 0.7649 phd | -0.00070 -0.019 0.985 0.9993 0.9993 0.9842 ment | 0.02479 7.097 0.000 1.0251 1.2650 9.4839 -------------+-------------------------------------------------------- ln alpha | -0.97636 alpha | 0.37668 SE(alpha) = 0.05103 ---------------------------------------------------------------------- b = raw coefficient z = z-score for test of b=0 P>|z| = p-value for z-test e^b = exp(b) = factor change in expected count for unit increase in X e^bStdX = exp(b*SD of X) = change in expected count for SD increase in X SDofX = standard deviation of X Binary Equation: Factor Change in Odds of Always 0 ---------------------------------------------------------------------- Always0 | b z P>|z| e^b e^bStdX SDofX -------------+-------------------------------------------------------- fem | 0.63593 0.749 0.454 1.8888 1.3732 0.4987 mar | -1.49947 -1.597 0.110 0.2232 0.4919 0.4732 kid5 | 0.62843 1.419 0.156 1.8747 1.6172 0.7649 phd | -0.03772 -0.122 0.903 0.9630 0.9636 0.9842 ment | -0.88229 -2.790 0.005 0.4138 0.0002 9.4839 ---------------------------------------------------------------------- Vuong Test = 2.24 (p=0.012) favoring ZINB over NBRM. ---------------------------------------------------------------------- b = raw coefficient z = z-score for test of b=0 P>|z| = p-value for z-test e^b = exp(b) = factor change in odds for unit increase in X e^bStdX = exp(b*SD of X) = change in odds for SD increase in X SDofX = standard deviation of X . . log close log: d:\spost.stata8\do\st8ch7.log log type: text closed on: 26 May 2003, 12:52:23 -------------------------------------------------------------------------------------------------------------