You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ENH: Bias in GLM scale estimate, scale in gamma larger than MLE #7525
I'm experimenting with gamma parameterization using GLM.
It looks like pearson_chi2 scale is upward biased, i.e. larger than in data generating process and larger than profile MLE.
example default GLM scale = 10.222, profile-MLE = 9.652
The problem in the gamma example comes from a few large residuals (heavy tails ?)
continuous with example with nobs=300
from statsmodels.robust import scale as robscale
robscale.mad(results.resid_pearson)**2, robscale.iqr(results.resid_pearson)**2, results.resid_pearson.var(ddof=2), results.scale
(6.754030599189746e-05,
0.04818820437606308,
15.307996548260522,
15.307996548260522)
import statsmodels.stats.robust_compare as robcomp
robcomp.TrimmedMean(results.resid_pearson, 0.2).var_winsorized
0.0626056548930061
results.resid_pearson[results.resid_pearson < 10].var(ddof=2)
2.4368080086817816
When we work with heavy tailed distribution, then it would be better to use methods that discount outlying observations, e.g. mle or robust scale, instead of var or pearson_chi2.
edit
one problem with this is that the robust scale measures are all calibrated for the normal distribution. Here gamma is very different from the normal distribution, if the main part is still in small values.
Running my notebook a few times without using the random.seed, nobs=300
The above plots are not typical,
chi2 scale is noisy, i.e. fluctuates a lot across samples, but is not overestimating scale in most cases.
gofplot using chi2 scale shows deviations in both directions of the 45 degree line. The fluctuations across samples are larger than the fluctuations using mle scale. mle_scale estimate looks much more stable.
diagnostic: some version of PIT, gof plots. I'm not sure yet where to put those and how to interface them.
this version only works for continuous distributions, not for discrete WIP/ENH: add discrete Diagnostic classes #7166 started diagnostic classes for discrete distributions
check/add for gaussian and inverse gaussian families
Activity
josef-pkt commentedon Jun 29, 2021
mle scale looks better in small sample, e.g. nobs < 500 or nobs <100
pearson_chi2 scale looks better in (very) large samples, nobs >= 20,000
with PIT
Pit histogram with (profile) MLE scale, nobs = 20000

Pit histogram with pearson chi2 scale, nobs = 300

josef-pkt commentedon Jun 29, 2021
The problem in the gamma example comes from a few large residuals (heavy tails ?)
continuous with example with nobs=300
When we work with heavy tailed distribution, then it would be better to use methods that discount outlying observations, e.g. mle or robust scale, instead of var or pearson_chi2.
edit
one problem with this is that the robust scale measures are all calibrated for the normal distribution. Here gamma is very different from the normal distribution, if the main part is still in small values.
josef-pkt commentedon Jun 30, 2021
normal scores qqplot
import statsmodels.graphics.gofplots as gppearson chi2 scale:
gp.qqplot(stats.norm.ppf(pit), stats.norm, line="45");profile-mle scale:
plot(stats.norm.ppf(pit_mle), stats.norm, line="45");josef-pkt commentedon Jun 30, 2021
Running my notebook a few times without using the random.seed, nobs=300
The above plots are not typical,
chi2 scale is noisy, i.e. fluctuates a lot across samples, but is not overestimating scale in most cases.
gofplot using chi2 scale shows deviations in both directions of the 45 degree line. The fluctuations across samples are larger than the fluctuations using mle scale. mle_scale estimate looks much more stable.
josef-pkt commentedon Jul 1, 2021
here is my current notebook
I changed the seed to have chi2 scale closer to correct value
https://nbviewer.jupyter.org/gist/josef-pkt/18b80adb766aee8e506273ef2870157a
todo:
this version only works for continuous distributions, not for discrete
WIP/ENH: add discrete Diagnostic classes #7166 started diagnostic classes for discrete distributions
check/add for gaussian and inverse gaussian families