# Extensions - Statistical

The com.singularsys.extensions.statistical Extension adds a range of statistical functions.

## Aggregate functions

These functions take a set of arguments or an array of data and calculate different statistics.

Name Description Examples
Count Counts its arguments `count(1,2,3,4) == 4` `count([1,2,3,4])`
ElementSumSummation of the arguments `sum(1,2,3,4) == 10` `sum([1,2,3,4])`
MeanMean of the arguments `mean(1,2,3,4) == 2.5` `mean([1,2,3,4])`
MedianMedian of the arguments `median(1,2,3,4) == 2.5` `median(1,2,3,4,5) == 3`
ModeMode of the arguments `mode(1,2,3,3,4) == 3`
Variance Population/Sample variance and standard deviations of the arguments `var_p(1,2,3,4) == 1.25`
`var_s(1,2,3,4) == 1.67`
`sd_p(1,2,3,4) == 1.12`
`sd_s(1,2,3,4) == 1.29`
Rank Rank of a single element in a set, default is descending competition rank `rank(6,[5,6,7,8]) == 3`
Ranks Ranks of all elements in a set, default is descending competition rank `ranks([5,6,7,8]) == [4,3,2,1]`
ElementMinMax Minimum/maximum of the arguments `min(1,2,3,4) == 1` `max(1,2,3,4) == 4`
ElementSum Sum of the arguments `sum(1,2,3,4) == 10`
ElementProduct Product of the arguments `product(1,2,3,4) == 24`

These functions all require a field to be specified and can be added to Jep like other functions.

```Jep jep = new Jep();
FieldI f = new DoubleField();
jep.reinitializeComponents();

Node node = jep.parse("mean(1,2,3,4)");
Object res = jep.evaluate(node);
```

Some classes like `Variance` require a flag in the constructor to specify the particular type

```// Standard deviation based on entire population
Node node2 = jep.parse("sd(1,2,3,4)");
Object res2 = jep.evaluate(node2);
```

The full setup for the above functions is

```Jep jep = new Jep();
FieldI f = new DoubleField();
jep.reinitializeComponents();
```

## Distributions

A couple of statistical distributions are provided in the com.singularsys.extensions.statistical.distributions package.

Name Description Examples
BinomialDist Binomial distribution. A four argument version is available for Excel compatibility. `binomPdf(nSuccess,nTrial,p_success)` `binomPdf(10,2,0.25)`
BinomialCdf Binomial cumulative distribution function `binomCdf(nSuccess,nTrial,p_success)` `binomCdf(10,2,0.25)`
NormalDist Normal cumulative distribution function `normalCdf(x, mean, sd)` `normalCdf(0.3, 0, 1)`
NormalDist Inverse normal function `normalInv(probability,mean,sd)` `normalInv(0.3 ,0, 1)`

These functions would be set up using

```jep.addFunction("binomPdf",new BinomialDist());