<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/cts.linearModel.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>cts.linearModel</api:function-name><api:suggest>cts.linearmodel</api:suggest><api:suggest>cts</api:suggest><api:suggest>linearmodel</api:suggest><api:function-link mode="xquery" fullname="cts:linear-model">/apidoc/8.0/cts:linear-model.xml</api:function-link><api:function mode="javascript" name="linearModel" 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.linearModel"><api:summary>
  Returns a linear model that fits the frequency-weighted data set.
  The input data is a co-occurrence, formed from the specified value
  lexicons. The length of the input lexicon sequence should be 2, as
  currently only simple linear regression model is supported. The
  first lexicon should be the value of the dependent variable while
  the other lexicon should be the value of the independent variable.
  This function works like <code xmlns="http://www.w3.org/1999/xhtml">math:linear-model</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="values" type="cts:reference*"><api:param-description>
    References to two range indexes. The types of the range indexes must be
    numeric. If the size of this sequence is not 2, the function returns
    the empty sequence.
  </api:param-description><api:param-name>values</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 <a href="./cts:aggregate" xmlns="http://www.w3.org/1999/xhtml"><code>cts:aggregate</code></a>.
  </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 <a href="./cts:aggregate" xmlns="http://www.w3.org/1999/xhtml"><code>cts:aggregate</code></a>.
  </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 <a href="./cts:aggregate" xmlns="http://www.w3.org/1999/xhtml"><code>cts:aggregate</code></a>.
  </api:param-description><api:param-name>forest-ids</api:param-name><api:param-type>String[]</api:param-type></api:param></api:params><api:return>math.linearModel?</api:return><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
//   This query assumes range indexes of type unsignedLong
//   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 + 1;
  var uri = fn.concat(x, ".json");
  var vals = {xval:x, yval:j}
  var obj = {a:vals};
  xdmp.documentInsert(uri, obj);
  };

*******
// Run the following query:

cts.linearModel(
    [cts.jsonPropertyReference("yval", ["type=unsignedLong"]),
     cts.jsonPropertyReference("xval", ["type=unsignedLong"])],
    "item-frequency");

=&gt;
math.linearModel(
  &lt;math:linear-model intercept="0.352941176470588" 
      coefficients="1.97058823529412" rsquared="0.995196571090748" 
      xmlns:xs="http://www.w3.org/2001/XMLSchema" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:math="http://marklogic.com/xdmp/math"/&gt;)
</pre></api:example></api:function></api:function-page>