Repository navigation
Add weights to GEE - #2090
Add weights to GEE#2090
Conversation
|
Does this correspond to aweigths or pweights in Stata? From the change it looks like "Weighting to produce homogeneous variances" in the linked FAQ, i.e. specifying cross-sectional heteroscedasticity. My guess is that this needs more unit tests, for bse/cov_params and whatever else might be affected by this. |
|
These would be pweights. I am using them to analyze a survey data set in I checked the standard errors against stata and they agree pretty well, but I could include the test against Stata for standard errors as-is with a On Tue, Nov 18, 2014 at 7:40 PM, Josef Perktold [email protected]
|
based on my experience with figuring out what Stata is doing, I never tried xtgee in Stata:
Also, for the case here for testing the effect of weights, it might be possible to check and write a unit test if there is an approximately constant difference of your results relative to Stata's comparing the case with weights with the one without. In general: I haven't tried/managed yet to really figure out what adjustments Stata is doing for survey weights. The descriptions in the FAQ seems to point also in that direction, but that might only be used with the |
|
Stata apparently multiplies the standard robust covariance matrix by sqrt(N / (N - g)), where N is the total sample size and g is the average group size. I have verified this on examples with constant and with varying group sizes. I don't see this documented anywhere or know of any reference that would explain why this should be done. |
|
Also, probably already known, but Stata seems not to count the intercept when determining denominator dof for the scale parameter. |
|
Ready to merge? |
|
I have a bit more code in my branch, will get it in tonight. Thanks. On Fri, Nov 21, 2014 at 2:00 PM, Skipper Seabold [email protected]
|
|
I think this is ready now. |
There was a problem hiding this comment.
Can this be done with scale_ddof? This should be mentioned here.
|
Also in general, prefix naming convention would require Related: I don't use it directly in other robust sandwiches, I use small sample correction (which depends on the cov_type) and introduced a generic scale factor that allows users to arbitrarily scale the cov_params. |
There was a problem hiding this comment.
add test to calculate the fit with ddof_scale.
AFAIU, it should give the same result, and will provide a test for the new keyword
|
(Just remembered what I wanted to ask earlier.) Does the overall scaling of the weights effect any results? |
|
I think you are right. The estimates should not depend on the On Sat, Nov 22, 2014 at 5:30 PM, Josef Perktold [email protected]
|
There was a problem hiding this comment.
as general FYI: the fastest way in numpy to get an array with identical elements is empty and fill (there is a new function in recent numpy full that I haven't used yet and won't be compatible for us yet.)
|
I don't want to hold this up any longer, but I'm also not trying to figure out how the weights really work. Is it ready to merge? |
|
I think it's ready, I've been using this a lot. Thanks for the review. On Wed, Jan 21, 2015 at 8:00 PM, Josef Perktold [email protected]
|
|
Can you rebase and force push? It's rather far behind master. Otherwise, I'll do the rebase before merging. |
…t Stata for unequal group sizes
4548113 to
8a6bc11
Compare
|
Rebased and force pushed. |
|
you should fetch from upstream, statsmodels master, before rebase so it rebased to the latest version. A few commits behind master, but merging anyway. (no related/conflicting commits) |
|
maybe of related interest and application " Missing observations caused by dropouts or skipped visits present a problem in studies of longitudinal data. When the analysis is restricted to complete cases and the missing data depend on previous responses, the generalized estimating equation (GEE) approach, which is commonly used when the population-average effect is of primary interest, can lead to biased parameter estimates. The new GEE procedure in SAS/STAT® 13.2 implements a weighted GEE method, which provides consistent parameter estimates when the dropout mechanism is correctly specified. When none of the data are missing, the method is identical to the usual GEE approach, which is available in the GENMOD procedure. This paper reviews the concepts and statistical methods. Examples illustrate how you can apply the GEE procedure to incomplete longitudinal data. |
|
Interesting. I had followed the Stata docs which state that there is no application for subject-specific weights, so in #2090 I required cluster-level weights. It was easy to generalize and I now have a working branch for subject-level weights that I will PR later after some more testing. The update formula step 5 on page 3 of this doc is wrong: The denominator also needs to include the weight. The correct formula is here: |
|
Just in general:
both would need to be observation specific, in the second if the outlier is an observation and not an individual |
This PR adds weights to GEE. The implementation follows what is done in Stata, as described here:
http://www.stata.com/support/faqs/statistics/weighted-estimation-and-xtgee/