cov
Builtin index · Statistics & ML
result = cov(x, y)
Input: x, y · Output: result
What it is
Sample covariance between two length-N numeric vectors x and y, N-1 denominator โ the same convention var and std use.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = cov(x, y) | x vectornot documented yet
y vectornot documented yet
| result number
| Returns a single number. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
a = randn(200, seed = 11)
b = 0.8 * a + 0.6 * randn(200, seed = 12)
print("corr(a, b): {round(corr(a, b), 3)}")
print("cov(a, b): {round(cov(a, b), 3)}")
scatter(a, b, color = "#4169e1", alpha = 0.6)
title("corr = {round(corr(a, b), 3)}, cov = {round(cov(a, b), 3)}")
xlabel("a")
ylabel("b")
outputcorr(a, b): 0.691
cov(a, b): 0.515
ยท scatter: figure 1 (200 points)
from statistics-ml
How it works
cov(x, y) โ sample covariance (N-1, same convention as var/std; corr(x, y) == cov(x, y) / (std(x) * std(y))).
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.