MarkLogic Server 11.0 Product Documentation
math:correlation

math:correlation(
   $arg as json:array*
) as xs:double?

Summary

Returns the Pearson correlation coefficient of a data set. The size of the input array should be 2. 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 first column or the standard deviation of the second column is 0, the function returns the empty sequence.

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

Example

  let $array :=
    for $i in (1 to 10)
    let $j := 2*$i
    return json:to-array(($i,$j))

  return math:correlation($array)

  => 1
Powered by MarkLogic Server | Terms of Use | Privacy Policy