# Logistic or probit regression of events out of trials

`stats_binomial_regression` · Runs: On the server · Level: Checked against a reference: statsmodels 0.15.0 GLM, with Rodriguez's printed fit

Fits a logistic or probit regression to events out of trials, with coefficients, SE, z, p and deviance.

Research and education software; not medical advice, and not for diagnosis or treatment decisions. It computes from the inputs it receives. It does not check the person's data, design or sample.

[Catalogue](https://www.drybench.com/mcp/catalogue) / [Statistics](https://www.drybench.com/mcp/catalogue/statistics)

[Ask your assistant](https://www.drybench.com/mcp/connect)

```cite
Logistic or probit regression of events out of trials (stats_binomial_regression), Drybench MCP server 1.0.0; stats-binomial-regression@2.0.1 (Checked against a reference); https://www.drybench.com/mcp/tools/stats-binomial-regression
```

## What it is

Returns logistic or probit regression coefficients, SE, z, p and deviance for events out of trials (binomial, IRLS). Use when each row is a count of events, such as responders, out of a known number tested, against doses or other predictors. Not for a continuous response (use \`dose\_response\_4pl\` or use \`relate\_linear\_regression\`), one table of counts (use \`stats\_contingency\_table\`) or counts over an exposure (use \`stats\_poisson\_regression\`). Link, replicates and each covariate's scale are required with no default; separated data are refused (SEPARATION) and no LD50 is returned. 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](https://www.drybench.com/mcp/catalogue/statistics).

## What it does

**You give**

- `link` (required): 'logit' (logistic regression) or 'probit'. Required, no default.
- `response` (required): Events out of trials, one entry per row.
- `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.
- Separated data are refused; a fit whose separation 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 separation, where a standard error is many times its estimate, the estimate (and, for the logit, its odds ratio) can differ from the exact maximum by orders of magnitude, so read such a fit as near-separated, not as an effect size.
- Standard errors assume dispersion 1; no LD50 is given.
- 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.
- the events and non-events are separated by the predictors (complete or quasicomplete), 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 units

6 inputs

- `link` (required): 'logit' (logistic regression) or 'probit'. Required, no default.
- `response` (required): Events out of trials, one entry per row.
- `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 code

17 refusals

| Code | When |
| --- | --- |
| `RANK_DEFICIENT` | the design's columns are not linearly independent; columns are never dropped silently. |
| `DESIGN_ILL_CONDITIONED` | 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. |
| `SEPARATION` | the events and non-events are separated by the predictors (complete or quasicomplete), decided exactly before fitting. |
| `LENGTHS_DIFFER` | two columns of one call differ in length (a method condition until the kit holds it; Drybench's J5). |
| `REFERENCE_NOT_A_LEVEL` | a factor's reference is not one of its levels. |
| `FACTOR_ONE_LEVEL` | a factor with one level. |
| `TOO_MANY_LEVELS` | a factor with more than 12 levels. |
| `TOO_MANY_COEFFICIENTS` | more than 20 coefficients. |
| `TOO_FEW_ROWS` | no more rows than coefficients. |
| `NONPOSITIVE_ON_LOG` | a log10 covariate with a value at or below 0. |
| `NO_PREDICTORS` | no covariate and no factor. |
| `OUT_OF_RANGE` | level, 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_INTEGER` | a count (events, trials or counts) that is not a whole number (the kit's count rule). |
| `UNITS_DIFFER` | the values of one covariate, or the exposures, in more than one unit (the kit's rule for a unit group). |
| `DUPLICATE_NAME` | two predictors (covariates and factors together) share a name. |
| `INVALID_OPTION` | level, 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. |
| `EVENTS_EXCEED_TRIALS` | a row with more events than trials. |

## The calculation

The method's equations, constants and worked example.

### [Binomial regression, logit or probit link, by Fisher scoring (IRLS)](https://www.drybench.com/methods/m/stats-binomial-regression/2.0.1)

`stats-binomial-regression@2.0.1`

**Equation 1**

```text
L = Σ {y log μ + (n − y) log(1 − μ)} + Σ log C(n, y)
logit: logit μ = η, i.e. μ = 1/(1 + exp(−η))
probit: μ = Φ(η)
η = Xβ
deviance 2Σ{y log(y/(nμ)) + (n − y) log((n − y)/(n(1 − μ)))} = 2Σ{T(y, nμ) + T(n − y, n(1 − μ))} with T(y, m) = y log(y/m) − (y − m) (the linear parts cancel), y − nμ formed as (y − n) + n(1 − μ) when μ > ½ and the failures' difference its negative, 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)/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 μ = Σy/Σn on every row (the intercept-only fit, in closed form)
Pearson χ² = Σ (y − nμ)²/(nμ(1 − μ)), a row with nμ(1 − μ) = 0 contributing 0
AIC = −2L + 2p
odds ratio exp(β) (logit only)
the start is equation start
```

| Symbol | Meaning |
| --- | --- |
| `y` | events (a count) |
| `n` | trials (a count) |
| `μ` | the row's fitted probability of an event per trial |
| `η` | the row's linear predictor |
| `p` | coefficients |
| `L` | the log-likelihood |

Source 1.

**Equation 2**

```text
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
```

| Symbol | Meaning |
| --- | --- |
| `X` | the design matrix, one row per data row |
| `p` | coefficients (columns of X) |

Source 1.

**Equation 3**

```text
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
```

| Symbol | Meaning |
| --- | --- |
| `β̂` | 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**

```text
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
```

| Symbol | Meaning |
| --- | --- |
| `u` | score per row |
| `A` | working weight |

Source 1.

**Equation 5**

```text
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.
```

| Symbol | Meaning |
| --- | --- |
| `W` | the diagonal matrix of row weights (the identity before the fit) |
| `M` | the weighted design √W·X |
| `c_j` | the Euclidean norm of column j of M |
| `s_j` | the power of two that scales column j |
| `R` | the triangular factor of the scaled M |
| `rcond` | the reciprocal 1-norm condition of R |

Source 1.

**Equation 6**

```text
ℓ 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)
```

| Symbol | Meaning |
| --- | --- |
| `decrement` | uᵀI⁻¹u |

Source 1.

**Equation 7**

```text
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
```

| Symbol | Meaning |
| --- | --- |
| `μ₀` | 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**

```text
no finite MLE exists when some β ≠ 0 has X̄β ≥ 0 (complete or quasicomplete separation)
decided by the feasibility of the dual LP X̄ᵀλ = −X̄ᵀe, λ ≥ 0, through its phase one, a floating simplex steering and an exact BigInt certificate (λ, or a Farkas β = Mπ from the phase-one dual) or an exact simplex deciding. Our derivations, labelled: a grouped row with 0 < y < n carries both signs
β recovered from the phase-one dual (Konis §4.4.4 uses a bounded LP instead)
```

| Symbol | Meaning |
| --- | --- |
| `X̄` | rows signed by outcome |

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.
- link = logit: Logistic regression: logit π = η; exp(β) are odds ratios.
- link = probit: Probit regression: Φ⁻¹(π) = η; no odds ratios.

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-binomial-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**

- link = logit
- response.events\[0\] = 1
- response.events\[1\] = 2
- response.events\[2\] = 4
- response.events\[3\] = 4
- response.trials\[0\] = 5
- response.trials\[1\] = 5
- response.trials\[2\] = 5
- response.trials\[3\] = 5
- response.eventLabel = dead
- 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. log-odds-a = -0.84729786, from response.events, response.trials; by equation 1.
2. log-odds-b = 1.3862944, from response.events, response.trials; by equation 1.
3. estimate = 2.2335922, from log-odds-b, log-odds-a; by equation 2; gives coefficients\[1\].estimate.
4. se = 1.0493762, from response.events, response.trials; by equation 4; gives coefficients\[1\].se.
5. z = 2.1284952, from estimate, se; by equation 3; gives coefficients\[1\].z.
6. odds-ratio = 9.3333333, from estimate; by equation 1; gives coefficients\[1\].oddsRatio.estimate.

The working, as the case writes it:

```text
statsmodels' largest relative error against the 50-digit solve on beta and SE: 1.99e-16
the case tolerance is relative max(1e-9, 10 × that)
max fitted |eta| 1.39
effective relative bound under the absolute rules 1.0e-09 (at most 1e-7)
```

**Answer**

- coefficients\[1\].estimate = 2.2335922
- coefficients\[1\].se = 1.0493762
- coefficients\[1\].z = 2.1284952
- coefficients\[1\].oddsRatio.estimate = 9.3333333

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.

Who worked this case: not recorded.

## 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: Binomial regression, logit or probit link, by Fisher scoring (IRLS). At: section §1.1 (the binomial log-likelihood and the logit regression function); §3.2 examples (iii) logit and (v) probit, Φ(η); 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: Binomial regression, logit or probit link, by Fisher scoring (IRLS). At: section §1.3 (definitions after Albert and Anderson 1984 with Santner and Duffy's correction; theorems 1 and 2; Silvapulle 1981's theorem as stated in Konis, covering links with −log G convex); §4.2 (4.4)–(4.6); §4.4.3 (4.19), (4.20), Bland's rule; §4.5 (numerics). **Read in full, 10 November 2026**

Read by AI-assisted sessions. No person has checked these readings.

## 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 (300 exact pivots) is an internal invariant that returns an error and no number: no input within the caps was found to reach it; non-convergence (NO\_CONVERGENCE, equation stopping) returns an error and no number, and no binomial input within the caps was found to reach it; the step-halving and far-side underflow rules of equation stopping are exercised by no binomial fixture case through the tool (the engine's unit test reaches the underflow rule with an offset the tool does not take); LD50/ED50 and their intervals (Fieller, Finney not read); profile-likelihood intervals; quasi-likelihood SE and overdispersion; the Wald intervals' coverage; offsets; interactions; Nelder and Wedderburn 1972, Albert and Anderson 1984 and Silvapulle 1981 not read (the last two as stated in Konis).

No independent scientist has yet reviewed this.

### Changes to its methods

1 change

- [21 November 2026, stats-binomial-regression\@2.0.1](https://www.drybench.com/methods/corrections#2026-11-21-stats-binomial-regression201-1): In 2.0.1 the normal tail is the 0 it rounds to wherever the incomplete gamma's leading factor rounds to 0 (the fraction, at most 1/(x−a+1) for a ≥ 1 (8.2.2), at most 1/x for a ≤ 1 (8.10.1); below 1 in both, is not run), so those steps are evaluated and the fit takes the path the limit gives. Every value the function returned as a number is unchanged in every bit, and every case of the method's fixtures keeps its output hash.
