Mwnci Covariance() Function

Syntax

covariance(array, array, string)

Description

TheĀ covariance() method calculates and returns the covariance of two data sets. The optional 3rd argument is a single character “s“, “p” to give the sample, or population covariance.

If the covariance type is not given as the 3rd argument, then the result defaults to sample

In the term of statistics and mathematics, covariance definition elaborates as the measurement of the relationship between two random variables (X, Y). In simple words, covariance is said to be a measure of how much two random variables can vary together.

Covariance can be positive or negative. Positive covariance means the two data sets are likely to move in the same way. While a negative covariance indicates that as one data set rises, the other tends to fall.

Example

include("stats")
a=[1, 2, 3]
b=[10, 20, 27]
println(covariance(a,b,"s"))
println(covariance(a,b))
println(covariance(a,b,"p"))

8.5
8.5
5.666666666666667