|
|
math:linear-model(
|
|
$arg as json:array*
|
| ) as math:linear-model? |
|
 |
Summary:
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.
|
|
Example:
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"/>)
|
Example:
xquery version "1.0-ml";
(:
This query uses the cts version of this function.
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:document-insert($uri, <a><xval>{$i}</xval><yval>{$j}</yval></a>);
cts:linear-model(
(cts:element-reference(xs:QName("yval"), ("type=unsignedLong")),
cts:element-reference(xs:QName("xval"), ("type=unsignedLong"))))
=>
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"/>)
|
|
|
|
math:mode(
|
|
$arg as xs:anyAtomicType*,
|
|
[$options as xs:string*]
|
| ) as xs:anyAtomicType* |
|
 |
Summary:
Returns the mode of a sequence. The mode is the value that occurs most
frequently in a data set. If no value occurs more than once in the data
set, the function returns the empty sequence. If the input is the empty
sequence, the function returns the empty sequence.
Note that a data set can have multiple “modes”. The order of multiple
modes in the returned sequence is undefined.
Also note that values from a lexicon lookup are repeated
cts:frequency times before calculating the mode.
The function can be used on numeric values, xs:yearMonthDuration,
xs:dayTimeDuration, xs:string,
xs:anyURI, xs:date,
xs:dateTime, xs:time,
and cts:point.
|
Parameters:
$arg
:
The sequence of values.
|
$options
(optional):
Options. The default is ().
Options include:
- "collation=URI"
- Applies only when $arg is of the xs:string type. If no specified,
the default collation is used.
- "coordinate-system=name"
- Applies only when $arg is of the cts:point type. If no specified,
the default coordinate system is used.
|
|
Example:
math:mode((1,2,2,3,2,3,4,6,7,7,7))
=> 2 7
|
|
|
|
math:percent-rank(
|
|
$arg as xs:anyAtomicType*,
|
|
$value as xs:anyAtomicType,
|
|
[$options as xs:string*]
|
| ) as xs:double? |
|
 |
Summary:
Returns the rank of a value in a data set as a percentage of the data set.
If the given value is not equal to any item in the sequence, the function
returns the empty sequence. See math:rank.
|
Parameters:
$arg
:
The sequence of values.
|
$value
:
The value to be "ranked".
|
$options
(optional):
Options. The default is ().
Options include:
- "ascending"(default)
- Rank the value as if the sequence was sorted in ascending order.
- "descending"
- Rank the value as if the sequence was sorted in descending order.
- "collation=URI"
- Applies only when $arg is of the xs:string type. If no specified,
the default collation is used.
- "coordinate-system=name"
- Applies only when $arg is of the cts:point type. If no specified,
the default coordinate system is used.
|
|
Example:
math:percent-rank((1, 7, 5, 5, 10, 9),9)
=> 0.833333333333333
|
|
|
|
math:rank(
|
|
$arg as xs:anyAtomicType*,
|
|
$arg as xs:anyAtomicType,
|
|
[$options as xs:string*]
|
| ) as xs:integer? |
|
 |
Summary:
Returns the rank of a value in a data set. Ranks are skipped in the event
of ties. If the given value is not equal to any item in the sequence, the
function returns the empty sequence. The function can be used on numeric
values, xs:yearMonthDuration, xs:dayTimeDuration,
xs:string, xs:anyURI,
xs:date, xs:dateTime, xs:time,
and cts:point.
|
Parameters:
$arg
:
The sequence of values.
|
$arg
:
The value to be "ranked".
|
$options
(optional):
Options. The default is ().
Options include:
- "ascending"(default)
- Rank the value as if the sequence was sorted in ascending order.
- "descending"
- Rank the value as if the sequence was sorted in descending order.
- "collation=URI"
- Applies only when $arg is of the xs:string type. If no specified,
the default collation is used.
- "coordinate-system=name"
- Applies only when $arg is of the cts:point type. If no specified,
the default coordinate system is used.
|
|
Example:
math:rank((1, 7, 5, 5, 10, 9),9)
=> 5
|
|
|
|
math:trunc(
|
|
$arg as numeric?,
|
|
$n as xs:integer
|
| ) as numeric? |
|
 |
Summary:
Returns the number truncated to a certain number of decimal places.
If type of $arg is one of the four numeric types xs:float,
xs:double, xs:decimal or xs:integer the type of the result is the same as the
type of $arg. If the type of $arg is a type derived from one of the numeric
types, the result is an instance of the base numeric type.
For xs:float and xs:double arguments, if the argument is positive infinity,
then positive infinity is returned. If the argument is negative infinity, then
negative infinity is returned. If the argument is positive zero, then positive
zero is returned. If the argument is negative zero, then negative zero is
returned.
|
Parameters:
$arg
:
A numeric value to truncate.
|
$n
:
The numbers of decimal places to truncate to. The default is 0. Negative values
cause that many digits to the left of the decimal point to be truncated.
|
|
Example:
math:trunc(125.815) returns 125
math:trunc(125.815, 0) returns 125
math:trunc(125.815, 1) returns 125.8
math:trunc(125.815, 2) returns 125.81
math:trunc(125.815, 3) returns 125.815
math:trunc(-125.815, 2) returns -125.81
math:trunc(125.815, -1) returns 120
math:trunc(125.815, -2) returns 100
math:trunc(125.815, -3) returns 0
|
|
|