Package jdistlib.disttest
Class DistributionTest
java.lang.Object
jdistlib.disttest.DistributionTest
Comparing two distributions
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final doubleanderson_darling_statistic(double[] sample, GenericDistribution distribution) One-sample Anderson-Darling statistic against a fully specified continuous reference distribution.static final double[]anderson_darling_test(double[] sample, GenericDistribution distribution) One-sample Anderson-Darling test using a deterministic parametric bootstrap.static final double[]anderson_darling_test(double[] sample, GenericDistribution distribution, int replicates, RandomEngine random) One-sample Anderson-Darling test with caller-controlled bootstrap sampling.static final double[]ansari_bradley_test(double[] x, double[] y, boolean force_exact) Return the two-sided test of Ansari-Bradley.static final double[]ansari_bradley_test(double[] x, double[] y, boolean force_exact, TestKind kind) Ansari-Bradley test.static final double[]bartlett_test(double[] x, int[] group) Bartlett's teststatic final double[]binomial_test(int n_success, int n, double p, TestKind kind) Binomial teststatic final double[]chi_square_goodness_of_fit_test(long[] observed, double[] probabilities, int estimatedParameters) Pearson chi-square goodness-of-fit test for categorical counts.static final double[]chi_square_independence_test(long[][] counts) Pearson chi-square test of independence for a contingency table.static final doublecramer_von_mises_statistic(double[] sample, GenericDistribution distribution) One-sample Cramer-von Mises statistic against a fully specified continuous reference distribution.static final double[]cramer_von_mises_test(double[] first, double[] second) Two-sample Cramer-von Mises test using a deterministic permutation p-value.static final double[]cramer_von_mises_test(double[] first, double[] second, int permutations, RandomEngine random) Two-sample Cramer-von Mises test with caller-controlled permutations.static final double[]cramer_von_mises_test(double[] sample, GenericDistribution distribution) One-sample Cramer-von Mises test using a deterministic parametric bootstrap.static final double[]cramer_von_mises_test(double[] sample, GenericDistribution distribution, int replicates, RandomEngine random) One-sample Cramer-von Mises test with caller-controlled bootstrap sampling.static final doublecramer_vonmises_statistic(double[] X, double[] Y) Two-sample Cramer-Von Mises teststatic final double[]diptest(double[] x) Perform Hartigan's dip test, assuming the minimum test statistics D is zero.static final double[]diptest_presorted(double[] x) Perform Hartigan's dip test, assuming the minimum test statistics D is zero.static final double[]fligner_test(double[] x, int[] group) Fligner-Killeen teststatic final double[]fligner_test(double[] x, int[] group, double digitsRank) Fligner-Killeen test with a significant-digits control for ranking centered absolute deviations.static final double[]kolmogorov_smirnov_test(double[] X, double[] Y) Compute the Kolmogorov-Smirnov test to test between two distribution, two-sided, exact p-value.static final double[]kolmogorov_smirnov_test(double[] X, double[] Y, boolean isExact) Compute the Kolmogorov-Smirnov test to test between two distribution, two-sided.static final double[]kolmogorov_smirnov_test(double[] X, double[] Y, TestKind kind) Compute the Kolmogorov-Smirnov test to test between two distribution, exact p-value.static final double[]kolmogorov_smirnov_test(double[] X, double[] Y, TestKind kind, boolean isExact) Compute the Kolmogorov-Smirnov test to test between two distribution.static final double[]kolmogorov_smirnov_test(double[] X, GenericDistribution dist) Compute the Kolmogorov-Smirnov test to test between X and a known reference distribution, two-sided, exact p-value.static final double[]kolmogorov_smirnov_test(double[] X, GenericDistribution dist, boolean isExact) Compute the Kolmogorov-Smirnov test to test between X and a known reference distribution, two-sided.static final double[]kolmogorov_smirnov_test(double[] X, GenericDistribution dist, TestKind kind) Compute the Kolmogorov-Smirnov test to test between X and a known reference distribution, exact p-value.static final double[]kolmogorov_smirnov_test(double[] X, GenericDistribution dist, TestKind kind, boolean isExact) Compute the Kolmogorov-Smirnov test to test between X and a known reference distribution.static final double[]kruskal_wallis_test(double[] x, int[] group) Kruskal-Wallis teststatic final voidstatic final double[]mann_whitney_u_test(double[] x, double[] y, double mu, boolean correction, boolean paired, TestKind kind) Mann-Whitney-U teststatic final double[]mann_whitney_u_test(double[] x, double[] y, double mu, boolean correction, boolean paired, TestKind kind, double digitsRank, double digitsZap) Mann-Whitney-Wilcoxon test with the same rank rounding controls as current R.static final double[]mood_test(double[] x, double[] y) Performs Mood's two-sample test for a difference in scale parameters.static final double[]Performs Mood's two-sample test for a difference in scale parameters.static final double[]poisson_test(int num_events, double time, double rate, TestKind kind) Performs an exact test of a simple null hypothesis about the rate parameter in Poisson distributionstatic final double[]poisson_test(int num_events1, int num_events2, double time1, double time2, double r, TestKind kind) Comparison of Poisson ratesstatic final double[]Two sample t-teststatic final double[]One-sample t-teststatic final double[]t_test_paired(double[] x, double[] y, double mu, TestKind kind) Paired t-teststatic final double[]Performs an F test to compare the variances of two samples from normal populations.static final double[]Performs an F test to compare the variances of two samples from normal populations.static final double[]wilcoxon_test(double[] x, double mu, boolean correction, TestKind kind) One-sample Wilcoxon test.static final double[]wilcoxon_test(double[] x, double mu, boolean correction, TestKind kind, double digitsRank, double digitsZap) One-sample Wilcoxon signed-rank test with R-compatible preprocessing.
-
Constructor Details
-
DistributionTest
public DistributionTest()
-
-
Method Details
-
kolmogorov_smirnov_test
public static final double[] kolmogorov_smirnov_test(double[] X, double[] Y) Compute the Kolmogorov-Smirnov test to test between two distribution, two-sided, exact p-value. If there are ties, then p-values will be inexact!- Parameters:
X- an array with length of nXY- an array with length of nY- Returns:
- an array of two elements: The first is the test statistic, the second is the p-value
-
kolmogorov_smirnov_test
public static final double[] kolmogorov_smirnov_test(double[] X, double[] Y, boolean isExact) Compute the Kolmogorov-Smirnov test to test between two distribution, two-sided.- Parameters:
X- an array with length of nXY- an array with length of nYisExact- whether the p-value should be computed with the exact method or not (takes a long time). If there are ties, this option is ignored.- Returns:
- an array of two elements: The first is the test statistic, the second is the p-value
-
kolmogorov_smirnov_test
Compute the Kolmogorov-Smirnov test to test between two distribution, exact p-value. If there are ties, then p-values will be inexact!- Parameters:
X- an array with length of nXY- an array with length of nYkind- the kind of test {LOWER, GREATER, TWO_SIDED}- Returns:
- an array of two elements: The first is the test statistic, the second is the p-value
-
kolmogorov_smirnov_test
public static final double[] kolmogorov_smirnov_test(double[] X, double[] Y, TestKind kind, boolean isExact) Compute the Kolmogorov-Smirnov test to test between two distribution.- Parameters:
X- an array with length of nXY- an array with length of nYkind- the kind of test {LOWER, GREATER, TWO_SIDED}isExact- whether the p-value should be computed with the exact method or not (takes a long time). If there are ties, this option is ignored.- Returns:
- an array of two elements: The first is the test statistic, the second is the p-value
-
kolmogorov_smirnov_test
Compute the Kolmogorov-Smirnov test to test between X and a known reference distribution, two-sided, exact p-value. If there are ties, then p-values will be inexact!- Parameters:
X- an array with length of nXdist- reference distribution- Returns:
- an array of two elements: The first is the test statistic, the second is the p-value
-
kolmogorov_smirnov_test
public static final double[] kolmogorov_smirnov_test(double[] X, GenericDistribution dist, TestKind kind) Compute the Kolmogorov-Smirnov test to test between X and a known reference distribution, exact p-value. If there are ties, then p-values will be inexact!- Parameters:
X- an array with length of nXdist- reference distributionkind- the kind of test {LOWER, GREATER, TWO_SIDED}- Returns:
- an array of two elements: The first is the test statistic, the second is the p-value
-
kolmogorov_smirnov_test
public static final double[] kolmogorov_smirnov_test(double[] X, GenericDistribution dist, boolean isExact) Compute the Kolmogorov-Smirnov test to test between X and a known reference distribution, two-sided.- Parameters:
X- an array with length of nXdist- reference distributionisExact- whether the p-value should be computed with the exact method or not (takes a long time). If there are ties, this option is ignored.- Returns:
- an array of two elements: The first is the test statistic, the second is the p-value
-
kolmogorov_smirnov_test
public static final double[] kolmogorov_smirnov_test(double[] X, GenericDistribution dist, TestKind kind, boolean isExact) Compute the Kolmogorov-Smirnov test to test between X and a known reference distribution.- Parameters:
X- an array with length of nXdist- reference distributionkind- the kind of test {LOWER, GREATER, TWO_SIDED}isExact- whether the p-value should be computed with the exact method or not (takes a long time). If there are ties, this option is ignored.- Returns:
- an array of two elements: The first is the test statistic, the second is the p-value
-
ansari_bradley_test
public static final double[] ansari_bradley_test(double[] x, double[] y, boolean force_exact) Return the two-sided test of Ansari-Bradley.- Parameters:
x- the original xy- the original yforce_exact- Set to true if you want exact answer. The default behavior is that if there are ties or either the length of x or the length of y is at least 50.- Returns:
- an array of two elements: The first is the test statistic, the second is the p-value
-
ansari_bradley_test
public static final double[] ansari_bradley_test(double[] x, double[] y, boolean force_exact, TestKind kind) Ansari-Bradley test.- Parameters:
x- the original xy- the original yforce_exact- Set to true if you want exact answer. The default behavior is that if there are ties or either the length of x or the length of y is at least 50.kind- the kind of test {LOWER, GREATER, TWO_SIDED}- Returns:
- an array of two elements: The first is the test statistic, the second is the p-value
-
mood_test
public static final double[] mood_test(double[] x, double[] y) Performs Mood's two-sample test for a difference in scale parameters. Two-sided test.- Parameters:
x-y-- Returns:
- an array of two elements: The first is the test statistic, the second is the p-value
-
mood_test
Performs Mood's two-sample test for a difference in scale parameters.- Parameters:
x-y-kind- the kind of test {LOWER, GREATER, TWO_SIDED}- Returns:
- an array of two elements: The first is the test statistic, the second is the p-value
-
var_test
Performs an F test to compare the variances of two samples from normal populations. Ratio is set to 1.0.- Parameters:
x-y-kind- the kind of test {LOWER, GREATER, TWO_SIDED}- Returns:
- an array of two elements: The first is the test statistic, the second is the p-value
-
var_test
Performs an F test to compare the variances of two samples from normal populations.- Parameters:
x-y-ratio- the hypothesized ratio of the population variances of x and y.kind- the kind of test {LOWER, GREATER, TWO_SIDED}- Returns:
- an array of two elements: The first is the test statistic, the second is the p-value
-
wilcoxon_test
public static final double[] wilcoxon_test(double[] x, double mu, boolean correction, TestKind kind) One-sample Wilcoxon test. Test whether the vector of x is != mu- Parameters:
x-mu-correction- set to true if continuity correction is desired. Only matters if x has zeroes or tieskind- the kind of test {LOWER, GREATER, TWO_SIDED}- Returns:
- an array of two elements: The first is the test statistic, the second is the p-value
-
wilcoxon_test
public static final double[] wilcoxon_test(double[] x, double mu, boolean correction, TestKind kind, double digitsRank, double digitsZap) One-sample Wilcoxon signed-rank test with R-compatible preprocessing. Infinite digit values disable the corresponding operation.- Parameters:
digitsRank- significant digits applied before rankingdigitsZap- digits used to turn differences that are tiny relative to the sample scale into exact zeroes
-
mann_whitney_u_test
public static final double[] mann_whitney_u_test(double[] x, double[] y, double mu, boolean correction, boolean paired, TestKind kind) Mann-Whitney-U test- Parameters:
x-y-mu-correction- set to true if continuity correction is desired. Only matters then there are tiespaired- set to true for paired test (which reduces to Wilcoxon test)kind- the kind of test {LOWER, GREATER, TWO_SIDED}- Returns:
- an array of two elements: The first is the test statistic, the second is the p-value
-
mann_whitney_u_test
public static final double[] mann_whitney_u_test(double[] x, double[] y, double mu, boolean correction, boolean paired, TestKind kind, double digitsRank, double digitsZap) Mann-Whitney-Wilcoxon test with the same rank rounding controls as current R.digitsZapapplies whenpairedis true. -
t_test
One-sample t-test- Parameters:
x-mu-kind- the kind of test {LOWER, GREATER, TWO_SIDED}- Returns:
- an array of two elements: The first is the test statistic, the second is the p-value
-
t_test_paired
Paired t-test- Parameters:
x-y-mu-kind- the kind of test {LOWER, GREATER, TWO_SIDED}- Returns:
- an array of two elements: The first is the test statistic, the second is the p-value
-
t_test
public static final double[] t_test(double[] x, double[] y, double mu, boolean pool_var, TestKind kind) Two sample t-test- Parameters:
x-y-mu-pool_var- set to true if the variance should be pooled. Only matters when paired == falsekind- the kind of test {LOWER, GREATER, TWO_SIDED}- Returns:
- an array of two elements: The first is the test statistic, the second is the p-value
-
binomial_test
Binomial test- Parameters:
n_success- The number of successesn- The total number of trialsp- Expected probabilitykind- the kind of test {LOWER, GREATER, TWO_SIDED}- Returns:
- an array of two elements: The first is the test statistic, the second is the p-value
-
bartlett_test
public static final double[] bartlett_test(double[] x, int[] group) Bartlett's test- Parameters:
x-group- an array of group indices. Observation in x that belongs in the same group must have the same index.- Returns:
- an array of two elements: The first is the test statistic, the second is the p-value
-
fligner_test
public static final double[] fligner_test(double[] x, int[] group) Fligner-Killeen test- Parameters:
x-group- an array of group indices. Observation in x that belongs in the same group must have the same index.- Returns:
- an array of two elements: The first is the test statistic, the second is the p-value
-
fligner_test
public static final double[] fligner_test(double[] x, int[] group, double digitsRank) Fligner-Killeen test with a significant-digits control for ranking centered absolute deviations. This prevents an affine rescaling from manufacturing or destroying ties through binary floating-point roundoff. PassDouble.POSITIVE_INFINITYto rank the raw deviations.- Parameters:
x- observationsgroup- group indicesdigitsRank- significant digits applied before ranking- Returns:
- an array containing the statistic and p-value
-
kruskal_wallis_test
public static final double[] kruskal_wallis_test(double[] x, int[] group) Kruskal-Wallis test- Parameters:
x-group- an array of group indices. Observation in x that belongs in the same group must have the same index.- Returns:
- an array of two elements: The first is the test statistic, the second is the p-value
-
poisson_test
Performs an exact test of a simple null hypothesis about the rate parameter in Poisson distribution- Parameters:
num_events- number of events.time- time base for event count.rate- hypothesized ratekind- the kind of test {LOWER, GREATER, TWO_SIDED}- Returns:
- an array of two elements: The first is the test statistic, the second is the p-value
-
poisson_test
public static final double[] poisson_test(int num_events1, int num_events2, double time1, double time2, double r, TestKind kind) Comparison of Poisson rates- Parameters:
num_events1- number of events for the treatment.num_events2- number of events for control.time1- time base for event count for treatment.time2- time base for event count for control.kind- the kind of test {LOWER, GREATER, TWO_SIDED}- Returns:
- an array of two elements: The first is the test statistic, the second is the p-value
-
cramer_von_mises_statistic
public static final double cramer_von_mises_statistic(double[] sample, GenericDistribution distribution) One-sample Cramer-von Mises statistic against a fully specified continuous reference distribution.- Parameters:
sample- observationsdistribution- fully specified continuous reference law- Returns:
- the Cramer-von Mises W-squared statistic
-
cramer_von_mises_test
public static final double[] cramer_von_mises_test(double[] sample, GenericDistribution distribution) One-sample Cramer-von Mises test using a deterministic parametric bootstrap.- Parameters:
sample- observationsdistribution- fully specified continuous reference law- Returns:
- two elements: statistic and bootstrap p-value
-
cramer_von_mises_test
public static final double[] cramer_von_mises_test(double[] sample, GenericDistribution distribution, int replicates, RandomEngine random) One-sample Cramer-von Mises test with caller-controlled bootstrap sampling.- Parameters:
sample- observationsdistribution- fully specified continuous reference lawreplicates- positive number of parametric bootstrap samplesrandom- caller-owned random stream- Returns:
- two elements: statistic and bootstrap p-value
-
anderson_darling_statistic
public static final double anderson_darling_statistic(double[] sample, GenericDistribution distribution) One-sample Anderson-Darling statistic against a fully specified continuous reference distribution.- Parameters:
sample- observationsdistribution- fully specified continuous reference law- Returns:
- the Anderson-Darling A-squared statistic
-
anderson_darling_test
public static final double[] anderson_darling_test(double[] sample, GenericDistribution distribution) One-sample Anderson-Darling test using a deterministic parametric bootstrap.- Parameters:
sample- observationsdistribution- fully specified continuous reference law- Returns:
- two elements: statistic and bootstrap p-value
-
anderson_darling_test
public static final double[] anderson_darling_test(double[] sample, GenericDistribution distribution, int replicates, RandomEngine random) One-sample Anderson-Darling test with caller-controlled bootstrap sampling.- Parameters:
sample- observationsdistribution- fully specified continuous reference lawreplicates- positive number of parametric bootstrap samplesrandom- caller-owned random stream- Returns:
- two elements: statistic and bootstrap p-value
-
cramer_von_mises_test
public static final double[] cramer_von_mises_test(double[] first, double[] second) Two-sample Cramer-von Mises test using a deterministic permutation p-value.- Parameters:
first- first samplesecond- second sample- Returns:
- two elements: statistic and permutation p-value
-
cramer_von_mises_test
public static final double[] cramer_von_mises_test(double[] first, double[] second, int permutations, RandomEngine random) Two-sample Cramer-von Mises test with caller-controlled permutations.- Parameters:
first- first samplesecond- second samplepermutations- positive number of label permutationsrandom- caller-owned random stream- Returns:
- two elements: statistic and permutation p-value
-
chi_square_goodness_of_fit_test
public static final double[] chi_square_goodness_of_fit_test(long[] observed, double[] probabilities, int estimatedParameters) Pearson chi-square goodness-of-fit test for categorical counts.- Parameters:
observed- nonnegative observed countsprobabilities- strictly positive category probabilities or weightsestimatedParameters- number of parameters estimated from these counts- Returns:
- statistic, upper-tail p-value, and degrees of freedom
-
chi_square_independence_test
public static final double[] chi_square_independence_test(long[][] counts) Pearson chi-square test of independence for a contingency table.- Parameters:
counts- rectangular table with at least two rows and columns- Returns:
- statistic, upper-tail p-value, and degrees of freedom
-
cramer_vonmises_statistic
public static final double cramer_vonmises_statistic(double[] X, double[] Y) Two-sample Cramer-Von Mises test- Parameters:
X-Y-- Returns:
- statistic
-
diptest
public static final double[] diptest(double[] x) Perform Hartigan's dip test, assuming the minimum test statistics D is zero.- Parameters:
x- Can be of any order. If x is already sorted, use diptest_presorted to save some time.- Returns:
- an array of four elements: The first is the test statistic, the second is the p-value, followed by indices for which there are a dip. If there is no dip, the indices will be set to -1.
-
diptest_presorted
public static final double[] diptest_presorted(double[] x) Perform Hartigan's dip test, assuming the minimum test statistics D is zero.- Parameters:
x- MUST BE SORTED in order to output the right result. This routine will NOT check for order!- Returns:
- an array of four elements: The first is the test statistic, the second is the p-value, followed by indices for which there are a dip. If there is no dip, the indices will be set to -1.
-
main
-