Skip to main content

functional_pdp

Function functional_pdp 

Source
pub fn functional_pdp(
    fit: &FregreLmResult,
    data: &FdMatrix,
    _scalar_covariates: Option<&FdMatrix>,
    component: usize,
    n_grid: usize,
) -> Result<FunctionalPdpResult, FdarError>
Expand description

Functional PDP/ICE for a linear functional regression model.

Varies the FPC score for component across a grid while keeping other scores fixed, producing ICE curves and their average (PDP).

For a linear model, ICE curves are parallel lines (same slope, different intercepts).

§Arguments

  • fit – A fitted FregreLmResult
  • data – Original functional predictor matrix (n x m)
  • scalar_covariates – Optional scalar covariates (n x p)
  • component – Which FPC component to vary (0-indexed, must be < fit.ncomp)
  • n_grid – Number of grid points (must be >= 2)

§Errors

Returns FdarError::InvalidDimension if data has zero rows, its column count does not match fit.fpca.mean, or its row count does not match fit.fitted_values. Returns FdarError::InvalidParameter if component >= fit.ncomp or n_grid < 2.

§Examples

use fdars_core::matrix::FdMatrix;
use fdars_core::scalar_on_function::fregre_lm;
use fdars_core::explain::functional_pdp;

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_lm(&data, &y, None, 3).unwrap();
let pdp = functional_pdp(&fit, &data, None, 0, 10).unwrap();
assert_eq!(pdp.pdp_curve.len(), 10);
assert_eq!(pdp.ice_curves.shape(), (20, 10));