Skip to main content

autocorrelation

Function autocorrelation 

Source
pub fn autocorrelation(values: &[f64], lag: usize) -> Option<f64>
Expand description

Sample autocorrelation at lag, using the standard biased estimator (normalised by the total sum of squares, mean-centred):

r_k = Σ_{t=k}^{n-1} (x_t − x̄)(x_{t−k} − x̄)  /  Σ_{t=0}^{n-1} (x_t − x̄)²

r_0 is always 1.0 for non-constant data. Returns None if the slice is empty, lag >= n, or the series is constant (zero variance → undefined).