Skip to content

var_weights and #3543 - #3692

Merged
josef-pkt merged 20 commits into
statsmodels:masterfrom
thequackdaddy:var_weight_3543
Jun 20, 2017
Merged

josef-pkt merged 20 commits into
statsmodels:masterfrom
thequackdaddy:var_weight_3543

Conversation

@thequackdaddy

Copy link
Copy Markdown
Member

Hello:

This PR contains both #3543 and #3410, with #3543 rebased on master, and then #3410 rebased on top of that.

Let me know if this is what you want.

@coveralls

coveralls commented May 23, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.05%) to 90.474% when pulling 320b3d1 on thequackdaddy:var_weight_3543 into aed3187 on statsmodels:master.

@thequackdaddy

Copy link
Copy Markdown
Member Author

@josef-pkt I think this is what you wanted. Let me know if helpful.

I'd be thrilled to get this merged.

Thanks.

@thequackdaddy

Copy link
Copy Markdown
Member Author

@josef-pkt I realized that I missed your comment in #3410:

(*) Another testcase where loglike/llf will fail is comparing GLM Gaussian and var_weights and WLS, based on a missing term in this PR in the families.Gaussian.loglike, AFAICS. This might or might not be fixed in 3543.

So I added a test for that. Sure enough, you were right... loglike won't match. Should I fix that?

I noticed your comment about this taking years to figure out, and there are still blanks out there. I sincerely thank you for your work on this. Its been very, very helpful--I've learned a lot about this models over the past year fiddling with this.

As I have this written now in 2 separate PRs, please let me know if you'd rather I close this one and let you deal with these 2 PRs separately or if this combined one is better. Honestly not sure of your opinions on it.

Thanks again, @josef-pkt .

@coveralls

coveralls commented May 25, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.05%) to 90.476% when pulling 7a818f1 on thequackdaddy:var_weight_3543 into aed3187 on statsmodels:master.

@josef-pkt

Copy link
Copy Markdown
Member

If nothing new gets in the way, then I will look at this PR in the next few days. Most likely we can merge this version instead of the two separate ones, the merge and network graph looks good.

I think the main open issue that we postpone is MLE versus QMLE and, related, double exponential model for var_weights in models with scale=1. If Gaussian llf still fails here, then there are still bugs in families that define a scale different from 1 (because there scale and var_weights are defined for MLE in loglike.)

To return the thanks. It has been a long time since I read the Stata weights documentation for the first time, and didn't understand much of the background. The discussions with you were very helpful, and you did most of the actual implementation.

@josef-pkt

josef-pkt commented May 25, 2017 •

Copy link
Copy Markdown
Member

I thought fixing Gaussian loglike was merged or in the included PR here. But it's not.
fix is in this PR
https://github.com/statsmodels/statsmodels/pull/2353/files#diff-20016798d17fceba2ff1d3dfec9f2e61R516

ftp://public.dhe.ibm.com/software/analytics/spss/documentation/statistics/24.0/en/client/Manuals/IBM_SPSS_Statistics_Algorithms.pdf
page 414 table 46-5 has the loglike for the GLM families.
In the distributions that have a scale != 1 (and not just over- under-dispersion scale), Gaussian, Inverse Gaussian and Gamma, var_weights need to enter the loglike in the same way as scale
in SPSS notation scale / var_weights = phi / w

In Poisson and Binomial, var_weights w enter loglike in the same way as freq_weights f in the loglike according to the SPSS table.

params and cov_params are correct because the extra, currently incorrect parts don't affect the estimating equations for the mean parameters given fixed scale and var_weights. (That's why we see the problems only in llf and maybe deviance, common additive terms also drop out of the deviance.)
(Currently loglike are incorrect if we want to estimate scale and var_weights additional to the mean parameters by MLE)

(I will try to get an overview of the status of various GLM PRs)

@josef-pkt

josef-pkt commented May 25, 2017 •

Copy link
Copy Markdown
Member

only parts of #2353 are relevant here, other genmod PRs don't directly affect this PR.
(I'm not sure yet about the changes in the default handling of estimate_scale in #2353)
edit 2353 has a good discussion about the estimate_scale option and various scale definitions

One change we need is to separate var_weights from the other weights in loglike and related. (A possibly too "tricky" idea is to use the scale argument of loglike also for var_weights)

@josef-pkt

Copy link
Copy Markdown
Member

another issue full loglike versus fast loglike:
This issue came up a few times already, but fixing var_weights in loglike has the same implication.
For mean estimation we don't need several extra terms in the loglikelihood, these are terms that are constant (independent of mean parameters) given the data or constant given the variance. During optimization we could drop those. However, so far we always decided to use the full loglikelihood.
In GLM it is a bit easier because we still have IRLS which does not use loglike and is not affected by these extra terms.
I think we stick with this and fix loglike and related to be the full log likelihood including the terms we would need to optimize with respect to scale/var_weights.

(Leaving out the terms during optimization or keeping cached versions around looks too complicated right now.)

about deviance:
According to table 46-15 in the SPSS manual, both var_weights and freq_weights are just multiplicative factors. resed_deviance and similar need/should include var_weights but no other weights.
(IIRC, Stata doesn't do that. I didn't check the unit tests for this.)

@josef-pkt

Copy link
Copy Markdown
Member

I was looking at Gamma.loglike to see how "wrong" it is, and found the following comment in the code

        # in Stata scale is set to equal 1 for reporting llf
        # in R it's the dispersion, though there is a loss of precision vs.
        # our results due to an assumed difference in implementation

@josef-pkt josef-pkt mentioned this pull request May 30, 2017
7 tasks done
@thequackdaddy

Copy link
Copy Markdown
Member Author

Hi Josef. Sorry if I've missed something. Had to be away for the past week unexpectedly.

It looks like you don't like the current way we are doing loglikelihood and deviance. Is there anything here you want fixed in this PR? I looked at the loglikelihood formulas in the SPSS manual (thanks for finding those) and they look to be different in some cases to the values in the test suite...

I presume you want this fixed in another PR. But if my mistaken impression is holding up a merge, let me know.

Thanks.

@josef-pkt

Copy link
Copy Markdown
Member

can you rebase and then I will merge as is.

I don't have time right now, and I think it's easier to continue with incremental fixes before the next release. I would like to have at least one more round by the end of summer.

parameter estimates and wald inference (with limited cov_type) are good, so it is useful as the first main step towards full support of var_weights.

@coveralls

coveralls commented Jun 20, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.05%) to 90.486% when pulling 35c21fb on thequackdaddy:var_weight_3543 into c56e13c on statsmodels:master.

@josef-pkt

Copy link
Copy Markdown
Member

all green, merging

thanks @lorentzenchr @thequackdaddy

@josef-pkt
josef-pkt merged commit cc3fd16 into statsmodels:master Jun 20, 2017
@thequackdaddy
thequackdaddy deleted the var_weight_3543 branch June 20, 2017 20:17
@thequackdaddy

Copy link
Copy Markdown
Member Author

Thanks, @josef-pkt !

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.

3 participants