Version:

Loading TOC...

MarkLogic 10 Product Documentation

math:linear-modelmath:linear-model( $arg as json:array* ) as math:linear-model?

Returns a linear model that fits the given data set. The size of the input array should be 2, as currently only simple linear regression model is supported. The first element of the array should be the value of the dependent variable while the other element should be the value of the independent variable.

The function eliminates all pairs for which either the first element or the second element is empty. After the elimination, if the length of the input is less than 2, the function returns the empty sequence. After the elimination, if the standard deviation of the independent variable is 0, the function returns a linear model with intercept = the mean of the dependent variable, coefficients = NaN and r-squared = NaN. After the elimination, if the standard deviation of the dependent variable is 0, the function returns a linear model with r-squared = NaN.

For the version of this function that uses Range Indexes, see cts:linear-model.

Parameters | |
---|---|

arg | The input data set. Each array should contain a pair of values. |

let $array := for $i in (1 to 10) let $j := 2*$i + 1 return json:to-array(($j,$i)) return math:linear-model($array) => math:linear-model( <math:linear-model intercept="1" coefficients="2" rsquared="1" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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.