Skip to content

GEE rebased and cleaned - #1215

Merged
josef-pkt merged 3 commits into
statsmodels:gee_rebasedfrom
vincentarelbundock:gee_rebased
Dec 19, 2013
Merged

josef-pkt merged 3 commits into
statsmodels:gee_rebasedfrom
vincentarelbundock:gee_rebased

Conversation

@vincentarelbundock

Copy link
Copy Markdown

Made most of the minor fixes suggested by @josef-pkt on #928

Please leave a comment so I can add to this todo list:

  • Review tests (e.g. inheritance from_formula)

@vincentarelbundock

Copy link
Copy Markdown
Author

@josef-pkt you write "@vincentarelbundock see the test cases, from_formula works by inheritance.."

I'm not sure exactly how this works. Do you mean we don't have to have explicit tests for formulas inside the test_gee.py file?

@josef-pkt

Copy link
Copy Markdown
Member

I'm not sure what I meant, maybe I misinterpreted something

#928 (comment) looks like a good idea.

We should have some basic test that the formula interface, from_formula, works correctly in this case.
But once we have some cases in the test suite that use from_formula, then all the inherited/reused parts of the formulas will also work, I assume, and we would only need to test whether model specific parts, if there are any, work correctly.
(Or we inherited the same open problems that we have with formulas in all models.)

That's just a generic answer, I try to look at it later today. (Right now I'm struggling to get some test results out of Stata for kernel regression.)

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage remained the same when pulling db9bd00 on vincentarelbundock:gee_rebased into 22b6c87 on statsmodels:gee_rebased.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage remained the same when pulling e618939 on vincentarelbundock:gee_rebased into 22b6c87 on statsmodels:gee_rebased.

@vincentarelbundock

Copy link
Copy Markdown
Author

I'm trying to write an example, and can't figure out why I get different results in R and SM. These two models in R give identical coefficient estimates, but not in SM.

http://nbviewer.ipython.org/gist/vincentarelbundock/7963479

Any ideas?

@josef-pkt

Copy link
Copy Markdown
Member

My first impression is that I don't see why they should give the same results.

Based on the SUR analog, only if all the explanatory variables are the same in each equation/cross-sectional unit/group, then SUR (unrestricted) and OLS (independent) have identical parameter estimates.

Can you try another correlation structure?

@vincentarelbundock

Copy link
Copy Markdown
Author

I couldn't immediately find an easy analogue between R's gee and the varstrucs we have here. AR-M would work, but I'll need to figure out how to setup the time dimension first.

I will also need to read more on GEE generally, but in the meantime, I note that Table 6 of this paper shows identical coefficients for Exchangeable and Independence:

http://www.jstatsoft.org/v15/i02/paper

@vincentarelbundock

Copy link
Copy Markdown
Author

And the plot thickens. Stata produces different coefficient estimates under independence and exchangeability, but those estimates are different than ours:

 1 . insheet using respiratory.csv, clear
 2 . xtset id
 3 . xtgee outcome baseline center age, family(gaussian) corr(independent)
  GEE population-averaged model                   Number of obs      =       444
  Group variable:                         id      Number of groups   =        56
  Link:                             identity      Obs per group: min =         4
  Family:                           Gaussian                     avg =       7.9
  Correlation:                   independent                     max =         8
                                                  Wald chi2(3)       =    104.96
  Scale parameter:                  .1994266      Prob > chi2        =    0.0000

  Pearson chi2(444):                   88.55      Deviance           =     88.55
  Dispersion (Pearson):             .1994266      Dispersion         =  .1994266

  ------------------------------------------------------------------------------
       outcome |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
  -------------+----------------------------------------------------------------
      baseline |   .3737131   .0443404     8.43   0.000     .2868076    .4606187
        center |   .1330252   .0452028     2.94   0.003     .0444294     .221621
           age |   -.003695   .0016057    -2.30   0.021    -.0068421   -.0005478
         _cons |   .3142464   .0776171     4.05   0.000     .1621197    .4663732
  ------------------------------------------------------------------------------

 4 . xtgee outcome baseline center age, family(gaussian) corr(exchangeable)
  GEE population-averaged model                   Number of obs      =       444
  Group variable:                         id      Number of groups   =        56
  Link:                             identity      Obs per group: min =         4
  Family:                           Gaussian                     avg =       7.9
  Correlation:                  exchangeable                     max =         8
                                                  Wald chi2(3)       =     79.46
  Scale parameter:                    .20012      Prob > chi2        =    0.0000

  ------------------------------------------------------------------------------
       outcome |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
  -------------+----------------------------------------------------------------
      baseline |   .3197515    .049065     6.52   0.000     .2235859    .4159172
        center |   .1534501   .0423509     3.62   0.000     .0704439    .2364563
           age |  -.0042494   .0018075    -2.35   0.019     -.007792   -.0007067
         _cons |   .3279763   .0794045     4.13   0.000     .1723464    .4836062
  ------------------------------------------------------------------------------

