Loading TOC...

MarkLogic 10 Product Documentation
math:covariance

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

Summary

Returns the sample covariance 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.

For the version of this that uses range indexes, see cts:covariance.

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:covariance($array)

  => 18.3333333333333

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.