mixle.inference.ordinal module

Ordinal regression and rank-correlation (concordance) measures.

When the response is ordered categories (none < mild < severe; 1–5 stars) the spacing between levels is unknown, so neither plain regression (assumes equal spacing) nor multinomial logit (throws away the order) is right. The cumulative (proportional-odds / proportional-hazards) model is:

P(Y <= k | x) = F(alpha_k - x’ beta), alpha_1 < … < alpha_{K-1},

a single coefficient vector beta with K-1 ordered thresholds. ordinal_regression() fits this by maximum likelihood with F the logistic (ordered logit / proportional odds) or normal (ordered probit) CDF.

The concordance measures summarise the monotone association between two ordinal variables from the counts of concordant/discordant pairs: kendall_tau() (tau-b, tie-corrected), goodman_kruskal_gamma(), and somers_d() (asymmetric). concordance_summary() returns all of them with the underlying pair counts.

class OrdinalResult(coef, thresholds, se, log_likelihood, link, n_categories)[source]

Bases: object

Fitted ordinal (cumulative-link) regression.

Parameters:
coef

(p,) slope coefficients (positive beta_j raises the latent score, shifting mass toward higher categories).

Type:

numpy.ndarray

thresholds

(K-1,) ordered cut points alpha.

Type:

numpy.ndarray

se

(p,) standard errors for coef.

Type:

numpy.ndarray

log_likelihood

maximised log-likelihood.

Type:

float

link

"logit" or "probit".

Type:

str

n_categories

number of ordered categories K.

Type:

int

coef: ndarray
thresholds: ndarray
se: ndarray
log_likelihood: float
link: str
n_categories: int
predict_proba(x)[source]

Per-category probabilities (n, K) at design rows x.

Parameters:

x (ndarray)

Return type:

ndarray

predict(x)[source]

Most-probable ordered category per row.

Parameters:

x (ndarray)

Return type:

ndarray

ordinal_regression(x, y, *, link='logit', max_iter=200)[source]

Fit a cumulative-link ordinal regression (ordered logit / probit) by maximum likelihood.

Parameters:
  • x (ndarray) – (n, p) covariates (no intercept – the thresholds play that role).

  • y (ndarray) – (n,) integer category labels 0..K-1 (ordered).

  • link (str) – "logit" (proportional odds) or "probit".

  • max_iter (int) – optimiser iterations.

Returns:

An OrdinalResult.

Return type:

OrdinalResult

concordance_summary(x, y)[source]

All pairwise concordance measures between two ordinal variables.

Returns:

{'kendall_tau_b', 'gamma', 'somers_d_yx', 'somers_d_xy', 'concordant', 'discordant', 'tx', 'ty', 'txy'}tx = pairs tied on x only, ty on y only, txy on both.

Parameters:
Return type:

dict[str, float]

kendall_tau(x, y)[source]

Kendall’s tau-b rank correlation (tie-corrected) between two ordinal variables.

Parameters:
Return type:

float

goodman_kruskal_gamma(x, y)[source]

Goodman–Kruskal gamma: (C - D) / (C + D) ignoring ties.

Parameters:
Return type:

float

somers_d(x, y, *, dependent='y')[source]

Somers’ D, the asymmetric rank association treating dependent as the response.

Parameters:
Return type:

float