The com.singularsys.extensions.statistical Extension
adds a range of statistical 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])
|
ElementSum | Summation of the arguments | sum(1,2,3,4) == 10
sum([1,2,3,4])
|
Mean | Mean of the arguments | mean(1,2,3,4) == 2.5
mean([1,2,3,4])
|
Median | Median of the arguments | median(1,2,3,4) == 2.5
median(1,2,3,4,5) == 3
|
Mode | Mode 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.addFunction("mean", new Mean(f)); 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 jep.addFunction("sd", new Variance(Variance.Type.POPSD, f)); 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.addFunction("count", new Count()); jep.addFunction("mean", new Mean(f)); jep.addFunction("median", new Median(f)); jep.addFunction("mode", new Mode(f)); jep.addFunction("mean", new Mean(f)); jep.addFunction("var_p", new Variance(Variance.Type.POPVAR, f)); jep.addFunction("var_s", new Variance(Variance.Type.SAMPLEVAR, f)); jep.addFunction("sd_p", new Variance(Variance.Type.POPSD, f)); jep.addFunction("sd_s", new Variance(Variance.Type.SAMPLESD, f)); jep.addFunction("rank", new Rank(Rank.Type.COMPETITION,true,f)); jep.addFunction("ranks",new Ranks(Ranks.Type.COMPETITION,true,f)); jep.addFunction("min",new ElementMinMax(ElementMinMax.Type.MIN, f)); jep.addFunction("max",new ElementMinMax(ElementMinMax.Type.MAX,f)); jep.addFunction("sum",new ElementSum(f)); jep.addFunction("prod",new ElementProduct(f)); jep.reinitializeComponents();
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()); jep.addFunction("binomCdf",new BinomialCdf()); jep.addFunction("normalCdf",new NormalDist(NormalDist.Type.CDF)); jep.addFunction("normalInv",new NormalInverse());