This module provides a basic set of functionalities to analyze datasets of values, numeric or not.

Functions

frequencies

frequencies<T>(values: Array<T>): Array<{ value: T, occurrences: Number }>

The frequencies function returns the number of occurrences of each distinct element on values.

Parameters
Name Type Description

values

Array<T>

Example

This example shows how the frequencies behaves under an array of numbers.

Source
1
2
3
4
5
6
%dw 2.0
output application/json

import frequencies from org::mule::weave::Statistics
---
frequencies([1, 2, 11, 1, 1, 2])
Output
1
2
3
4
5
[
  {value: 1, occurrences: 3},
  {value: 2, occurrences: 2},
  {value: 11, occurrences: 1}
]

mean

mean(values: Array<Number>): Number | Null

The mean function returns the mean of an array of numbers, or null if the array is empty.

Parameters
Name Type Description

values

Array<Number>

Example

This example shows how the mean behaves over an array with numbers.

Source
1
2
3
4
5
6
%dw 2.0
output application/json

import mean from org::mule::weave::Statistics
---
mean([1, 2, 3, 4, 5])
Output
1
3
Example

This example shows how the mean behaves under an empty array.

Source
1
2
3
4
5
6
%dw 2.0
output application/json

import mean from org::mule::weave::Statistics
---
mean([]) default "N/A"
Output
1
"N/A"

median

median(values: Array<Number>): Number | Null

The median function returns the point on the medium of the population.

If the length of the array is even, the average of the two medium points is returned.

Parameters
Name Type Description

values

Array<Number>

Example

This example shows how the median behaves under different inputs.

Source
1
2
3
4
5
6
%dw 2.0
output application/json

import median from org::mule::weave::Statistics
---
median([3, 1, 4])
Output
1
3

mode

mode<T>(values: Array<T>): T | Null

The mode function returns the most common value on the array of values.

If there are more than one values with the most number of occurrences, the first one will be returned.

Parameters
Name Type Description

values

Array<T>

Example

This example shows how the mode behaves under an arbitrary array.

Source
1
2
3
4
5
6
%dw 2.0
output application/json

import mode from org::mule::weave::Statistics
---
mode(["hello", "world", "data", "weave", "data"])
Output
1
"data"

modes

modes<T>(values: Array<T>): Array<T>

The modes function returns the values with the most number of occurrences.

Parameters
Name Type Description

values

Array<T>

Example

This example shows how the modes behaves under an arbitrary array.

Source
1
2
3
4
5
6
%dw 2.0
output application/json

import mode from org::mule::weave::Statistics
---
modes(["hello", "world", "data", "weave", "data", "hello"])
Output
1
["hello", "data"]

quantilesOf

quantilesOf(n: Number, values: Array<Number>): Array<Number> | Null

The quantilesOf function returns the points that separate the values in n parts of equal size.

If the middle point of two points is taken, it’ll be taken doing the average between both points.

Parameters
Name Type Description

values

Array<Number>

n

Number

Example

This example shows how the quantilesOf behaves under an arbitrary array.

Source
1
2
3
4
5
6
%dw 2.0
output application/json

import * from org::mule::weave::Statistics
---
3 quantilesOf [1, 2, 3, 4, 5]
Output
1
[2, 4]

stdev

stdev(values: Array<Number>): Number | Null

The stdev function returns the standard deviation of the given set of values.

The standard deviation is defined as the square root of the variance.

Parameters
Name Type Description

values

Array<Number>

Example

This example shows how the stdev behaves under an arbitrary array.

Source
1
2
3
4
5
6
%dw 2.0
output application/json

import stdev from org::mule::weave::Statistics
---
stdev([1, 2, 3, 2])
Output
1
0.7071067811865475244008443621048491

variance

variance(values: Array<Number>): Number | Null

The variance function returns the variance of the given set of values.

Parameters
Name Type Description

values

Array<Number>

Example

This example shows how the variance behaves under an arbitrary array.

Source
1
2
3
4
5
6
%dw 2.0
output application/json

import variance from org::mule::weave::Statistics
---
variance([1, 2, 3, 2])
Output
1
0.5