Skip to content

ENH: add binned prediction table #7149

Open

Description

@josef-pkt

specific issue for a function that computes prediction table based on binning the space of endog. It can be attached as method to models that don't have pred_table.

Should work for continuous and count models, Maybe a good default would be 5 bins, so it can still be easily printed.

I think we would need predictive distribution, we cannot just compare observations with predicted mean.

related:
#5388 tools for binning and similar
#7080 add "inconclusive" to binary, multinomial
#7142 predictive distribution
#6252 PR for pred_table in GLM, binary only.

#6430 plots for predicted probabilities, not a cross-table, only comparing margins

maybe confusing
pred table is for classification, i.e. for choice with highest prob.
Maye I want more something with predicted probabilities, i.e. observed versus prob of bins

The only current example is in my count notebook or maybe diagnostic count for new models where we have all predicted probabilities in predict method.

Other version:
Instead of binning in endog space, we could groups observations similar to Hosmer-lemeshow test and compare group means and predicted means.
But this would be more a check on nonlinearity, no breaks or homogeneity across groups instead of on predictive distribution

Activity

  1. added this to the 0.14 milestone on Aug 25, 2021
  2. josef-pkt commented on Feb 23, 2023

    @josef-pkt
    MemberAuthor

    We need some functions for this.

    It's the second time (or third, ...) that I saw questions that try to compare distribution of endog with distribution of predicted mean (predict()).
    https://stackoverflow.com/questions/75544577/valueerror-observed-and-expected-need-to-have-the-same-number-of-observations

  3. josef-pkt commented on Feb 21, 2025

    @josef-pkt
    MemberAuthor

    small detour (because I was puzzled about the distribution of bin/cdf counts aggregated over observations)

    Prob(yi <= y' | x_i, theta) = cdf(y' | x_i, theta) = p_i

    sum over i is sum of bernoulli rvs with unequal probabilities.

    The distribution is Poisson Binomial distribution. with mean = sum_i pi and variance = sum_i pi * (1 - pi) (just property of sum of independent rv), however pdf, cdf are difficult.
    https://en.wikipedia.org/wiki/Poisson_binomial_distribution
    https://math.stackexchange.com/questions/392860/sum-of-bernoulli-random-variables-with-different-success-probabilities
    https://stats.stackexchange.com/questions/93852/sum-of-bernoulli-variables-with-different-success-probabilities

    For the binning case we would have sum of multinomial,
    https://math.stackexchange.com/questions/2164222/generalizing-poissons-binomial-distribution-to-the-multinomial-case

    However, we don't really care, although it's interesting.

    We us relative frequencies (bin counts divided by nobs, i.e. averaged over observations).
    This means law of large numbers applies and we only need mean and variance for large sample asymptotics.

    But I think this is not included in the uncertainty estimation.
    The above is the inherent distribution for the observed frequencies.

    AFAICS, we only look at parameter uncertainty, for example cdf as a function of estimated theta-hat.
    i.e. f(theta_hat) = sum_i cdf(y' | x_i, theta_hat) with delta method or similar applied to the given function f of theta.
    and similarly for multiple bins.

    For small samples or with small aggregate counts, this might not be a good approximation.

    In the case of rare events, the poisson approximation in https://en.wikipedia.org/wiki/Poisson_binomial_distribution
    might be useful.

    aside: python implementation of Poisson-Binomial https://github.com/tsakim/poibin/tree/master (link in Wikipedia page)

  4. josef-pkt commented on Nov 20, 2025

    @josef-pkt
    MemberAuthor

    aside:
    curiously Poisson-Binomial is under-dispersed relative to Binomial.

    I thought random coefficients or mixture distributions always lead to over dispersion.
    https://en.wikipedia.org/wiki/Mixed_Poisson_distribution#Properties

    Maybe because the heterogeneity here are fixed effects and not random effects/coefficient.
    (I vaguely remember being confused about this already once before.)
    Simulation with "random" coefficients fixed across Monte Carlo replications, versus new random coefficients in each replication.
    Heterogeneity does not mean we consider a random population, analysis is conditional on the selected population and not for the super population.

    detail: under dispersion of PB relative to B depends on the variance of the individual probabilities (times nobs), i.e. sum of squares.

    So we could have Poisson-Binomial as under-dispersed and Beta-Binomial as over-dispersed alternatives to Binomial, except Poisson-Binomial is difficult to work with.

    Implication for population averaged bin or categorical probabilities or relative frequencies:
    Heterogeneity because of unequal predicted probabilities (unequal exog) would lead to smaller than binomial variance of relative frequencies aggregated over the sample. We could add under dispersed (non-simultaneous) confidence interval to estimated relative population frequencies.
    In contrast mean is additive and we don't have a problem.

    I guess similar for Poisson-multinomial, generalized multinomial
    https://arxiv.org/pdf/2201.04237
    mean, var at beginning of section 2
    mean and var for each category are the same as in PB.

    Actually:
    mean and variance (and cov) are just general properties of summing independent random variables.
    (we always get within and between variances ?
    Variance of fixed effect is just descriptive statistic, not an estimate of a fictitious super population parameter.)

    (I guess this just goes back to estimating average treatment effect, which does not require identical coefficients across individuals. Wooldridge emphasizes this often E(y) of sample population versus E(y|x) ?)

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions