pub struct OrdinalFit { /* private fields */ }Expand description
A fitted proportional-odds (ordinal logistic) model for an ordered
categorical response with K ≥ 2 levels 0 < 1 < … < K−1.
Uses the cumulative-logit parametrization of R’s MASS::polr:
logit P(yᵢ ≤ k) = αₖ − xᵢᵀβ, k = 0 … K−2,
with strictly increasing thresholds α₀ < α₁ < … < α_{K−2} and a single
coefficient vector β shared across all thresholds (the proportional-odds
assumption). Positive βⱼ raises the odds of falling in a higher category.
The design matrix carries no intercept — the thresholds play that role.
Fit by Newton–Raphson on the full (K−1) + p parameter vector (thresholds
then coefficients) with a backtracking line search. With K = 2 this reduces
exactly to binary LogisticFit: β equals
the logistic slopes and α₀ equals the negated logistic intercept.
Implementations§
Source§impl OrdinalFit
impl OrdinalFit
Sourcepub fn new(x: Array2<f64>, y: Array1<f64>) -> Result<Self>
pub fn new(x: Array2<f64>, y: Array1<f64>) -> Result<Self>
Fit a proportional-odds model of ordered y on X (default: up to 100
Newton iterations, tolerance 1e-10).
The response holds integer levels 0 … K−1, every level present; K is
inferred as max(y) + 1. Do not include an intercept column in X.
§Errors
RegressionError::EmptyInput/RegressionError::ShapeMismatch.RegressionError::InvalidResponsefor non-integer/negative labels, a missing level, or fewer than two levels.RegressionError::RankDeficientif the information matrix is singular.RegressionError::NotConvergedif Newton’s method fails to converge.
Sourcepub fn with_options(
x: Array2<f64>,
y: Array1<f64>,
max_iter: usize,
tol: f64,
) -> Result<Self>
pub fn with_options( x: Array2<f64>, y: Array1<f64>, max_iter: usize, tol: f64, ) -> Result<Self>
Like OrdinalFit::new with an explicit iteration cap and tolerance.
Sourcepub fn n_observations(&self) -> usize
pub fn n_observations(&self) -> usize
Number of observations.
Sourcepub fn n_features(&self) -> usize
pub fn n_features(&self) -> usize
Number of design columns p.
Sourcepub fn n_parameters(&self) -> usize
pub fn n_parameters(&self) -> usize
Total number of parameters, (K − 1) + p (thresholds plus coefficients).
Sourcepub fn iterations(&self) -> usize
pub fn iterations(&self) -> usize
Newton iterations taken to converge.
Sourcepub fn design_matrix(&self) -> ArrayView2<'_, f64>
pub fn design_matrix(&self) -> ArrayView2<'_, f64>
The design matrix as fitted.
Sourcepub fn response(&self) -> ArrayView1<'_, f64>
pub fn response(&self) -> ArrayView1<'_, f64>
The integer level labels.
Sourcepub fn thresholds(&self) -> ArrayView1<'_, f64>
pub fn thresholds(&self) -> ArrayView1<'_, f64>
Threshold (cutpoint) parameters α₀ < … < α_{K−2}.
Sourcepub fn coefficients(&self) -> ArrayView1<'_, f64>
pub fn coefficients(&self) -> ArrayView1<'_, f64>
Shared coefficient vector β (proportional-odds effects).
Sourcepub fn fitted_probabilities(&self) -> ArrayView2<'_, f64>
pub fn fitted_probabilities(&self) -> ArrayView2<'_, f64>
Fitted class probabilities, shape n × K.
Sourcepub fn covariance(&self) -> ArrayView2<'_, f64>
pub fn covariance(&self) -> ArrayView2<'_, f64>
Covariance of the stacked (K−1)+p parameter vector (thresholds first).
Sourcepub fn log_likelihood(&self) -> f64
pub fn log_likelihood(&self) -> f64
Maximized log-likelihood.
Sourcepub fn coefficient_standard_errors(&self) -> Array1<f64>
pub fn coefficient_standard_errors(&self) -> Array1<f64>
Standard errors of the coefficients β (the last p diagonal entries of
the covariance).
Sourcepub fn threshold_standard_errors(&self) -> Array1<f64>
pub fn threshold_standard_errors(&self) -> Array1<f64>
Standard errors of the thresholds α.
Sourcepub fn p_values(&self) -> Array1<f64>
pub fn p_values(&self) -> Array1<f64>
Two-sided Wald p-values for the coefficients from the standard normal.
Sourcepub fn residual_deviance(&self) -> f64
pub fn residual_deviance(&self) -> f64
Residual deviance −2ℓ.
Sourcepub fn null_deviance(&self) -> f64
pub fn null_deviance(&self) -> f64
Deviance of the intercept-only (threshold-only, β = 0) model.
Sourcepub fn mcfadden_r2(&self) -> f64
pub fn mcfadden_r2(&self) -> f64
McFadden’s pseudo-R², 1 − ℓ/ℓ₀.
Sourcepub fn predict_proba(&self, x: ArrayView2<'_, f64>) -> Array2<f64>
pub fn predict_proba(&self, x: ArrayView2<'_, f64>) -> Array2<f64>
Predicted class probabilities for a new design matrix x, shape
rows × K.
Trait Implementations§
Source§impl Clone for OrdinalFit
impl Clone for OrdinalFit
Source§fn clone(&self) -> OrdinalFit
fn clone(&self) -> OrdinalFit
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for OrdinalFit
impl RefUnwindSafe for OrdinalFit
impl Send for OrdinalFit
impl Sync for OrdinalFit
impl Unpin for OrdinalFit
impl UnsafeUnpin for OrdinalFit
impl UnwindSafe for OrdinalFit
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.