Skip to content

ENH: Bias in GLM scale estimate, scale in gamma larger than MLE #7525

Open

Description

@josef-pkt

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

Pit didn't look very good with default scale

TBC (need to run)

Activity

  1. josef-pkt commented on Jun 29, 2021

    @josef-pkt
    MemberAuthor

    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

    nobs
    50
    stats.kstest(pit, "uniform")
    KstestResult(statistic=0.25367781901056613, pvalue=0.0025290446272375755)
    stats.kstest(pit_mle, "uniform")
    KstestResult(statistic=0.08886670725932139, pvalue=0.7918381302029637)
    

    with PIT

    distr_mle = stats.gamma(shape_mle, scale=scale_mle)
    pit_mle = distr_mle.cdf(y)
    plt.hist(pit_mle, bins=np.linspace(0, 1, 21))
    

    Pit histogram with (profile) MLE scale, nobs = 20000
    image

    Pit histogram with pearson chi2 scale, nobs = 300
    image

  2. josef-pkt commented on Jun 29, 2021

    @josef-pkt
    MemberAuthor

    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.

  3. josef-pkt commented on Jun 30, 2021

    @josef-pkt
    MemberAuthor

    normal scores qqplot

    import statsmodels.graphics.gofplots as gp

    pearson chi2 scale:

    gp.qqplot(stats.norm.ppf(pit), stats.norm, line="45");
    image

    profile-mle scale:

    plot(stats.norm.ppf(pit_mle), stats.norm, line="45");
    image

  4. josef-pkt commented on Jun 30, 2021

    @josef-pkt
    MemberAuthor

    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.

  5. josef-pkt commented on Jul 1, 2021

    @josef-pkt
    MemberAuthor

    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:

    check/add for gaussian and inverse gaussian families

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