cts:linearmodel( $values as cts:reference*, [$options as xs:string*], [$query as cts:query?], [$forestids as xs:unsignedLong*] ) as math:linearmodel?
Returns a linear model that fits the frequencyweighted data set.
The input data is a cooccurrence, 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 math:linearmodel
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.
Parameters  

values  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. 
options 
Same as the "options" parameter in cts:aggregate .

query 
Same as the "query" parameter in cts:aggregate .

forestids 
Same as the "forestids" parameter in cts:aggregate .

xquery version "1.0ml"; (: 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. :) for $i in (1 to 10) let $j := 2*$i + 1 let $uri := concat($i, ".xml") return xdmp:documentinsert($uri, <a><xval>{$i}</xval><yval>{$j}</yval></a>); cts:linearmodel( (cts:elementreference(xs:QName("yval"), ("type=unsignedLong")), cts:elementreference(xs:QName("xval"), ("type=unsignedLong"))), "itemfrequency") => math:linearmodel( <math:linearmodel intercept="1" coefficients="2" rsquared="1" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance" xmlns:math="http://marklogic.com/xdmp/math"/>)
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.