Overview
Purpose
Compute the covariance between two variables, with optional support for weights.
Parameters
x: first variable.y: second variable.w: optional weights compatible withxandy.
Returns
A float with the covariance between x and y.
Errors and exceptions
ValueErrorifxandydo not have the same length.ValueErrorif the inputs contain non-finite values.ValueErrorifwis incompatible or not positive.
Example
from mespy import covariance
x = [1.0, 2.0, 3.0]
y = [2.0, 4.0, 6.0]
print(covariance(x, y))
Notes
The implemented formula is E[xy] - E[x]E[y]. In the weighted case, the means are weighted with the same w vector.