Skip to main content

functional_logistic

Function functional_logistic 

Source
pub fn functional_logistic(
    data: &FdMatrix,
    y: &[f64],
    scalar_covariates: Option<&FdMatrix>,
    ncomp: usize,
    max_iter: usize,
    tol: f64,
) -> Result<FunctionalLogisticResult, FdarError>
Expand description

Functional logistic regression for binary outcomes.

Fits: log(P(Y=1)/P(Y=0)) = α + ∫β(t)X(t)dt + γᵀz using IRLS (iteratively reweighted least squares) on FPC scores.

§Arguments

  • data - Functional predictor matrix (n × m)
  • y - Binary response vector (0.0 or 1.0, length n)
  • scalar_covariates - Optional scalar covariates (n × p)
  • ncomp - Number of FPC components
  • max_iter - Maximum IRLS iterations (default: 25)
  • tol - Convergence tolerance (default: 1e-6)

§Errors

Returns FdarError::InvalidDimension if data has fewer than 3 rows, zero columns, or y.len() != n. Returns FdarError::InvalidParameter if any element of y is not 0.0 or 1.0. Returns FdarError::ComputationFailed if the SVD inside FPCA fails to extract components.

§Examples

use fdars_core::matrix::FdMatrix;
use fdars_core::scalar_on_function::functional_logistic;

let data = FdMatrix::from_column_major(
    (0..200).map(|i| (i as f64 * 0.1).sin()).collect(),
    10, 20,
).unwrap();
let y = vec![0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0];
let fit = functional_logistic(&data, &y, None, 3, 25, 1e-6).unwrap();
assert_eq!(fit.probabilities.len(), 10);
assert!(fit.probabilities.iter().all(|&p| p >= 0.0 && p <= 1.0));