Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: grouping, negative binomial regression, and margins
From
"Roger B. Newson" <[email protected]>
To
[email protected]
Subject
Re: st: grouping, negative binomial regression, and margins
Date
Mon, 12 Aug 2013 12:45:56 +0100
I would second Nick's advice. If you want to fit a model for each
region, then you should use a loop over regions. As in:
levelsof region, lo(regions)
foreach RE of num `regions' {
nbreg NUMTA i.NUMDS if region==`RE', nolog
margins NUMDS
}
It might be even better if you used the -marglmean- package,
downloadable from SSC, to get confidence intervals for marginal means.
-marglmean- is a wrapper for -margins- that adds a Normalizing and
variance-stabilizing log transform, which is a good idea with
negative-binomial marginal means. As in:
levelsof region, lo(regions)
levelsof NUMDS, lo(nume)
foreach RE of num `regions' {
nbreg NUMTA i.NUMDS if region==`RE', nolog
foreach NDS of num `nums' {
marglmean, at(NUMDS=`NDS') eform
}
This will probably give more sensible confidence intervals. I myself
always use -marglmean- for marginal means after a negative-binomial
regrassion.
I hope this helps.
Best wishes
Roger
Roger B Newson BSc MSc DPhil
Lecturer in Medical Statistics
Respiratory Epidemiology and Public Health Group
National Heart and Lung Institute
Imperial College London
Royal Brompton Campus
Room 33, Emmanuel Kaye Building
1B Manresa Road
London SW3 6LR
UNITED KINGDOM
Tel: +44 (0)20 7352 8121 ext 3381
Fax: +44 (0)20 7351 8322
Email: [email protected]
Web page: http://www.imperial.ac.uk/nhli/r.newson/
Departmental Web page:
http://www1.imperial.ac.uk/medicine/about/divisions/nhli/respiration/popgenetics/reph/
Opinions expressed are those of the author, not of the institution.
On 10/08/2013 23:54, Nick Cox wrote:
It is standard that when you run
by <varlist>: <command>
Stata runs through the possibilities but only results for the last
model fitted remain in memory. In your case the results in memory are
for the last region fitted and those are what -margins- uses.
Nick
[email protected]
On 10 August 2013 23:04, Ahmed Al Attar <[email protected]> wrote:
Hi,
I am working on a project where I have a bivariate model. All of my data are counts and I have verified using countfit that the best model to use is the Negative binomial regression.
My Dependent Variable is called NUMTA (with values one of 0,1,2,3,4,5,6)
My Independent Variable is called NUMDS (with values either 0, 1 or 2)
The study takes place over 10 different regions, each with counts of NUMTA and NUMDS which brings us to a total of 870 observations.
The commands that I have entered into stata are:
sort region
by region: nbreg NUMTA i.NUMDS, nolog
The output is a negative binomial regression by region as you can see below. This is for 1 of my 10 regions:
Negative binomial regression Number of obs = 87
LR chi2(1) = 0.50
Dispersion = mean Prob > chi2 = 0.4810
Log likelihood = -34.128129 Pseudo R2 = 0.0072
------------------------------------------------------------------------------
numta | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
1.numds | -12.98646 1298.721 -0.01 0.992 -2558.434 2532.461
_cons | -2.044954 .3103769 -6.59 0.000 -2.653282 -1.436627
-------------+----------------------------------------------------------------
/lnalpha | -.7772627 3.388113 -7.417842 5.863317
-------------+----------------------------------------------------------------
alpha | .4596625 1.557389 .0006004 351.8895
------------------------------------------------------------------------------
Likelihood-ratio test of alpha=0: chibar2(01) = 0.11 Prob>=chibar2 = 0.367
However, when I follow this up with the command:
margins NUMDS
then I get the following output:
Adjusted predictions Number of obs = 87
Model VCE : OIM
Expression : Predicted number of events, predict()
------------------------------------------------------------------------------
| Delta-method
| Margin Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
numds |
0 | .0657895 .0310757 2.12 0.034 .0048822 .1266967
1 | .1111111 .1214722 0.91 0.360 -.1269701 .3491923
2 | .4999992 .6852692 0.73 0.466 -.8431037 1.843102
------------------------------------------------------------------------------
The above output says 87 observations, when I know it should show predictions for 870 observations instead. Which leads me to believe that it has done the margins command for only 1 of my 10 regions.
Is there a way to do the margins command using (by region:) in order to get 10 different margins outputs? When I try to run the command by region: margins NUMDS state says I cannot run it. If not, is there any other course of action you would advise?
Thank you very much for your support,
Ahmed Al-Attar
RCTC-Organization
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/