cts.correlation( 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 correlation given a 2-way co-occurrence.
The co-occurrence is formed from the specified value lexicons.
This function works like math:correlation
except each pair
in the input lexicons 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++) { const j = 2 * x; const 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.correlation( cts.jsonPropertyReference("xval","type=int"), cts.jsonPropertyReference("yval","type=int"), ["item-frequency"]); => 1
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.