Skip to content

Commit

Permalink
[Stats] add tTest statistics to have p-value from 2 vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
chapuisk committed Dec 10, 2021
1 parent 6e484fd commit 47b437f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions ummisco.gaml.extensions.maths/META-INF/MANIFEST.MF
Expand Up @@ -11,6 +11,7 @@ Export-Package: org.apache.commons.math3.ml.clustering,
org.apache.commons.math3.random,
org.apache.commons.math3.stat.descriptive,
org.apache.commons.math3.stat.descriptive.moment,
org.apache.commons.math3.stat.inference,
org.apache.commons.math3.stat.regression,
org.apache.commons.math3.util,
ummisco.gaml.extensions.maths.ode.statements
Expand Down
Expand Up @@ -25,6 +25,7 @@
import org.apache.commons.math3.random.MersenneTwister;
import org.apache.commons.math3.stat.descriptive.moment.Kurtosis;
import org.apache.commons.math3.stat.descriptive.moment.Skewness;
import org.apache.commons.math3.stat.inference.TTest;

import com.google.common.collect.Ordering;

Expand Down Expand Up @@ -1080,6 +1081,30 @@ public static IList<IList> KMeansPlusplusApache(final IScope scope, final IList
return results.items();
}
}

@operator (
value = "tTest",
can_be_const = false,
category = { IOperatorCategory.STATISTICAL },
concept = { IConcept.STATISTIC })
@doc (
value = "Returns the observed significance level, or p-value, associated with a two-sample, "
+ "two-tailed t-test comparing the means of the two input lists."
+ "The number returned is the smallest significance level at which one can reject the null hypothesis",
examples = { @example (
value = "tTest([10.0,5.0,1.0, 3.0],[1.0,10.0,5.0,1.0])",
equals = "0.01") })
public static Double tTestPValue(final IScope scope, final IList seq1, final IList seq2) {
TTest t = new TTest();

double[] s1 = new double[seq1.length(scope)];
for (int i = 0; i < seq1.length(scope); i++) { s1[i] = Cast.asFloat(scope, seq1.get(i)); }

double[] s2 = new double[seq2.length(scope)];
for (int i = 0; i < seq2.length(scope); i++) { s2[i] = Cast.asFloat(scope, seq2.get(i)); }

return t.tTest(s1,s2);
}

@operator (
value = "dtw",
Expand Down

0 comments on commit 47b437f

Please sign in to comment.