<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/cts.correlation.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>cts.correlation</api:function-name><api:suggest>cts.correlation</api:suggest><api:suggest>cts</api:suggest><api:suggest>correlation</api:suggest><api:function-link mode="xquery" fullname="cts:correlation">/apidoc/8.0/cts:correlation.xml</api:function-link><api:function mode="javascript" name="correlation" type="builtin" lib="cts" category="SearchBuiltins" subcategory="Math Lexicon" hidden="false" bucket="MarkLogic Built-In Functions" prefix="cts" namespace="http://marklogic.com/cts" fullname="cts.correlation"><api:summary>
  Returns the frequency-weighted correlation given a 2-way co-occurrence.
  The co-occurence is formed from the specified value lexicons.
  This function works like <code xmlns="http://www.w3.org/1999/xhtml">math:correlation</code> except each pair
  in the input lexicons is counted <code xmlns="http://www.w3.org/1999/xhtml">cts:frequency</code> times. This
  function performs the calculation in parallel in all data nodes then
  aggregates the values.
</api:summary><api:params><api:param name="value1" type="cts:reference"><api:param-description>
    Reference to a range index. The type of the range index must be numeric.
  </api:param-description><api:param-name>value1</api:param-name><api:param-type>cts.reference</api:param-type></api:param><api:param name="value2" type="cts:reference"><api:param-description>
    Reference to a range index. The type of the range index must be numeric.
  </api:param-description><api:param-name>value2</api:param-name><api:param-type>cts.reference</api:param-type></api:param><api:param name="options" type="xs:string*" optional="true"><api:param-description>
    Same as the "options" parameter in <code xmlns="http://www.w3.org/1999/xhtml">cts:aggregate</code>.
  </api:param-description><api:param-name>options</api:param-name><api:param-type>String[]</api:param-type></api:param><api:param name="query" type="cts:query?" optional="true"><api:param-description>
     Same as the "query" parameter in <code xmlns="http://www.w3.org/1999/xhtml">cts:aggregate</code>.
  </api:param-description><api:param-name>query</api:param-name><api:param-type>cts.query?</api:param-type></api:param><api:param name="forest-ids" type="xs:unsignedLong*" optional="true"><api:param-description>
     Same as the "forest-ids" parameter in <code xmlns="http://www.w3.org/1999/xhtml">cts:aggregate</code>.
  </api:param-description><api:param-name>forest-ids</api:param-name><api:param-type>String[]</api:param-type></api:param></api:params><api:return>Number?</api:return><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
//   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&lt;11; x++) {
  var j = 2 * x;
  var o = new Object();
  o.xval = x;
  o.yval = [];
  for (y=0; y&lt;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"]);
=&gt;
1
</pre></api:example></api:function></api:function-page>