Skip to main content

predict_fregre_robust

Function predict_fregre_robust 

Source
pub fn predict_fregre_robust(
    fit: &FregreRobustResult,
    new_data: &FdMatrix,
    new_scalar: Option<&FdMatrix>,
) -> Vec<f64>
Expand description

Predict new responses using a fitted robust functional regression model.

Projects new_data onto the FPCA basis stored in fit, then applies the estimated coefficients.

§Arguments

  • fit - A fitted FregreRobustResult
  • new_data - New functional predictor matrix (n_new × m)
  • new_scalar - Optional new scalar covariates (n_new × p)

§Examples

use fdars_core::matrix::FdMatrix;
use fdars_core::scalar_on_function::{fregre_l1, predict_fregre_robust};

let (n, m) = (20, 30);
let data = FdMatrix::from_column_major(
    (0..n * m).map(|k| {
        let i = (k % n) as f64;
        let j = (k / n) as f64;
        ((i + 1.0) * j * 0.2).sin()
    }).collect(),
    n, m,
).unwrap();
let y: Vec<f64> = (0..n).map(|i| (i as f64 * 0.5).sin()).collect();
let fit = fregre_l1(&data, &y, None, 3).unwrap();
let preds = predict_fregre_robust(&fit, &data, None);
assert_eq!(preds.len(), 20);