@josef-pkt

Copy link
Copy Markdown
Member

I'm still suspicious about the geepack result.
"exchangeable" is the same correlation structure as in a random effects panel (one way within random constant)
while "independent" should be the same as pooled LS (or just OLS, I guess).
Although GEE uses robust cov instead of the non-robust cov in Panel.

Does unstructured work in our GEE with unbalanced clusters/panel? (Stata doesn't IIRC the documentation)

'exchangeable' could be verified also with Stata, I guess.

Given your time constraint, it might be better to let Kerby or me worry about this.

@kshedden Do you know if there are special cases where "exchangeable" and "independent" produces the same coefficient estimates?

@josef-pkt

Copy link
Copy Markdown
Member

Good about the Stata results. That's much better (that they get different results between the two corr structures.)

My guess is that there still might be options or default differences. Our GEE summary doesn't show the estimated parameters for correlation and variance.
There could be differences for example in how the correlation is estimated (my experience trying to match Stata's GLSAR equivalent was very mixed, difficult to find the same estimator), or there could be differences in the assumption on heteroscedasticity.
I went over the Stata documentation for the differences between xtgee and other estimators, but that was in summer and I need to look again.

xtgee outcome baseline center age, family(gaussian) corr(independent)
in my interpretation should be equivalent to OLS in our defaults (for coefficients) IIRC.

@josef-pkt

Copy link
Copy Markdown
Member

I forgot about the different position of the constant when I compared your notebook with your Stata results.
"independent" looks the same as our GEE (*)
"exchangeable" looks pretty close between Stata and our GEE.
In this case, there might be just a small difference in the estimate of the correlations. Can you check what the estimated correlation is in our version compared to Stata? There could also be a small difference in the scale estimate, but AFAIU that shouldn't affect the params estimate.

(bug in geepack ?)

(*) standard errors in Stata are quite different, my best guess, given my experience matching sandwiches with Stata, is small sample correction. But I don't remember whether our GEE doesn't use bias corrected by default. I didn't read anything about bias correction for vce in Stata AFAIR.

@kshedden

Copy link
Copy Markdown
Contributor

I would like to do more comparisons with Stata, but at this point, all my
comparisons have been with R. If I recall, the estimates and standard
errors for the independent and exchangeable cases agree very well with R.
The covariance structure update for the exchangeable case is directly out
of the Zeger/Liang papers, and I believe there is only one standard way of
doing it.

However the other covariance structures are not as clearly defined. I had
trouble figuring out how the R code handles the autoregressive case, so I
implemented a method of moments update that makes sense and performs
reasonably well, but does not agree exactly with R.

I'll have more time to look into this starting in about two weeks.

Kerby

On Sat, Dec 14, 2013 at 10:25 PM, Josef Perktold
[email protected]:

I'm still suspicious about the geepack result.
"exchangeable" is the same correlation structure as in a random effects
panel (one way within random constant)
while "independent" should be the same as pooled LS (or just OLS, I guess).
Although GEE uses robust cov instead of the non-robust cov in Panel.

Does unstructured work in our GEE with unbalanced clusters/panel? (Stata
doesn't IIRC the documentation)

'exchangeable' could be verified also with Stata, I guess.

Given your time constraint, it might be better to let Kerby or me worry
about this.

@kshedden https://github.com/kshedden Do you know if there are special
cases where "exchangeable" and "independent" produces the same coefficient
estimates?

—
Reply to this email directly or view it on GitHubhttps://github.com//pull/1215#issuecomment-30597259
.

@vincentarelbundock

Copy link
Copy Markdown
Author

@josef-pkt I also looked at the wrong rows! It looks like our results agree with Stata very well. When I ask Stata to produce robust standard errors, those match up quite well too!

wrt R, I don't know. The gee package gives me the same results as geepack and, from what I can tell, they use different codebases. Maybe there's something I'm missing with the call structure...

SM INDEPENDENCE
                    coef    std err          z      P>|z|      [95.0% Conf. Int.]
------------------------------------------------------------------------------
baseline       0.3737      0.068      5.509      0.000         0.241     0.507
center         0.1330      0.073      1.819      0.069        -0.010     0.276
age           -0.0037      0.002     -1.545      0.122        -0.008     0.001
Intercept      0.3142      0.111      2.840      0.005         0.097     0.531

STATA
     outcome |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
    baseline |   .3737131   .0684468     5.46   0.000     .2395599    .5078663
      center |   .1330252   .0737739     1.80   0.071    -.0115689    .2776194
         age |   -.003695    .002414    -1.53   0.126    -.0084263    .0010363
       _cons |   .3142464   .1116554     2.81   0.005     .0954059     .533087
------------------------------------------------------------------------------


SM EXCHANGEABLE
                 coef    std err          z      P>|z|      [95.0% Conf. Int.]
------------------------------------------------------------------------------
baseline       0.3200      0.076      4.197      0.000         0.171     0.469
center         0.1534      0.075      2.049      0.040         0.007     0.300
age           -0.0042      0.003     -1.512      0.131        -0.010     0.001
Intercept      0.3279      0.114      2.887      0.004         0.105     0.551

STATA
     outcome |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
    baseline |   .3197515   .0769933     4.15   0.000     .1688474    .4706557
      center |   .1534501   .0755258     2.03   0.042     .0054223    .3014779
         age |  -.0042494   .0028373    -1.50   0.134    -.0098103    .0013116
       _cons |   .3279763   .1146574     2.86   0.004     .1032519    .5527006
------------------------------------------------------------------------------

@josef-pkt

Copy link
Copy Markdown
Member

That looks pretty good,

Thanks Vincent. Are the Stata commands the ones from you previous message xtgee ....?
I also want to try some examples.

This time I will really merge this, so we get it in master before Christmas. I just need to get some smaller PR in first. Then it's GEE and IV/GMM as a present for Christmas or any other end of year celebration.

@vincentarelbundock

Copy link
Copy Markdown
Author

Yes, start with:

wget http://vincentarelbundock.github.io/Rdatasets/csv/geepack/respiratory.csv

And then:

insheet using respiratory.csv, clear
xtset id
xtgee outcome baseline center age, family(gaussian) corr(independent) vce(robust)
xtgee outcome baseline center age, family(gaussian) corr(exchangeable) vce(robust)
log close
translate gee.smcl gee.txt

@vincentarelbundock

Copy link
Copy Markdown
Author

I mean "NO". Not quite the same commands since I added vce(robust)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

our standard name is start_params in discrete and others

@josef-pkt

Copy link
Copy Markdown
Member

Looks good to me, merging

Thanks Vincent

josef-pkt added a commit that referenced this pull request Dec 19, 2013
STY/ENH GEE mostly code style, add to formula.api
@josef-pkt
josef-pkt merged commit 6affdc6 into statsmodels:gee_rebased Dec 19, 2013
@vincentarelbundock

Copy link
Copy Markdown
Author

Alright then, didn't expect it to go through right away :)

I'll try to cook up a Notebook example pretty soon and I'll make a new PR for that.

@josef-pkt josef-pkt mentioned this pull request Dec 19, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants