Class DistributionTest

java.lang.Object
jdistlib.disttest.DistributionTest

public class DistributionTest extends Object
Comparing two distributions
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static final double
    anderson_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 test
    static final double[]
    binomial_test(int n_success, int n, double p, TestKind kind)
    Binomial test
    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.
    static final double[]
    Pearson chi-square test of independence for a contingency table.
    static final double
    cramer_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 double
    cramer_vonmises_statistic(double[] X, double[] Y)
    Two-sample Cramer-Von Mises test
    static 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 test
    static 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[]
    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[]
    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 test
    static final void
    main(String[] args)
     
    static final double[]
    mann_whitney_u_test(double[] x, double[] y, double mu, boolean correction, boolean paired, TestKind kind)
    Mann-Whitney-U test
    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.
    static final double[]
    mood_test(double[] x, double[] y)
    Performs Mood's two-sample test for a difference in scale parameters.
    static final double[]
    mood_test(double[] x, double[] y, TestKind kind)
    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 distribution
    static final double[]
    poisson_test(int num_events1, int num_events2, double time1, double time2, double r, TestKind kind)
    Comparison of Poisson rates
    static final double[]
    t_test(double[] x, double[] y, double mu, boolean pool_var, TestKind kind)
    Two sample t-test
    static final double[]
    t_test(double[] x, double mu, TestKind kind)
    One-sample t-test
    static final double[]
    t_test_paired(double[] x, double[] y, double mu, TestKind kind)
    Paired t-test
    static final double[]
    var_test(double[] x, double[] y, double ratio, TestKind kind)
    Performs an F test to compare the variances of two samples from normal populations.
    static final double[]
    var_test(double[] x, double[] y, TestKind kind)
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 nX
      Y - 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 nX
      Y - an array with length of nY
      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

      public 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. If there are ties, then p-values will be inexact!
      Parameters:
      X - an array with length of nX
      Y - an array with length of nY
      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
    • 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 nX
      Y - an array with length of nY
      kind - 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

      public 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. If there are ties, then p-values will be inexact!
      Parameters:
      X - an array with length of nX
      dist - 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 nX
      dist - reference distribution
      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
    • 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 nX
      dist - reference distribution
      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

      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 nX
      dist - reference distribution
      kind - 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 x
      y - the original y
      force_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 x
      y - the original y
      force_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

      public static final double[] mood_test(double[] x, double[] y, TestKind kind)
      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

      public static final double[] var_test(double[] x, double[] y, TestKind kind)
      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

      public static final double[] var_test(double[] x, double[] y, double ratio, TestKind kind)
      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 ties
      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, 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 ranking
      digitsZap - 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 ties
      paired - 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. digitsZap applies when paired is true.
    • t_test

      public static final double[] t_test(double[] x, double mu, TestKind kind)
      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

      public static final double[] t_test_paired(double[] x, double[] y, double mu, TestKind kind)
      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 == false
      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
    • binomial_test

      public static final double[] binomial_test(int n_success, int n, double p, TestKind kind)
      Binomial test
      Parameters:
      n_success - The number of successes
      n - The total number of trials
      p - Expected probability
      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
    • 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. Pass Double.POSITIVE_INFINITY to rank the raw deviations.
      Parameters:
      x - observations
      group - group indices
      digitsRank - 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

      public 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 distribution
      Parameters:
      num_events - number of events.
      time - time base for event count.
      rate - hypothesized rate
      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
    • 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 - observations
      distribution - 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 - observations
      distribution - 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 - observations
      distribution - fully specified continuous reference law
      replicates - positive number of parametric bootstrap samples
      random - 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 - observations
      distribution - 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 - observations
      distribution - 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 - observations
      distribution - fully specified continuous reference law
      replicates - positive number of parametric bootstrap samples
      random - 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 sample
      second - 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 sample
      second - second sample
      permutations - positive number of label permutations
      random - 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 counts
      probabilities - strictly positive category probabilities or weights
      estimatedParameters - 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

      public static final void main(String[] args)