Overview
Purpose
Compute the variance of x, supporting both the unweighted and weighted cases.
Parameters
x: numeric data.w: optional weights.ddof: correction applied to the denominator. In the unweighted case the denominator islen(x) - ddof; in the weighted case it issum(w) - ddof.
Returns
A float with the variance.
Errors and exceptions
ValueErrorifxis empty or not finite.ValueErrorifwis invalid.ValueErrorif the denominator becomes less than or equal to zero.
Example
from mespy import variance
x = [2.0, 4.0, 4.0, 4.0, 5.0, 5.0, 7.0, 9.0]
print(variance(x)) # 4.0
print(variance(x, ddof=1)) # correzione di Bessel
Notes
The default
ddof=0is consistent with the descriptive convention used throughout the package.The weighted version uses the internal weighted mean, not
numpy.var.