cts.variance( range-index as cts.reference, [options as String[]], [query as cts.query?], [forest-ids as (Number|String)[]] ) as Number?
Returns a frequency-weighted sample variance given a value lexicon. This
function works like math:variance
except each item in the
lexicon is counted cts:frequency
times.
This function performs the calculation in parallel in all data nodes
then aggregates the values.
The function returns the empty sequence if the lexicon contains no value.
// This query assumes an int range index // is configured in the database. It // generates some sample data and then // performs the aggregation in a separate // transaction. declareUpdate(); for (x=1; x<11; x++) { let o = new Object(); o.int = []; for (y=x; y<11; y++) { o.int.push(y); }; xdmp.documentInsert((x + ".json"), o); }; ******* // Then run the following (requires int range index on int): const item = cts.variance( cts.jsonPropertyReference("int","type=int"), ["item-frequency","concurrent"]); const frag = cts.variance( cts.jsonPropertyReference("int","type=int"), ["fragment-frequency","concurrent"]); const res = new Array(); res.push(item); res.push(frag); res; => [6.11111111111111, 6.11111111111111]