# 协方差（Covariance，covariance）

两个等长列表的样本协方差。

## 怎么写

### covariance(xs, ys)

各元素与其均值之差的乘积之和，除以 n - 1。

**xs**

第一个列表。接受一个列表。

**ys**

第二个列表，与第一个等长。接受一个列表。

## 示例

- $\displaystyle \operatorname{covariance}(\left[ 1, 2, 3, 4 \right], \left[ 2, 4, 5, 9 \right]) = \frac{11}{3}$

  `covariance([1, 2, 3, 4], [2, 4, 5, 9])`

  在求解器中，`covariance([1, 2, 3, 4], [2, 4, 5, 9])` 的结果是 `11/3`。

  [在求解器中打开](https://zh.hilberon.com/?q=covariance%28%5B1%2C%202%2C%203%2C%204%5D%2C%20%5B2%2C%204%2C%205%2C%209%5D%29)

## 相关函数

- [cvar](https://zh.hilberon.com/library/cvar)

  损失的条件风险价值：其在最差的占比 1 - level 上的期望值。
- [correlation](https://zh.hilberon.com/library/correlation)

  两个等长列表的相关系数。
- [distributed](https://zh.hilberon.com/library/distributed)

  变量及其所服从的分布，供概率和期望读取。
- [cdf](https://zh.hilberon.com/library/cdf)

  服从某个分布的变量取值至多为某个值的概率。
- [expectation](https://zh.hilberon.com/library/expectation)

  某变量的表达式在给定分布或过程下的期望值。
- [binomial_distribution](https://zh.hilberon.com/library/binomial_distribution)

  n 次独立试验中成功的次数，每次试验成功的概率为 p。

---
Source: https://zh.hilberon.com/library/covariance
