pastas.stats.core.var#

var(x, weighted=True, max_gap=30)[source]#

Method to compute the (weighted) variance of a time series.

Parameters
  • x (pandas.Series) – Series with the values and a DatetimeIndex as an index.

  • weighted (bool, optional) – Weight the values by the normalized time step to account for irregular time series. Default is True.

  • max_gap (int, optional) – maximum allowed gap period in days to use for the computation of the weights. All time steps larger than max_gap are replace with the mean weight. Default value is 90 days.

Return type

ArrayLike

Notes

The (weighted) variance for a time series x is computed as:

\[\sigma_x^2 = \sum_{i=1}^{N} w_i (x_i - \bar{x})^2\]

where \(w_i\) are the weights, taken as the time step between observations, normalized by the sum of all time steps. Note how weighted mean (\(\bar{ x}\)) is used in this formula.