pecon.stats.cov#

pecon.stats.cov(x, y, ddof=1)#

Compute the covariance between two variables.

Covariance measures the direction of the linear relationship between two variables. A positive value indicates that the variables tend to move together, while a negative value indicates an inverse relationship.

Parameters:
  • x (array-like) – One-dimensional sequences of numerical values with equal length.

  • y (array-like) – One-dimensional sequences of numerical values with equal length.

  • ddof (int, optional) – Delta degrees of freedom. Default is 1 for sample covariance.

Returns:

The covariance between x and y.

Return type:

float

Notes

The value of ddof must satisfy 0 <= ddof < N, where N is the number of observations. Otherwise, a ValueError is raised.

Examples

>>> from pecon import stats
>>> x = [2, 4, 6, 8, 10, 17, 24]
>>> y = [1, 6, 12, 30, 17, 55, 40]
>>> cov = stats.cov(x, y, ddof=1)
>>> print(f"covariance = {cov}")
covariance = 128.33333333333337