Statalist


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

st: RE: Estimating residuals following nbreg


From   "Steichen, Thomas J." <SteichT@RJRT.com>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Estimating residuals following nbreg
Date   Wed, 29 Oct 2008 17:27:53 -0400

Paul,

I think the problem is that
  . predict xb, xb

Does not produce xb = x_j*beta, it produces x b = x_j*beta + ln(demog_exposure_j) when you specify the exposure(option).

Thus,
  . gen n_pred_formula = exp(xb)*demog_exposure
does not get what
  . predict n_pred
gives.

Instead, try
  . gen n_pred_formula = exp(xb - ln(demog_exposure))*demog_exposure

Tom


-----------------------------------
Thomas J. Steichen
steicht@rjrt.com
-----------------------------------

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Paul Seed
Sent: Wednesday, October 29, 2008 4:15 PM
To: statalist@hsphsun2.harvard.edu
Subject: st: Estimating residuals following nbreg

Dear all,

I fitted a negative binomial regrression, and tried to check the model
residuals by
estimating the differences and the standard errors, without success.
Can anyone tell me what I am doing wrong?
I am using stata 9.2 (fully up to date) on Windows XP, Dell latitue
laptop, if it is relevant.

xi: nbreg n_copd i.sha i.imd_nat , nolog exposure(demog_exposure) irr
predict xb, xb
predict stdp , stdp
predict n_pred
* According to the manual, the predicted number of events = exp(xb)*exposure
gen n_pred_formula = exp(xb)*demog_exposure
* so, xb_formula should be the same as xb
gen xb_formula = log(n_pred/demog_exposure)
* and xb_obs should be the observed value of xb
gen xb_obs = log(n_copd /demog_exposure)

* and this should be a z-score for the residuals with mean 0, SD 1
gen z = (xb_obs - xb)/stdp

su z  n_pred* xb*

* This is what I get: for the regression and the summaries:
i.sha             _Isha_1-10          (naturally coded; _Isha_3 omitted)
i.imd_nationa~e   _Iimd_natio_0-5     (naturally coded; _Iimd_natio_5
omitted)

Negative binomial regression                      Number of obs
=       8192
                                                  LR chi2(14)     =
2217.96
Dispersion     = mean                             Prob > chi2     =
0.0000
Log likelihood = -39291.575                       Pseudo R2       =
0.0274

------------------------------------------------------------------------------
      n_copd |        IRR   Std. Err.      z    P>|z|     [95% Conf.
Interval]
-------------+----------------------------------------------------------------
     _Isha_1 |   1.329169   .0266175    14.21   0.000      1.27801
1.382376
     _Isha_2 |   1.250265   .0236651    11.80   0.000     1.204732
1.297518
     _Isha_4 |   1.721701   .0407484    22.96   0.000     1.643659
1.803447
     _Isha_5 |   1.539672   .0247868    26.81   0.000     1.491849
1.589028
     _Isha_6 |   1.228066   .0271053     9.31   0.000     1.176073
1.282357
     _Isha_7 |   1.233594   .0249431    10.38   0.000     1.185663
1.283464
     _Isha_8 |   1.320831   .0251773    14.60   0.000     1.272395
1.371111
     _Isha_9 |   1.169725   .0204633     8.96   0.000     1.130298
1.210528
    _Isha_10 |   1.479601   .0271344    21.36   0.000     1.427363
1.533751
_Iimd_nati~0 |    1.32367   .0337734    10.99   0.000     1.259103
1.391547
_Iimd_nati~1 |   1.558233   .0252282    27.40   0.000     1.509562
1.608472
_Iimd_nati~2 |   1.360677   .0223115    18.78   0.000     1.317642
1.405117
_Iimd_nati~3 |   1.206407   .0201443    11.24   0.000     1.167564
1.246542
_Iimd_nati~4 |   1.110986   .0190818     6.13   0.000     1.074209
1.149023
demog_expo~e | (exposure)
-------------+----------------------------------------------------------------
    /lnalpha |   -1.84722   .0176387                     -1.881791
-1.812648
-------------+----------------------------------------------------------------
       alpha |   .1576749   .0027812                      .1523171
.1632213
------------------------------------------------------------------------------
Likelihood-ratio test of alpha=0:  chibar2(01) = 7.2e+04 Prob>=chibar2 =
0.000


    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
           z |      8181   -253.3219    59.07685  -523.0276   56.79291
      n_pred |      8192     94.1288    69.12208   1.554023   699.5399
n_pred_for~a |      8192    12220.43    18677.29    1.63849     381644
          xb |      8192    4.284738     .749684   .4408472   6.550423
  xb_formula |      8192    .0281945    .2300367  -.4633753   .5234895
-------------+--------------------------------------------------------
      xb_obs |      8181   -.0675564    .5262027  -4.380957   2.350302






Paul T Seed MSc CStat, Lecturer in Medical Statistics,
 tel  (+44) (0) 20 7188 3642, fax (+44) (0) 20 7620 1227
Wednesdays: (+4) (0) 20 7848 4148

 paul.seed@kcl.ac.uk, paul.t.seed@gmail.com

 King's College London, Division of Reproduction and Endocrinology
 St Thomas' Hospital, Westminster Bridge Road, London SE1 7EH


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

CONFIDENTIALITY  NOTE:  This e-mail message, including any attachment(s), contains information that may be confidential, protected by the attorney-client or other legal privileges, and/or proprietary non-public information. If you are not an intended recipient of this message or an authorized assistant to an intended recipient, please notify the sender by replying to this message and then delete it from your system. Use, dissemination, distribution, or reproduction of this message and/or any of its attachments (if any) by unintended recipients is not authorized and may be unlawful.

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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