pub fn kde(samples: &[f64], grid_points: &[f64]) -> Result<Vec<f64>, Error>Expand description
Kernel density estimate using a Gaussian kernel and Scott’s rule bandwidth.
kde(samples, grid_points) evaluates the KDE at each
point in grid_points and returns the density values
(one per grid point). The bandwidth is computed from
samples via Scott’s rule (h = n^(-1/5) * std(samples));
all grid points share the same bandwidth.
§Errors
Returns Error::Data if samples, grid points, or the derived
bandwidth cannot produce finite density values.
§Examples
use lichtung_plot::stats::distribution::kde;
let samples = vec![0.0, 1.0, 2.0, 3.0, 4.0];
let grid = vec![0.0, 1.0, 2.0, 3.0, 4.0];
let densities = kde(&samples, &grid).unwrap();
// The density is highest at the center (2.0) and
// falls off symmetrically.
assert!(densities[2] > densities[0]);
assert!(densities[2] > densities[4]);