CovarianceAggregator

A CovarianceAggregator is an Aggregator that returns the sample covariance of two numeric properties as a Double. The sample covariance is NaN if no non-null pairs of values were found, and it is zero if exactly one pair of non-null values was found. This Aggregator overrides the terminateDoubleDouble method, so that the sample covariance is also available as a DoubleDouble. This allows the sample covariance to be used by other Aggregators as a high-precision DoubleDouble.

Usage

Create and use a CovarianceAggregator, with one of the following methods:

  • Aggregator agg = new CovarianceAggregator("propertyOne", "propertyTwo");
  • Aggregator agg = Aggregator.getAggregator("Covariance(propertyOne, propertyTwo)");

The values returned by the two properties of the object must be numeric.

The sample covariance is calculated by summing up the products of both values' differences from their respective arithmetic means (averages), then dividing that sum by (n - 1), where n is the number of occurrences where both properties are not null.