Unbiased covariances are given by the formula cov(X, Y) = sum [(xi - E(X))(yi - E(Y))] / (n - 1),
where E(X)
is the mean of X
and E(Y)
is the mean of the Y
values. Non-bias-corrected estimates use n
in place of n - 1
. To determine if the covariance is bias corrected or not, we need to set an additional, optional parameter called biasCorrected
which is set to true by default.
Create a method that takes two one-dimensional double arrays. Each array represents a set of data points:
public void calculateCov(double[] x, double[] y){
Calculate the covariance of the two sets of data points as follows:
double covariance = new Covariance().covariance(x, y, false);