
cts.covariance( value1 as cts.reference, value2 as cts.reference, [options as String[]], [query as cts.query?], [forest-ids as (Number|String)[]] ) as Number?
  Returns the frequency-weighted sample covariance given a 2-way co-occurrence.
  The co-occurrence is formed from the specified value lexicons.
  This function works like 
  math.covariance except each pair
  in the co-occurrence is counted 
  cts.frequency times.
  This function performs the calculation in parallel in all data nodes
  then aggregates the values.
//   This query assumes range indexes with positions are
//   configured in the database for both xval and yval. It
//   generates some sample data and then performs the
//   aggregation in a separate transaction.
//  Generate data:
declareUpdate();
for (x=1; x<11; x++) {
  let j = 2 * x;
  let o = new Object();
  o.xval = x;
  o.yval = [];
  for (y=0; y<x; y++) {
    o.yval.push(j);
  };
  xdmp.documentInsert(("cov" + x + ".json"), o);
};
*******
// Run the query:
cts.covariance(
  cts.jsonPropertyReference("xval","type=int"),
  cts.jsonPropertyReference("yval","type=int"),
    ["item-frequency"]);
=>
12.2222222222222