pub fn local_linear(
x: &[f64],
y: &[f64],
x_new: &[f64],
bandwidth: f64,
kernel: &str,
) -> Result<Vec<f64>, FdarError>Expand description
Local linear regression smoother.
§Arguments
x- Predictor valuesy- Response valuesx_new- Points at which to evaluate the smootherbandwidth- Kernel bandwidthkernel- Kernel type
§Returns
Smoothed values at x_new
§Errors
Returns FdarError::InvalidDimension if x is empty, x_new is empty,
or x and y have different lengths.
Returns FdarError::InvalidParameter if bandwidth is not positive.
§Examples
use fdars_core::smoothing::local_linear;
let x: Vec<f64> = (0..30).map(|i| i as f64 / 29.0).collect();
let y: Vec<f64> = x.iter().map(|&xi| 2.0 * xi + 1.0).collect();
let smoothed = local_linear(&x, &y, &x, 0.2, "gaussian").unwrap();
assert_eq!(smoothed.len(), 30);
// Local linear should fit linear data well in the interior
assert!((smoothed[15] - (2.0 * x[15] + 1.0)).abs() < 0.1);