<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/cts.stddev.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>cts.stddev</api:function-name><api:suggest>cts.stddev</api:suggest><api:suggest>cts</api:suggest><api:suggest>stddev</api:suggest><api:function-link mode="xquery" fullname="cts:stddev">/apidoc/8.0/cts:stddev.xml</api:function-link><api:function mode="javascript" name="stddev" 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.stddev"><api:summary>
  Returns a frequency-weighted sample standard deviation given a value lexicon.
  This function works like <code xmlns="http://www.w3.org/1999/xhtml">math:stddev</code> except each item in the
  lexicon 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.
  The function returns the empty sequence if the lexicon contains no value.
</api:summary><api:params><api:param name="range-index" type="cts:reference"><api:param-description>
    Reference to a range index. The type of the range index must be numeric.
  </api:param-description><api:param-name>range-index</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 <code xmlns="http://www.w3.org/1999/xhtml">cts:aggregate</code>.
  </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 <code xmlns="http://www.w3.org/1999/xhtml">cts:aggregate</code>.
  </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 <code xmlns="http://www.w3.org/1999/xhtml">cts:aggregate</code>.
  </api:param-description><api:param-name>forest-ids</api:param-name><api:param-type>String[]</api:param-type></api:param></api:params><api:return>Number?</api:return><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
//   This query assumes an int range index
//   is configured in the database. It
//   generates some sample data and then
//   performs the aggregation in a separate
//   transaction.

declareUpdate();

for (x=1; x&lt;11; x++) {
  var o = new Object();
  o.int = [];
  for (y=x; y&lt;11; y++) { 
    o.int.push(y);    
  };
  xdmp.documentInsert((x + ".json"), o); 
};

*******
// Then run the following (requires int range index on int):

var item = cts.stddev(
  cts.jsonPropertyReference("int","type=int"),
    ["item-frequency","concurrent"]);
var frag = cts.stddev(
  cts.jsonPropertyReference("int","type=int"),
    ["fragment-frequency","concurrent"]);
var res = new Array();
res.push(item);
res.push(frag);
res;
=&gt;
[2.47206616236522, 2.47206616236522]

</pre></api:example></api:function></api:function-page>