Skip to content

Poisson regression of counts over an exposure

stats_poisson_regression

Fits a Poisson regression to counts per exposure, with coefficients, rate ratios and deviance.

Runs
On the server
Level
Checked against a reference: statsmodels 0.15.0 GLM, with Rodriguez's printed fit
Ask your assistant

What it is

Returns Poisson regression coefficients, SE, z, p, rate ratios and deviance for counts per exposure (log link, IRLS). Use when each row is a count, such as colonies or plaques, over a stated or equal exposure, against doses or other predictors. Not for events out of a known number tested (use `stats_binomial_regression`), a continuous response (use `relate_linear_regression`) or one table of counts (use `stats_contingency_table`). Replicates and each covariate's scale are required; rates are per the exposure's unit; dispersion is reported, never corrected. A measurement's unit is required, never assumed: any unit of the kit's table, returned in its canonical spelling; a unit group takes one unit, never converted.

Field: Statistics and design.

What it does

You give

  • offset (required): 'none' (equal exposure per row), 'exposure' (each row's exposure, with its unit; rates are per that unit) or 'log-offset' (a stated log offset per row). Required, no default.
  • response (required): Counts, one entry per row, with the exposure or log offset the offset mode names.
  • replicates (required): What one row is: 'independent' (independent biological replicates; opens z, p and the intervals), 'technical' (technical replicates) or 'unspecified'. Required: never inferred from the data.
  • level (required): Confidence level of the Wald intervals: 0.9, 0.95 or 0.99 (or 90, 95, 99 %). Must be above 0 and below 1.
  • covariates: At most 4 covariates. Optional.
  • factors: At most 3 factors, each with at most 12 levels. With the covariates, at most 20 coefficients: 1 + covariates + levels beyond each reference. Optional.

No request is recorded for this tool.

Limits

  • Research statistics and experimental-design arithmetic on the data, margins, prevalence and settings you supply.
  • Not for diagnosis or treatment decisions and not a regulatory analysis.
  • It does not choose a design, a margin, a cut-off or a sample size for you.
  • At most 500 rows, 4 covariates, 3 factors of up to 12 levels each, and 20 coefficients.
  • Data with no finite estimate are refused; a fit whose finiteness cannot be decided exactly, or that does not converge, returns an error, never a number.
  • Estimates are converged relative to their standard error, not to a fixed number of digits: near an infinite estimate, where a standard error is many times its estimate, the estimate and its rate ratio can differ from the exact maximum by orders of magnitude, so read such a fit as near-infinite, not as an effect size.
  • Standard errors assume dispersion 1, whatever the reported dispersion statistic.
  • Every computed number a reply returns, other than an integer or an exact decimal, is rounded once to 12 significant figures: to the nearest, a change of at most 5 × 10⁻¹² of its value, except that a lower bound is rounded down and an upper bound up, a change of less than 1 × 10⁻¹¹; the method computes, and decides any pass or fail, on the unrounded value.

It will not answer when

  • the design's columns are not linearly independent; columns are never dropped silently.
  • the condition test of equation condition refuses: the reciprocal condition is strictly below the threshold RECIPROCAL_CONDITION_THRESHOLD on the unweighted design before the fit or on the weighted design at the converged iterate, or the rank test fails on a weighted design at the start's iterate or any later one (Drybench ruling, 10 November 2026, J4; K4). Only the refusal at the converged iterate serves a number, its reciprocal condition as belowThresholdReciprocalCondition; the refusal before the fit and a failed rank test serve none.
  • some coefficient direction leaves every positive count's fit unchanged and lowers zero counts' means, so the MLE is infinite (Drybench ruling, 10 November 2026, K2 derivation), decided exactly before fitting.
  • two columns of one call differ in length (a method condition until the kit holds it; Drybench's J5).
Every input, with its units6 inputs
  • offset (required): 'none' (equal exposure per row), 'exposure' (each row's exposure, with its unit; rates are per that unit) or 'log-offset' (a stated log offset per row). Required, no default.
  • response (required): Counts, one entry per row, with the exposure or log offset the offset mode names.
  • replicates (required): What one row is: 'independent' (independent biological replicates; opens z, p and the intervals), 'technical' (technical replicates) or 'unspecified'. Required: never inferred from the data.
  • level (required): Confidence level of the Wald intervals: 0.9, 0.95 or 0.99 (or 90, 95, 99 %). Must be above 0 and below 1.
  • covariates: At most 4 covariates. Optional.
  • factors: At most 3 factors, each with at most 12 levels. With the covariates, at most 20 coefficients: 1 + covariates + levels beyond each reference. Optional.
Every refusal, with its code19 refusals
CodeWhen
RANK_DEFICIENTthe design's columns are not linearly independent; columns are never dropped silently.
DESIGN_ILL_CONDITIONEDthe condition test of equation condition refuses: the reciprocal condition is strictly below the threshold RECIPROCAL_CONDITION_THRESHOLD on the unweighted design before the fit or on the weighted design at the converged iterate, or the rank test fails on a weighted design at the start's iterate or any later one (Drybench ruling, 10 November 2026, J4; K4). Only the refusal at the converged iterate serves a number, its reciprocal condition as belowThresholdReciprocalCondition; the refusal before the fit and a failed rank test serve none.
MLE_NOT_FINITEsome coefficient direction leaves every positive count's fit unchanged and lowers zero counts' means, so the MLE is infinite (Drybench ruling, 10 November 2026, K2 derivation), decided exactly before fitting.
LENGTHS_DIFFERtwo columns of one call differ in length (a method condition until the kit holds it; Drybench's J5).
REFERENCE_NOT_A_LEVELa factor's reference is not one of its levels.
FACTOR_ONE_LEVELa factor with one level.
TOO_MANY_LEVELSa factor with more than 12 levels.
TOO_MANY_COEFFICIENTSmore than 20 coefficients.
TOO_FEW_ROWSno more rows than coefficients.
NONPOSITIVE_ON_LOGa log10 covariate with a value at or below 0.
NO_PREDICTORSno covariate and no factor.
OUT_OF_RANGElevel, taken in unit 1, at or below 0 or at or above 1 (100 % included); a count below 0 (the kit's bounds).
NOT_AN_INTEGERa count (events, trials or counts) that is not a whole number (the kit's count rule).
UNITS_DIFFERthe values of one covariate, or the exposures, in more than one unit (the kit's rule for a unit group).
DUPLICATE_NAMEtwo predictors (covariates and factors together) share a name.
INVALID_OPTIONlevel, taken in unit 1 (95 % is 0.95), is not within 1e-12 (absolute, exclusive) of 0.9, 0.95 or 0.99; a level within 1e-12 of one of them is taken as exactly that level, so one ulp from 0.95 is 0.95, and 0.95 + 2e-12 or 0.8 is refused.
NONPOSITIVE_EXPOSUREan exposure at or below 0.
CONFLICTING_ARGUMENTresponse.exposure and response.logOffset both given, or either given with an offset mode that does not take it.
MISSING_ARGUMENToffset 'exposure' without response.exposure, or 'log-offset' without response.logOffset.

The calculation

The method's equations, constants and worked example.

Poisson regression, log link, by Fisher scoring (IRLS), with an exposure or a log offsetstats-poisson-regression@2.0.1

Equation 1

L = Σ {y η − exp(η) − log y!}, μ = exp(η), η = Xβ + offset (offset = log exposure, the stated log offset, or 0)

deviance 2Σ{y log(y/μ) − (y − μ)}, a row with y = 0 contributing 2μ (0·log 0 = 0), each term computed as m·h(y/m) with h(r) = r ln r − r + 1 ≥ 0, which is y log(y/m) − (y − m): with d = (y − μ)/μ, m = μ, h is the series Σ_{k≥2} (−d)^k/(k(k − 1)), summed in double precision from k = 2 until a term no longer changes the sum, when |d| < 1/4, and y log(y/m) − (y − m) directly otherwise, a row with y = 0 giving m

so no term is negative

null deviance: the same with μ = exposure·Σy/Σexposure on every row, exposure = exp(offset) (the intercept-only fit, in closed form)

Pearson χ² X² = Σ (y − μ)²/μ

AIC=−2L+2p

dispersion statistic X²/(n − p), reported, never used to correct the SE

rate ratio exp(β)

the start is equation start

an exposure may be any positive normal double, the smallest included, and a log offset any finite double: one far from the other rows' (an exposure of 2.2250738585072014e-308 h beside 1 h) can leave the weights at β₀ spread so widely that the rank test of equation condition fails, and the call is refused DESIGN_ILL_CONDITIONED

SymbolMeaning
ycount (a count)
μthe row's fitted mean count
ηthe row's linear predictor
nrows
pcoefficients
Lthe log-likelihood
Ethe row's exposure, in the unit you state (offset = log E), as-given

Source 1.

Equation 2

X: a column of 1s (the intercept), then each covariate in the order given (its value, or log10 of it on 'log10'), then each factor's levels other than its reference, sorted by name (UTF-16 code units), each a 0/1 indicator of the row's level (treatment coding)

a covariate's coefficient is per its unit (per log10 unit on 'log10'), an indicator's is the difference from the reference

p = the number of columns. A linear covariate's coefficient is in 1/u, u the covariate's unit as given, wrapped in parentheses when u is compound (1/mg, 1/(µg/mL))

the reply's units table gives its UCUM code where the tool has a hand-written one, and otherwise { none } with the kit's reason: no code is derived at run time. Order of checks: the kit's argument checks (OUT_OF_RANGE, NOT_AN_INTEGER, UNITS_DIFFER and the kit's other codes)

then the response's own conditions (binomial LENGTHS_DIFFER for trials, then EVENTS_EXCEED_TRIALS

Poisson the offset arguments, MISSING_ARGUMENT, CONFLICTING_ARGUMENT, LENGTHS_DIFFER, NONPOSITIVE_EXPOSURE)

NO_PREDICTORS

the design's, DUPLICATE_NAME, then per covariate LENGTHS_DIFFER and NONPOSITIVE_ON_LOG, per factor LENGTHS_DIFFER, then per factor REFERENCE_NOT_A_LEVEL, FACTOR_ONE_LEVEL and TOO_MANY_LEVELS, then TOO_MANY_COEFFICIENTS and TOO_FEW_ROWS

then INVALID_OPTION for the level

each an invalid input, the first met answering. Then rank, the condition test before the fit, separation (or the Poisson no-finite-MLE test), and the fit

SymbolMeaning
Xthe design matrix, one row per data row
pcoefficients (columns of X)

Source 1.

Equation 3

SE = √diag (DᵀAD)⁻¹ at the fit

z = β̂/SE

p=2(1−Φ(|z|))

interval β̂ ± z₍₁₊ₗ₎/₂·SE

the ratio exp(β̂) with limits exp of the interval's

SymbolMeaning
β̂a coefficient's estimate (per its covariate's unit), as-given
z₍₁₊ₗ₎/₂the standard normal quantile Φ⁻¹((1 + l)/2), l the caller's level
Φthe standard normal distribution function

Source 1.

Equation 4

the likelihood equations Dᵀu = 0 with u = ∂L/∂η, D = X

Fisher scoring (DᵀAD)(β* − β) = Dᵀu with A = E[−∂²L/∂η∂ηᵀ], solved as the weighted least-squares regression of A⁻¹u + Dβ on D with weights A (IRLS)

asymptotic covariance (DᵀAD)⁻¹ with dispersion 1

SymbolMeaning
uscore per row
Aworking weight

Source 1.

Equation 5

The condition test, stated as computed. Applied to the unweighted design before the fit (W = I) and to the weighted design at the converged iterate (W = diag A at the β̂ where the stopping rule is met, A the working weight of equation score: binomial nμ(1 − μ) for the logit, nφ(η)²/(Φ(η)Φ(−η)) for the probit, Poisson μ). (1) M = √W·X, each row of X times the square root of its weight. (2) For each column j, c_j = ‖M_·j‖₂, the square root of the sum of the squared entries taken in row order in double precision

s_j = 2^(−round(log₂ c_j)), round to the nearest integer with a half rounded toward +∞, and s_j = 1 when c_j = 0

column j of M is multiplied by s_j (exact, a power of two). (3) R is the p × p upper-triangular factor of the QR factorisation of the scaled M (Householder reflections, no pivoting)

R is unique up to the signs of its rows, which change neither norm below. (4) R⁻¹ is formed explicitly by back-substitution in double precision

‖B‖₁ is the largest over columns of the sum of the absolute values of the column's entries

rcond = 1/(‖R‖₁·‖R⁻¹‖₁), computed so and never estimated. (5) The design is refused DESIGN_ILL_CONDITIONED when rcond < 1e-4, strictly

an rcond within rounding of 1e-4 may fall on either side. (6) The rank test: at the Householder step for column j, if the norm of the column's entries from row j down is at most 1e-7 times the norm of column j of the scaled M, the matrix has lost rank

before the fit that is RANK_DEFICIENT, and on a weighted design it is DESIGN_ILL_CONDITIONED. The rank test is applied to every weighted least-squares solve (the start's regression with the weights of μ₀, then the solve at each iterate from the start's β₀ on, the converged one included)

the rcond test of step (5) only before the fit and at the converged iterate. A weight that overflows to infinity fails the rank test. (7) What the refusal serves: at the converged iterate, the rcond of step (4) as belowThresholdReciprocalCondition (unit 1)

before the fit, and for a failed rank test, no number.

SymbolMeaning
Wthe diagonal matrix of row weights (the identity before the fit)
Mthe weighted design √W·X
c_jthe Euclidean norm of column j of M
s_jthe power of two that scales column j
Rthe triangular factor of the scaled M
rcondthe reciprocal 1-norm condition of R

Source 1.

Equation 6

ℓ is L of the method's likelihood equation, the full log-likelihood with Σ log C(n, y) (binomial) or −Σ log y! (Poisson), computed in double precision (log-gamma for the constants). Each iteration first checks the stopping rule: stop when the Newton decrement uᵀ(DᵀAD)⁻¹u ≤ 1e-20 (the squared norm of the step regression's fitted values) at the current β. Otherwise the step is tried at full length and then halved, at most 10 times, 11 trials in all

the first trial whose ℓ is finite and not below ℓ − 64·ε·|ℓ| (ℓ at the current β, ε = 2⁻⁵²) is accepted. If no trial is accepted, or 100 iterations pass without the stopping rule being met, the call is answered with the kit's NO_CONVERGENCE, an error with no number. Far-side underflow: a row observed on the far side (binomial y < n at η > 0, or y > 0 at η < 0

Poisson y > 0) whose tail quantity (logit μ(1 − μ)

probit Φ(−|η|) or φ(|η|)

Poisson μ) is below the smallest normal double, 2.2250738585072014e-308, makes ℓ count as not finite at that β, so a trial reaching it is never accepted. At the start, while ℓ at β₀ is not finite for this or any reason, β₀ is halved toward β = 0, at most 10 times

if ℓ is still not finite, NO_CONVERGENCE. A probit row whose Φ(−|η|) or φ(|η|) is 0 in double precision has weight 0 (Drybench ruling, 10 November 2026, rulings K3 and H4

J4

the level review, C1)

SymbolMeaning
decrementuᵀI⁻¹u

Source 1.

Equation 7

The start, the library's own and not Green's: μ₀ = (y + 0.5)/(n + 1) (binomial) or y + 0.1 (Poisson)

η₀ = logit μ₀, Φ⁻¹(μ₀) or log μ₀, less the offset

β₀ is the weighted least-squares regression of η₀ on X with weights A at μ₀ (equation score's working weights at η = η₀ + offset), through equation condition's column-scaled solve, whose rank test applies

SymbolMeaning
μ₀the row's starting mean (probability or count)
η₀the row's starting linear predictor less its offset
β₀the starting coefficients, as-given

Source 1.

Equation 8

Our derivation, published source not yet read (Drybench ruling, 10 November 2026, ruling K2): no finite MLE exactly when some d ≠ 0 has x′d = 0 on every positive-count row and x′d ≤ 0 on every zero-count row

decided by the feasibility of Konis' dual LP X̄ᵀλ = −X̄ᵀe, λ ≥ 0 (phase one, a floating simplex steering, an exact BigInt certificate or an exact simplex deciding), with X̄ holding each positive-count row as x and as −x and each zero-count row as −x

the offset does not enter

SymbolMeaning
da direction in coefficient space
xa row of the design X
X̄the signed rows, as defined in the text
λthe dual LP's multipliers
ea vector of 1s

Source 2.

Conventions

  • RECIPROCAL_CONDITION_THRESHOLD = 0.0001: Fixed by the method; not an argument. The threshold of the condition test (equation condition): a design whose reciprocal condition, computed as that equation states, is strictly below it before the fit or at the converged iterate is refused DESIGN_ILL_CONDITIONED.
  • offset = none: Equal exposure per row: η = Xβ.
  • offset = exposure: η = Xβ + log(exposure); exp(β) are rate ratios per the exposure's unit.
  • offset = log-offset: η = Xβ + the stated log offset.

A definition, not a model: the equation states what the quantity means. A different convention gives a different number.

Worked example

Worked example: one case of stats-poisson-regression@2.0.1, from its inputs through each step to the answer. Values are written as a person writes them; the working carries more digits, so your own figure may differ in the last digit shown.

Inputs

  • offset = exposure
  • response.counts[0] = 1
  • response.counts[1] = 3
  • response.counts[2] = 5
  • response.counts[3] = 7
  • response.countLabel = colonies
  • response.exposure[0] = 1 h
  • response.exposure[1] = 1 h
  • response.exposure[2] = 1.5 h
  • response.exposure[3] = 1.5 h
  • replicates = independent
  • level = 0.95
  • factors[0].name = group
  • factors[0].values[0] = A
  • factors[0].values[1] = A
  • factors[0].values[2] = B
  • factors[0].values[3] = B
  • factors[0].reference = A

Steps

  1. rate-ratio = 2, from response.counts, response.exposure; by equation 1; gives coefficients[1].rateRatio.estimate.
  2. estimate = 0.69314718, from rate-ratio; by equation 2; gives coefficients[1].estimate.
  3. se = 0.57735027, from response.counts; by equation 4; gives coefficients[1].se.
  4. z = 1.2005661, from estimate, se; by equation 3; gives coefficients[1].z.

The working, as the case writes it:

statsmodels' largest relative error against the 50-digit solve on beta and SE: 1.60e-16

the case tolerance is relative max(1e-9, 10 × that)

max fitted |eta| 1.79

effective relative bound under the absolute rules 1.0e-09 (at most 1e-7)

Answer

coefficients[1].rateRatio.estimate = 2

coefficients[1].estimate = 0.69314718

coefficients[1].se = 0.57735027

coefficients[1].z = 1.2005661

Where these values came from: an outside program, statsmodels GLM; SciPy; mpmath (tolerances) statsmodels 0.15.0; scipy 1.18.1; mpmath 1.4.1; statsmodels 0.15.0 GLM (Newton, tol 1e-15; SE from its expected information); z, p and limits from SciPy.

At build the tool returned this answer within the tolerance the file states: estimates, SE, z, limits, ratios and fit statistics relative max(1e-9, 10 × statsmodels' measured error against the 50-digit solve) per case (where units differ under one path, absolute: the larger of that size of the smallest magnitude and 100 × the measured error times the largest, an interval limit's magnitude being |estimate| + half-width; the log-likelihood absolute at that size of its magnitude); p that times (z_max² + 1) and the odds and rate ratios that times max(1, |ln ratio|), their sensitivities; no absolute rule looser than 1e-7 relative on any value it governs; Rodriguez's printed values at half a unit of their print; counts, df, names, codes and statuses exact.

Sources

  1. Green PJ. Iteratively reweighted least squares for maximum likelihood estimation, and some robust and resistant alternatives. J R Statist Soc B 1984;46(2):149-192

    Used for: Poisson regression, log link, by Fisher scoring (IRLS), with an exposure or a log offset. At: section §3.2 example (ii), Poisson with mean exp(η); the canonical link, observed = expected information; section §1.2: D = X, the design; the column order and treatment coding are the library's, stated; section §1.2, the asymptotic covariance (DᵀAD)⁻¹; the Wald z, p and interval are the library's standard large-sample forms, stated; section §1.2, eqs. (1)–(4) and the covariance σ²(DᵀAD)⁻¹; §3.3, u_i = π_i(y_i − mu_i)/(τ_i²δ_i), A_ii = π_i/(τ_i²δ_i²); section §1.2: the weighted least-squares regression (3) the test is applied to; the column scaling, the condition number, its threshold and the rank test are the library's own, stated (Drybench ruling, 10 November 2026, J4 and K4); section §1.2: iterate (3) until convergence; the stopping rule, cap, halving and underflow rule are the library's own, stated, not Green's (Drybench ruling, 10 November 2026, engine rulings); section §1.2: the iteration (3) the start feeds; the start itself is the library's own, stated, and no claim is made about what Green says of starting values (Drybench ruling, 10 November 2026, engine rulings).

    Read in full, 10 November 2026
  2. Konis K. Linear programming algorithms for detecting separated data in binary logistic regression models. DPhil thesis, University of Oxford, 2007

    Used for: Poisson regression, log link, by Fisher scoring (IRLS), with an exposure or a log offset. At: section §4.4.3 (the dual LP used for the test); the sign rule is the library's derivation from the Poisson log-likelihood, stated in Drybench's engine rulings, K2.

    Read in full, 10 November 2026

How it is checked

Level

Checked against a reference.

Checked against

Another program's fit of our model; an outside program, statsmodels GLM; SciPy; mpmath (tolerances), statsmodels 0.15.0; scipy 1.18.1; mpmath 1.4.1; a reference program this project wrote itself, second implementation (Python 3.13; NumPy, SciPy distribution functions and mpmath only), 2026-11-14, iteratively reweighted least squares in double precision, polished by Fisher scoring in mpmath 1.4.1 at 60 digits and rounded once; the condition test in double precision as the record states it; not an outside program.

Cases

No case set is linked to this version.

Not checked

An undecided separation is an internal invariant (an error, no number); non-convergence (NO_CONVERGENCE, equation stopping) is reached by valid inputs with log offsets several hundred below the others': the start's underflow rule by stored reference values#e2-start-underflow, and the halving rule by, for example, counts 5, 400, 5, 1517 at x = 3, 3, 2, 4 with log offsets 0, 0, 0, −729.2070388793945, which no fixture case holds, since only a double-precision replay of the engine decides it; quasi-likelihood SE and overdispersion correction; negative binomial; zero inflation; the Wald intervals' coverage; interactions; the log-likelihood and AIC at very large counts (lgamma differences, n ≳ 1e6).

Changes to its methods0 changes

No change is logged for these method versions.