Skip to content

ENH: GLMInfluence, extend OLSInfluence to WLS #4268

Open

Description

@josef-pkt

this is a specific issue to get the analogue of stats.outliers_influence.OLSInfluence for GLM and WLS,
It might be possibly to also extend to other models that follow the same pattern and can provide residuals and hat_matrix (maybe RLM and TheilRidge).

the more general issues are
#3336 general diagnostics and specification for other models
#3743 general GLM/WLS diagnostics, the current issue would implement the influence/outlier part
#4257 influence and outliers based on general properties of MLE and M-Estimators. the current issue is a special case where influence function, hessian, score are defined specifically for the model as OLS analogue.

#4267 one specific implementation part: attach weights and hat_matrix_diag so they can be used for the outlieres and influence measures

Implementation

preliminary work in gist and discussion in
#4267 (comment)

For GLMInfluence we can essentially just translate formulas to code, e.g. Pregibon, Williams and a few other references (my reading was partially random, and I didn't check any GLM text books)

For WLS, I don't have a reference. Giltinan, Carrol and Ruppert 1986 consider the HetGLS case for WLS, i.e. it's a two-parameter model with influence also coming through the estimation of the variance function.
My guess is that for the fixed weights WLS (var_weights) case, we can just use wexog and wresid in all parts of OLSInfluence instead of the unweighted attributes. That sounds correct for influence on parameters and parameter influence.
However, I guess we want the influence on prediction to be on the original endog.

unit tests, reference functions in other packages
I have no idea yet.
according to https://stackoverflow.com/questions/47686227/poisson-regression-in-statsmodels-and-r R has a glm.diag and glm.diag.plots
https://stat.ethz.ch/R-manual/R-devel/library/boot/html/glm.diag.html
I don't know why it is in boot, boot has license: "unlimited"
another
https://stats.stackexchange.com/questions/45401/how-to-validate-diagnose-a-gamma-glm-in-r

Activity

  1. added this to the 0.10 milestone on Feb 24, 2018
  2. josef-pkt commented on Feb 24, 2018

    @josef-pkt
    MemberAuthor

    Stata glm postestimation had hat and cooksd in predict, and additionally standardized (using hat matrix diagonal) and studentized (using scale) versions of the residuals.

    details in formulas

    • weights W in hat matrix is described to be equal to Variance, which sounds strange/wrong to me in the non-canonical link case, see my comments in GLM function not returning weights #4267
    • cooksd divides additionally by k (number of regressors including constant) (which I didn't do in my gist, and Pregibon 1981 doesn't either equ (6) and next formula after equ (7). The latter is what Stata uses (no square in denominator, i.e. resid_pearson**2 * hii / (1 - hii)

    edit about dividing by k
    some other articles divide by k to standardize cooksd
    The trace of the hatmatrix, or some other matrix product (?), sums to k_exog,

  3. josef-pkt commented on Feb 24, 2018

    @josef-pkt
    MemberAuthor

    another aside: computational efficiency, numerical stability
    Pregibon 1981 mentions using QR at the end, which is in generally favored and used by the R/Julia developers.
    One advantage would be that scipy has or will get downdating, which might also be useful for dropping mutliple observations.

    However, we are usually using SVD/pinv which I find easier (or are more familiar with).
    (One possible issue: What's the interpretation when we the regularization in pinv is used for the numerically singular case? In OLS/WLS/IRLS that still corresponds to what the current implementation actually does in the default case.)

  4. josef-pkt commented on Jun 9, 2018

    @josef-pkt
    MemberAuthor

    some notes on implementation details for GLM:
    I'm starting GLMInfluence with test case against a SAS example

    options for hat_matrix_diag

    • EIM, weights = model.hessian_factor(res.params, observed=False) this is the same as IRLS weights up to convergence tolerance. Displayed in SAS printout
    • OIM, weights = model.hessian_factor(res.params, observed=True) this uses actual hessian, i.e. corresponds to one newton step, but otherwise uses the same WLS hat matrix.
      SAS doesn't have this for GLM but it looks like they have a newton step weights in procedure logistic that look similar to observed hessian factor (for Binomial models with non-canonical link)
    • MLE version: use observed hessian and score. I don't know yet how this will look like, but we don't take the WLS hatmatrix pattern, maybe diag(score_obs dot (-Hessian)**(-1) dot score_obs.T)

    I planning to add a GLMResults.get_hat_matrix_diag method that can take options instead of using an attribute.

  5. josef-pkt commented on Jun 14, 2018

    @josef-pkt
    MemberAuthor

    comment about sandwich cov_params in influence measures (GEE case)

    quote from Preisser and Qaqish 1996, end of section 3.2 in context of dfbeta_scaled

    """
    Both of these scaled measures for the change in beta_hat use the naive variance estimate
    which is a consistent estimate of the true variance of beta_hat only if the working correlation
    structure is correctly specified. Alternatively, scaling may be done by the robust variance
    estimate which is consistent even under misspecification of R{a) (Liang & Zeger, 1986).
    We prefer the naive variance estimate. The robust variance estimate, with squared residuals
    in the middle of its sandwich formula, is inflated by large residuals, so its use for standardisation
    would mask observations with large residuals.
    """

  6. josef-pkt commented on Jun 14, 2018

    @josef-pkt
    MemberAuthor

    another sandwich comment, again GEE

    quote from Bradley G. Hammill, John S. Preisser A SAS/IML software program for GEE and regression diagnostics

    reformatted from middle of page 1200
    """
    Similarly, let DOBSij be the observation-level Cook’s D for the jth observation in cluster i, which can be calculated as
    DOBSij = DFBETAOij M DFBETAOij / p
    In this macro, the following specifications of M are available:
    (1) M = the inverse of the model-based covariance estimate,
    (2) M = the inverse of the empirical covariance estimate, and
    (3) M = the inverse of the bias-correctedcovariance estimate.
    """

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions