Repository navigation
Description
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
josef-pkt commentedon Feb 24, 2018
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
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,
josef-pkt commentedon Feb 24, 2018
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.)
josef-pkt commentedon Jun 9, 2018
some notes on implementation details for GLM:
I'm starting GLMInfluence with test case against a SAS example
options for hat_matrix_diag
weights = model.hessian_factor(res.params, observed=False)this is the same as IRLS weights up to convergence tolerance. Displayed in SAS printoutweights = 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)
I planning to add a
GLMResults.get_hat_matrix_diagmethod that can take options instead of using an attribute.josef-pkt commentedon Jun 14, 2018
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.
"""
josef-pkt commentedon Jun 14, 2018
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.
"""