How this calculation works
Fit shared category probabilities and a finite concentration parameter to repeated count vectors. The Dirichlet-multinomial allows row-to-row variation beyond a fixed multinomial model while retaining the actual total count of each row.
P(x|α)=n!/∏x_j! · Γ(A)/Γ(A+n) · ∏Γ(α_j+x_j)/Γ(α_j), A=Σα_j; ρ=1/(A+1).A worked example
The 36 prefilled rows have three categories and different row totals. The fitted concentration is approximately 2.541910, giving intraclass correlation 1/(A+1)≈0.282334. Category probabilities are the fitted alpha values divided by their sum, not a posterior calculated from a supplied prior.
Good to know
20–150 independent rows, 2–5 categories, nonnegative integer counts≤10000 and positive row totals. Positive interior alpha parameters fitted by three-start bounded log-likelihood optimization; numerical score/curvature checks. Reject unresolved boundary concentration. No covariates, zero inflation, coefficient intervals or global-optimum certificate.
Reference: SciPy Dirichlet-multinomial distribution (opens in a new tab) ↗
Each row represents another composition experiment
A row contains counts allocated among the same named categories in one independent experiment or sampling unit. Its total can differ from other row totals, but the category order must remain consistent across every row.
Combining all rows into one grand count vector discards the between-row variation that this fit is meant to estimate. Conversely, arbitrarily splitting one experiment into many supposedly independent rows can exaggerate the amount of independent information available.
Compare this with the Dirichlet posterior predictive calculator for categorical counts. A Dirichlet posterior with supplied prior counts does not fit between-row overdispersion.
Mean proportions and concentration play different roles
The alpha parameters have a sum A and normalized proportions alpha divided by A. The normalized vector describes the average composition, while A controls how tightly row-specific composition probabilities concentrate around that average.
A large concentration approaches ordinary multinomial behavior. A small concentration permits stronger variation and more lopsided rows. The parameter is not a number of prior observations supplied by the user; here it is estimated from repeated experimental count vectors.
Keep multinomial coefficients in the reported likelihood
The probability of a count vector includes both a multinomial combinatorial factor and gamma-function terms. The fit evaluates these in logarithmic form to avoid multiplying huge factorials and tiny probabilities directly.
Constants independent of alpha do not affect its maximizing value, but they matter when reporting a complete data log likelihood. The output includes them, making an independently computed distribution logpmf a meaningful reference for the numerical result.
Read the fitted concentration in the example
The example contains 36 three-category count rows with varying totals. Its fitted A is about 2.5419, and the corresponding rho is about 0.2823. These quantities summarize overdispersion within the specified shared-composition model.
The fitted category means are estimated jointly with concentration. They need not match an unweighted average of row proportions or a simple pooled count ratio exactly. Those alternatives weight observations differently and do not maximize this same likelihood.
Three starts do not create a global proof
The implementation optimizes logarithmic alpha values from several concentration starts. It retains the best resolved interior fit, checks a numerical score and checks local positive curvature of the negative log likelihood before returning parameters.
These diagnostics describe numerical behavior near the returned estimate. They do not prove that the model fits the data, that every scientific cause of row variation is captured, or that all uncertainty about alpha can be summarized by the displayed decimal places.
Boundary fits require an explicit failure message
Some data provide little evidence of overdispersion and drive concentration toward infinity. Other configurations can move a category parameter toward zero. Publishing the finite search boundary as if it were an ordinary estimate would overstate what was resolved.
This version rejects parameters too close to its logarithmic limits, unresolved curvature and nonconvergent searches. Every category must have at least one observed count, so an entirely absent category is not silently assigned an arbitrary tiny fitted probability.
Use the model only for the chosen sampling units
Rows must be plausibly independent under a shared distribution. Cluster dependence, systematic covariate changes, unequal detection mechanisms and structural zeros can call for a richer model rather than a single common concentration parameter.
The result supplies no automatic category merging, regression, confidence interval or predictive validation. Use its likelihood and fitted proportions as one part of a transparent exploratory analysis, and preserve the original row-level data when comparing alternative models.
A few questions, answered
Can rows have different totals?
Yes. The likelihood uses each row’s actual total rather than requiring one shared trial count.
Is alpha a user-supplied Bayesian prior here?
No. The alpha vector is estimated by likelihood from repeated count rows.
Why can a nearly multinomial sample be rejected?
Its concentration optimum may be effectively infinite, outside a resolved finite interior fit.
What is rho?
Under this Dirichlet-multinomial model, rho=1/(A+1) expresses within-row overdispersion relative to fixed multinomial probabilities.