Skip to content

diagnostic, gof for Poisson and count data #1537

Open

Activity

  1. josef-pkt commented on Apr 28, 2016

    @josef-pkt
    MemberAuthor

    I just remembered this and had to search for it.
    good to implement, AFAIR. (I thought I remember something like this for Binomial/Bernoulli, but maybe not.)

    It smooths the probability integral transform to get something that looks similar to continuous data case.
    The usual is randomization.

    Czado, Claudia, Tilmann Gneiting, and Leonhard Held. 2009. “Predictive Model Assessment for Count Data.” Biometrics 65 (4): 1254–61. doi:10.1111/j.1541-0420.2009.01191.x.

    edit
    issue #2027 has reference issue for Czado
    probabilistic forecasting article is for continuous distributions

  2. josef-pkt commented on Apr 28, 2016

    @josef-pkt
    MemberAuthor

    The Czado et al and similar articles are for predictive distributions and not just for mean prediction.
    i.e. we want to estimate a probability distribution that we can use for prediction, and not just get consistent estimates for mean parameters as in QMLE.

  3. changed the title [-]diagnostic for Poisson and count data[/-] [+]diagnostic, gof for Poisson and count data[/+] on Aug 28, 2017
  4. josef-pkt commented on Aug 28, 2017

    @josef-pkt
    MemberAuthor

    adding this here, see also #3887 which includes ideas for comparing different count models
    The following is from a trying out notebook, based on zero-inflation PR ex_generalizedpoisson_nbp.ipynb
    dataset is randhie

    we can get aggregate predicted probabilities now with predict

    prob_nbp1 = res_nbp1.predict(which='prob').mean(0)
    prob_zip = res_zip.predict(which='prob').mean(0)
    

    Besides plotting the histogram, we can also compute some distance measures. Here I'm using proportions or probabilities and not counts as in chisquare test.
    We still need some helper functions for binning or combining of small or zero count cells. Here I just truncate.

    def pdistance(freq, prob_model):
        freq_ = np.concatenate((freq, [1 - freq.sum()]))
        prob_model_ = np.concatenate((prob_model, [1 - prob_model.sum()]))
        return ((prob_model_ - freq_)**2 / prob_model_).sum()
        
    distance_poi = pdistance(freq[:d], prob_poi[:d])
    distance_zip = pdistance(freq[:d], prob_zip[:d])
    distance_gp1 = pdistance(freq[:d], prob_gp1[:d])
    distance_nb1 = pdistance(freq[:d], prob_nb1[:d])
    distance_nbp1 = pdistance(freq[:d], prob_nbp1[:d])
    
    names = 'distance_poi distance_zip distance_gp1 distance_nb1 distance_nbp1'.split()
    distances = [distance_poi, distance_zip, distance_gp1, distance_nb1, distance_nbp1]      
    for i, di in zip(names, distances):
        print('%-15s' % i, di)
    
    distance_poi    1.3168185068
    distance_zip    1.30513026291
    distance_gp1    0.00404240449299
    distance_nb1    0.0141810233831
    distance_nbp1   0.0141810233831
    

    according to this gp1 would be the best fit in aggregated average distribution. Visually in histogram there is little difference between gp and nb, but poisson and zip are way off.
    gp1 is actually gp(p=1.2) where I did a rough (eyeballing the histogram) search for p.

  5. josef-pkt commented on Aug 28, 2017

    @josef-pkt
    MemberAuthor

    related: eval_measures for non-continuous variables and GLM #2572

  6. josef-pkt commented on Aug 28, 2017

    @josef-pkt
    MemberAuthor

    bar plots using pandas (I like the look of my handmade better.)

    plot of frequencies

    fig = plt.figure(figsize=(8,6))
    ax = fig.add_subplot(111)
    d = 13
    df2 = pd.DataFrame(np.column_stack([freq[:d], prob_poi[:d], prob_zip[:d], prob_gp1[:d], prob_nb1[:d]]), 
                       columns=['freq', 'poisson', 'zip', 'gp(1.2)', 'nb1'])
    df2.plot.bar(ax=ax)
    

    difference between predicted and observed frequencies/probabilities

    fig = plt.figure(figsize=(8,6))
    ax = fig.add_subplot(111)
    d = 13
    df2 = pd.DataFrame(np.column_stack([i - freq[:d] for i in [prob_poi[:d], prob_zip[:d], prob_gp1[:d], prob_nb1[:d]]]), 
                       columns=['poisson', 'zip', 'gp(1.2)', 'nb1'])
    df2.plot.bar(ax=ax)
    

    count_freq_diff

  7. danielkurniadi commented on Dec 30, 2019

    @danielkurniadi

    Hi @josef-pkt , have we added any dispersiontest functionality similar to that of AER or DHarma in R?

  8. josef-pkt commented on Dec 30, 2019

    @josef-pkt
    MemberAuthor

    https://github.com/statsmodels/statsmodels/blob/master/statsmodels/discrete/_diagnostics_count.py

    Mainly for poisson, many versions without clear preferences or recommendations AFAIR

    (I’m on a skiing trip and can provide more info in the next few days.)

  9. josef-pkt commented on Dec 30, 2019

    @josef-pkt
    MemberAuthor

    Correction I didn't remember correctly.
    That module has mainly zero inflation tests. I don’t remember where the excess dispersion tests are

  10. josef-pkt commented on Dec 30, 2019

    @josef-pkt
    MemberAuthor

    def dispersion_poisson(results):

  11. danielkurniadi commented on Dec 30, 2019

    @danielkurniadi

    Alright will take a look. Enjoy the skiing trip. Merry XMas and Happy New year btw.

  12. josef-pkt commented on Apr 21, 2021

    @josef-pkt
    MemberAuthor

    I don't find an issue with this reference

    frequency plot similar to what I have in notebook and prob_plots in statsmodels.discrete._diagnostics_count

    Holling, Heinz, Walailuck Böhning, Dankmar Böhning, and Anton K Formann. 2016. “The Covariate-Adjusted Frequency Plot.” Statistical Methods in Medical Research 25 (2): 902–16. https://doi.org/10.1177/0962280212473386.

    Holling, Heinz, Walailuck Bohning, and Dankmar Bohning. 2015. “The Covariate-Adjusted Frequency Plot for the Rasch Poisson Counts Model.” Thailand Statistician 13 (1): 67–78.

    This includes a random effects Poisson model, but it is not clear from the article, whether or how they include the random effects in the predicted frequencies/probabilities.

    maybe they only used fixed effects for the plots.

    aside: their 2016 article has a discussion on exposure and n_trials in Poisson and Binomial count models.
    I just checked: PoissonResults predict_prob, and predict function in new count models like GPP, NBP include offset and exposure
    both in the same way as for predict function.
    I didn't check the exposure case for this plot, but it looks like offset and exposure are automatically included.

  13. danielkurniadi commented on Apr 22, 2021

    @danielkurniadi

    ok cool.

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