arrCovariance method

num? arrCovariance(
  1. List<num> num1,
  2. List<num> num2
)

The sample mean and sample covariance are estimators of the population mean and population covariance, where the term population refers to the set from which the sample was taken.

In probability theory and statistics, the binomial distribution with parameters n and p is the discrete probability distribution of the number of successes in a sequence of n independent experiments, each asking a yes–no question, and each with its own boolean-valued outcome: success/yes/true/one (with probability p) or failure/no/false/zero (with probability q = 1 − p). A single success/failure experiment is also called a Bernoulli trial or Bernoulli experiment and a sequence of outcomes is called a Bernoulli process; for a single trial, i.e., n = 1, the binomial distribution is a Bernoulli distribution. The binomial distribution is the basis for the popular binomial test of statistical significance.

Example

print(Statistical().arrCovariance([65.21, 64.75, 65.26, 65.76, 65.96] ,[67.25, 66.39, 66.12, 65.70, 66.64]));
//output -0.0580

Implementation

num? arrCovariance(List<num> num1, List<num> num2) {
  if (num1.length != num2.length) return null;
  var sum = 0.0;
  for (var i = 0; i < num2.length; i++) {
    sum += ((num1[i] - arrMean(num1)) * (num2[i] - arrMean(num2)));
  }
  return sum / (num1.length - 1);
}