Skip to content

Suggestion: include quasi-likelihood models #4942

Open

Description

@dsaxton

I think quasi-likelihood models (https://en.wikipedia.org/wiki/Quasi-likelihood) could make a useful addition to statsmodels, especially since they currently do not seem to have an implementation in Python (they are however supported in R, even within the base glm function). I do see that statsmodels includes generalized estimating equations, but I don't know enough about these to say how much overlap these have with quasi-likelihood methods.

In any event, one common use case for these models is dealing with overdispersion in count data, where a Poisson distribution may not provide the best fit (see issue #2632).

Activity

  1. josef-pkt commented on Aug 19, 2018

    @josef-pkt
    Member

    There are many open and closed issues on this. I have been working on that for several years.

    We don't use the quasi-loglikelihood loglike function itself, and we don't officially support the simple case of dispersion coefficient, i.e. quasi-poisson, although it is mostly implemented as a "side effect" of the generality of GLM.

    However, we have cov_type='HC0' which produces cov_params and standard errors bse that are robust to misspecified variance, which is more general than only allowing for excess dispersion.
    The parameter estimates in GLM or linear exponential family only depend on a correctly specified mean (inverse link) function, the variance only improves asymptotic efficiency, as long as we compute the correct dispersion or heteroscedasticity robust cov_params.

    short hand: our GLM can work under similar assumptions as GEE but without the specific panel/group structure. QMLE is built into GLM and not a special family as in R.
    Our version also supports continuous non-negative endog in the count models or continuous endog in [0, 1] for Binomial/Logit/Probit because with cov_type='HC0' we get the robust cov_params for these cases.

    There are open issues for enhancements to have full, unit tested support for the case when we only have excess dispersion instead of full heteroscedasticity robustness, HC0. One use case for that is that we can still compare quasi-likelihood for models that are only misspecified by excess dispersion across models, i.e. compare dispersion corrected loglike or deviance.

    I guess we need to improve the documentation to make this easier to find.

  2. josef-pkt commented on Aug 19, 2018

    @josef-pkt
    Member

    another way of stating this:
    We have Goddambe/Eicker/Huber/White robust sandwich cov_params built into the models as fit keyword in regression linear models, discrete models and GLM.
    GLM with quasi-likelihood interpretation is just reusing this, but doesn't have the excess dispersion special case from the GLM statistics literature yet.

  3. dsaxton commented on Aug 19, 2018

    @dsaxton
    Author

    Perhaps improving the documentation could help. Looking over it just now (and doing a grep on the code base) it's not clear to me how one would implement a basic quasi likelihood model.

    Aside from the documentation, there might be value in providing a very simple interface (e.g., a QuasiGLM class) for users who have basic knowledge of quasi-likelihood, but may not know about the subtleties of robust covariance estimation. They would only need to understand the concept of a variance function and provide this as a parameter. In my opinion it should be no more difficult than it is in R, which is to specify (for example) family = quasipoisson along with a variance function in a call to glm.

  4. josef-pkt commented on Aug 19, 2018

    @josef-pkt
    Member

    actually, I think ours is easier and more flexible, once we understand that quasixxx just changes the variance/dispersion assumption, and does not affect the mean parameter estimates.
    http://nbviewer.jupyter.org/gist/josef-pkt/d21e6fc6d4cede4f7d60#GLM-Poisson

    mod = GLM(endog, exog, family=Poisson())
    res_glm_hc1 = mod.fit(cov_type='HC1')
    

    which also allows for other cov_types like cluster robust similar to GEE

    I think it's mainly a documentation question.

    Choosing arbitrary variance functions is not officially supported, although it works through a backdoor.
    Double exponential models or similar where the variance depends on explanatory variables is currently missing (and not even any draft code yet)

  5. dsaxton commented on Aug 19, 2018

    @dsaxton
    Author

    Interesting, I myself wasn't aware of this connection between quasi-likelihood and robust covariance estimation. I'm assuming HC1 does in an automated way what the user would be doing by simply guessing a variance function? It could be useful to benchmark this against R's family = quasipoisson option.

    Quick question, if HC1 is so flexible that it effectively mimics the behavior of a quasi-likelihood model, in what way are the data still treated as being Poisson distributed?

  6. josef-pkt commented on Aug 19, 2018

    @josef-pkt
    Member

    actually we also have scale as fit keyword
    http://www.statsmodels.org/devel/generated/statsmodels.genmod.generalized_linear_model.GLM.fit.html

    However, there were several fixes for scale in the last release, and the usage is not unit tested for the QMLE like quasi-poisson case.
    e.g. some discussion about it is in #3773

  7. dsaxton commented on Aug 19, 2018

    @dsaxton
    Author

    I'm trying to wrap my head around the connection between covariance estimation and quasi-likelihood and there's an idea I'm struggling with. Quasi-likelihood deals with the marginal distribution of y (the relationship between the mean and variance specifically), so at least on the surface it seems to be separate from questions about covariance structure.

  8. josef-pkt commented on Aug 19, 2018

    @josef-pkt
    Member

    take example OLS
    OLS estimates consistently the parameters if the linear mean function is correctly specified. This is true even if there is heteroscedasticity and correlation across observations i.e. variance and correlation are misspecified.
    However, even though the mean parameters are consistently estimated, the standard OLS covariance matrix of the parameter estimates is incorrect if there is heteroscedasticity or correlation. Robust sandwich covariance estimators still correctly estimate the cov_params for the corresponding misspecified heteroscedasticity (HC) or cluster correlation or autocorrelation.

    The same as for OLS is true for the linear exponential family, i.e. GLM, Poisson, Binomial, ...

    The core assumption is that the mean function E(y | x) = inverse_link(x beta) is correctly specified, then we can estimate beta consistently.
    We don't need any other assumption on the distribution for this, but we are also not estimating anything else of the population distribution than the conditional expectation.

    The variance assumption is a "bonus".
    Even though OLS consistently estimates the mean parameters even when there is heteroscedasticity, it will not be an efficient estimator if we have some information about the heteroscedasticity and can use WLS instead.
    Similarly in GEE, using a working correlation structure improves the efficiency (asymptotic variance) of the estimator, but it is not needed for the underlying consistency of the mean parameter estimates, and the working correlation structure does not need to be correctly specified because we still use additionally a cluster robust sandwich cov_params.

    quasipoisson in the sense of excess dispersion makes an intermediate assumption. It assumes that the Poisson variance var(y) = mu is correctly specified except for an additional dispersion coefficient, i.e.
    var(y) = theta * mu. The corresponding cov_params is corrected for the excess dispersion theta but is not robust to other misspecification of the variance of y, e.g. the second negative binomial version (NB2) assumes var(y) = mu + a mu^2. If that is the true model, then inference for quasi-poisson with only excess dispersion would be wrong, but 'HC' would still be robust to this misspecification.

  9. josef-pkt commented on Sep 30, 2018

    @josef-pkt
    Member

    related: PR #5277
    based on my looking into NegativeBinomial we already have the full QMLE case with dispersion coefficient implemented and NB as test case for scale='x2' i.e. pearson_chi2.

    We still need documentation and a notebook to contrast this with cov_type, nonrobust or hc0.
    (I looked at it mainly during the var_weights/scale cleanup PR)

  10. thequackdaddy commented on Oct 15, 2018

    @thequackdaddy
    Member

    @josef-pkt Going back to Tweedie

    For Tweedie, we do not define any logliklihood function. That is fine because IRLS and newton just use either deriv/deriv2 of the variance and link functions (IRLS) or score and hessian (newton). However, lbfgs and other optimizers work best with the loglike defined.

    For Tweedie--and only Tweedie--would you be OK with having the loglikelihood be the extended quasi likelihood function?

    SAS has kindly pubished the formula they use here:
    http://support.sas.com/documentation/cdl/en/stathpug/67524/HTML/default/viewer.htm#stathpug_hpgenselect_details16.htm

    Should we document it in the GLM notes if we did this, or perhaps modify GLMResults.summary to say "quasi-likelihood" in that case?

    And to confirm (I think the answer was yes) do you think that the "extended quasi" F-test would still be valid? I should use that test more, but have not, personally.

  11. josef-pkt commented on Oct 15, 2018

    @josef-pkt
    Member

    @thequackdaddy

    based on what I remember:

    Yes to adding a loglikelihood implementation to tweedie. Your PR is still open and this should be added.

    No to calling/documenting it as QMLE. It's a numerical approximation to the proper likelihood, while QMLE, especially the way I usually use it refers to general misspecified likelihood functions in the linear exponential family. (There are too many different things called QMLE across branches of literature.)
    I think we should document it as approximate likelihood in general and a bit more details

    I don't remember about "extended quasi" F-test.
    I think it should work for a loglikelihood ratio type test, which we still don't have for GLM.
    I don't remember where the approximation makes shortcuts that rule out some use cases, e.g. AFAIR scale is not properly included, if we would want to estimate the scale and dispersion parameters maximizing the loglike.

  12. josef-pkt commented on Oct 15, 2018

    @josef-pkt
    Member

    I never really thought about that our "newton" only uses score and hessian. That's because the implementation is very basic and doesn't do any stepsize checking.
    The more robust newton methods in scipy do need the objective function to avoid going the wrong way if the hessian is not nice (positive definite or positive semi-definite).
    Our newton uses a small Ridge adjustment to work better in at least some of the "not nice" cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions