Class StatUtils

java.lang.Object
edu.cmu.tetrad.util.StatUtils

public final class StatUtils extends Object
Contains a number of basic statistical functions. Most methods are overloaded for either long or double arrays. NOTE: Some methods in this class have been adapted from class DStat written by Michael Fanelli, and the routines have been included here by permission. The methods which were adapted are:
  • gamma
  • internalGamma
  • beta
  • igamma
  • erf
  • poisson
  • chidist
  • contTable1
These methods are protected under copyright by the author. Here is the text of his copyright notice for DSTAT.java: "Copyright 1997 by Michael Fanelli. All Rights Reserved. Unlimited use of this beta code granted for non-commercial use only subject to the the expiration date. Commercial (for profit) use requires written permission."
Author:
josephramsey
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    averageDeviation(double[] array)
     
    static double
    averageDeviation(double[] array, int N)
     
    static double
    averageDeviation(long[] array)
     
    static double
    averageDeviation(long[] array, int N)
     
    static double
    beta(double x1, double x2)
    Calculates the value of beta for doubles
    static double
    chidist(double x, int degreesOfFreedom)
    Calculates the one-tail probability of the Chi-squared distribution for doubles
    static short
     
    static double
    correlation(double[] array1, double[] array2)
     
    static double
    correlation(double[] array1, double[] array2, int N)
     
    static double
    correlation(long[] array1, long[] array2)
     
    static double
    correlation(long[] array1, long[] array2, int N)
     
    static double
    correlation(Vector data1, Vector data2)
     
    static double[]
    cov(double[] x, double[] y, double[] condition, double threshold, double direction)
     
    static double
    covariance(double[] array1, double[] array2)
     
    static double
    covariance(double[] array1, double[] array2, int N)
     
    static double
    covariance(long[] array1, long[] array2)
     
    static double
    covariance(long[] array1, long[] array2, int N)
     
    static double[][]
    covMatrix(double[] x, double[] y, double[][] z, double[] condition, double threshold, double direction)
     
    static int
    dieToss(int n)
     
    static double[]
    E(double[] x, double[] y, double[] condition, double threshold, double direction)
     
    static double
    entropy(int numBins, double[] _f)
     
    static double
    erf(double x)
    Calculates the error function for a double
    static double
    expScore(double[] _f)
     
    static double
    factorial(int c)
     
    static int
    fdr(double alpha, List<Double> pValues)
     
    static int
    fdr(double alpha, List<Double> pValues, boolean negativelyCorrelated, boolean pSorted)
     
    static double
    fdrCutoff(double alpha, List<Double> pValues, boolean negativelyCorrelated)
     
    static double
    fdrCutoff(double alpha, List<Double> pValues, boolean negativelyCorrelated, boolean pSorted)
    Calculates the cutoff value for p-values using the FDR method.
    static double
    fdrCutoff(double alpha, List<Double> pValues, int[] _k, boolean negativelyCorrelated, boolean pSorted)
     
    static double
    fdrQ(List<Double> pValues, int k)
     
    static double
    gamma(double z)
    GAMMA FUNCTION (From DStat, used by permission).
    static double[]
    getRanks(double[] arr)
     
    static List<Integer>
    getRows(double[] x, double[] condition, double threshold, double direction)
     
    static List<Integer>
    getRows(double[] x, double threshold, double direction)
     
    static double
    getZForAlpha(double alpha)
     
    static double
    igamma(double a, double x)
    Calculates the incomplete gamma function for two doubles
    static double
    kendallsTau(double[] x, double[] y)
     
    static double
    kurtosis(double[] array)
     
    static double
    kurtosis(double[] array, int N)
     
    static double
    kurtosis(long[] array)
     
    static double
    kurtosis(long[] array, int N)
     
    static double
     
    static double
    logCoshScore(double[] _f)
     
    static double
     
    static double
    max(double[] array)
     
    static double
    max(double[] array, int N)
     
    static double
    max(long[] array)
     
    static double
    max(long[] array, int N)
     
    static double
    maxEntApprox(double[] x)
     
    static double
    mean(double[] array)
     
    static double
    mean(double[] array, int N)
     
    static double
    mean(long[] array)
     
    static double
    mean(long[] array, int N)
     
    static double
    mean(Vector data, int N)
     
    static double
    meanAbsolute(double[] _f)
     
    static double
    median(double[] array)
     
    static double
    median(double[] array, int N)
     
    static double
    median(long[] array)
     
    static long
    median(long[] array, int N)
     
    static double
    min(double[] array)
     
    static double
    min(double[] array, int N)
     
    static double
    min(long[] array)
     
    static double
    min(long[] array, int N)
     
    static double
    mu(double[] array)
     
    static double
    mu(double[] array, int N)
     
    static double
    mu(long[] array)
     
    static double
    mu(long[] array, int N)
     
    static double
    muHat(double[] array)
     
    static double
    muHat(double[] array, int N)
     
    static double
    muHat(long[] array)
     
    static double
    muHat(long[] array, int N)
     
    static int
    N(double[] array)
     
    static int
    N(long[] array)
     
    static double
    Assumes that the given covariance matrix was extracted in such a way that the order of the variables (in either direction) is X, Y, Z1, ..., Zn, where the partial correlation one wants is correlation(X, Y | Z1,...,Zn).
    static double
    partialCorrelation(Matrix covariance, int x, int y, int... z)
     
    static double
     
    static double
    Assumes that the given covariance matrix was extracted in such a way that the order of the variables (in either direction) is X, Y, Z1, ..., Zn, where the partial covariance one wants is covariance(X, Y | Z1,...,Zn).
    static double
    partialCovarianceWhittaker(Matrix covariance, int x, int y, int... z)
     
    static double
    partialStandardDeviation(Matrix covariance, int x, int... z)
     
    static double
    partialVariance(Matrix covariance, int x, int... z)
     
    static double
    poisson(double k, double x, boolean cum)
    Calculates the Poisson Distribution for mean x and k events for doubles.
    static double
    pow()
     
    static double
    quartile(double[] array, int quartileNumber)
     
    static double
    quartile(double[] array, int N, int quartileNumber)
     
    static double
    quartile(long[] array, int quartileNumber)
     
    static double
    quartile(long[] array, int N, int quartileNumber)
     
    static double
    range(double[] array)
     
    static double
    range(double[] array, int N)
     
    static double
    range(long[] array)
     
    static double
    range(long[] array, int N)
     
    static double
    rankCorrelation(double[] arr1, double[] arr2)
     
    static double[]
    removeNaN(double[] x1)
     
    static double
    sd(double[] array)
     
    static double
    sd(double[] array, int N)
     
    static double
    sd(long[] array)
     
    static double
    sd(long[] array, int N)
     
    static double
    skewness(double[] array)
     
    static double
    skewness(double[] array, int N)
     
    static double
    skewness(long[] array)
     
    static double
    skewness(long[] array, int N)
     
    static double
    sSquare(double[] array)
     
    static double
    sSquare(double[] array, int N)
     
    static double
    sSquare(long[] array)
     
    static double
    sSquare(long[] array, int N)
     
    static double
    ssx(double[] array)
     
    static double
    ssx(double[] array, int N)
     
    static double
    ssx(long[] array)
     
    static double
    ssx(long[] array, int N)
     
    static double[]
    standardizeData(double[] data)
     
    static double
    standardizedFifthMoment(double[] array)
     
    static double
    standardizedFifthMoment(double[] array, int N)
     
    static double
    standardizedSixthMoment(double[] array)
     
    static double
    standardizedSixthMoment(double[] array, int N)
     
    static double
    sum(double[] x)
     
    static double
    sxy(double[] array1, double[] array2)
     
    static double
    sxy(double[] array1, double[] array2, int N)
     
    static double
    sxy(long[] array1, long[] array2)
     
    static double
    sxy(long[] array1, long[] array2, int N)
     
    static double
    sxy(Vector data1, Vector data2, int N)
     
    static double
    varHat(double[] array)
     
    static double
    varHat(double[] array, int N)
     
    static double
    varHat(long[] array)
     
    static double
    varHat(long[] array, int N)
     
    static double
    variance(double[] array)
     
    static double
    variance(double[] array, int N)
     
    static double
    variance(long[] array)
     
    static double
    variance(long[] array, int N)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • StatUtils

      public StatUtils()
  • Method Details

    • mean

      public static double mean(long[] array)
      Parameters:
      array - a long array.
      Returns:
      the mean of the values in this array.
    • mean

      public static double mean(double[] array)
      Parameters:
      array - a double array.
      Returns:
      the mean of the values in this array.
    • mean

      public static double mean(long[] array, int N)
      Parameters:
      array - a long array.
      N - the number of values of array which should be considered.
      Returns:
      the mean of the first N values in this array.
    • mean

      public static double mean(double[] array, int N)
      Parameters:
      array - a double array.
      N - the number of values of array which should be considered.
      Returns:
      the mean of the first N values in this array.
    • mean

      public static double mean(Vector data, int N)
      Parameters:
      data - a column vector.
      N - the number of values of array which should be considered.
      Returns:
      the mean of the first N values in this array.
    • median

      public static double median(long[] array)
      Parameters:
      array - a long array.
      Returns:
      the median of the values in this array.
    • median

      public static double median(double[] array)
      Parameters:
      array - a double array.
      Returns:
      the median of the values in this array.
    • median

      public static long median(long[] array, int N)
      Parameters:
      array - a long array.
      N - the number of values of array which should be considered.
      Returns:
      the median of the first N values in this array.
    • median

      public static double median(double[] array, int N)
      Parameters:
      array - a double array.
      N - the number of values of array which should be considered.
      Returns:
      the median of the first N values in this array.
    • quartile

      public static double quartile(long[] array, int quartileNumber)
      Parameters:
      array - a long array.
      quartileNumber - 1, 2, or 3.
      Returns:
      the requested quartile of the values in this array.
    • quartile

      public static double quartile(double[] array, int quartileNumber)
      Parameters:
      array - a double array.
      quartileNumber - 1, 2, or 3.
      Returns:
      the requested quartile of the values in this array.
    • quartile

      public static double quartile(long[] array, int N, int quartileNumber)
      Parameters:
      array - a long array.
      N - the number of values of array which should be considered.
      quartileNumber - 1, 2, or 3.
      Returns:
      the requested quartile of the first N values in this array.
    • quartile

      public static double quartile(double[] array, int N, int quartileNumber)
      Parameters:
      array - a double array.
      N - the number of values of array which should be considered.
      quartileNumber - 1, 2, or 3.
      Returns:
      the requested quartile of the first N values in this array.
    • min

      public static double min(long[] array)
      Parameters:
      array - a long array.
      Returns:
      the minimum of the values in this array.
    • min

      public static double min(double[] array)
      Parameters:
      array - a double array.
      Returns:
      the minimum of the values in this array.
    • min

      public static double min(long[] array, int N)
      Parameters:
      array - a long array.
      N - the number of values of array which should be considered.
      Returns:
      the minimum of the first N values in this array.
    • min

      public static double min(double[] array, int N)
      Parameters:
      array - a double array.
      N - the number of values of array which should be considered.
      Returns:
      the minimum of the first N values in this array.
    • max

      public static double max(long[] array)
      Parameters:
      array - a long array.
      Returns:
      the maximum of the values in this array.
    • max

      public static double max(double[] array)
      Parameters:
      array - a double array.
      Returns:
      the maximum of the values in this array.
    • max

      public static double max(long[] array, int N)
      Parameters:
      array - a long array.
      N - the number of values of array which should be considered.
      Returns:
      the maximum of the first N values in this array.
    • max

      public static double max(double[] array, int N)
      Parameters:
      array - a double array.
      N - the number of values of array which should be considered.
      Returns:
      the maximum of the first N values in this array.
    • range

      public static double range(long[] array)
      Parameters:
      array - a long array.
      Returns:
      the range of the values in this array.
    • range

      public static double range(double[] array)
      Parameters:
      array - a double array.
      Returns:
      the range of the values in this array.
    • range

      public static double range(long[] array, int N)
      Parameters:
      array - a long array.
      N - the number of values of array which should be considered.
      Returns:
      the range of the first N values in this array.
    • range

      public static double range(double[] array, int N)
      Parameters:
      array - a double array.
      N - the number of values of array which should be considered.
      Returns:
      the range of the first N values in this array.
    • N

      public static int N(long[] array)
      Parameters:
      array - a long array.
      Returns:
      the length of this array.
    • N

      public static int N(double[] array)
      Parameters:
      array - a double array.
      Returns:
      the length of this array.
    • ssx

      public static double ssx(long[] array)
      Parameters:
      array - a long array.
      Returns:
      the sum of the squared differences from the mean in array.
    • ssx

      public static double ssx(double[] array)
      Parameters:
      array - a double array.
      Returns:
      the sum of the squared differences from the mean in array.
    • ssx

      public static double ssx(long[] array, int N)
      Parameters:
      array - a long array.
      N - the number of values of array which should be considered.
      Returns:
      the sum of the squared differences from the mean of the first N values in array.
    • ssx

      public static double ssx(double[] array, int N)
      Parameters:
      array - a double array.
      N - the number of values of array which should be considered.
      Returns:
      the sum of the squared differences from the mean of the first N values in array.
    • sxy

      public static double sxy(long[] array1, long[] array2)
      Parameters:
      array1 - a long array.
      array2 - a long array, same length as array1.
      Returns:
      the sum of the squared differences of the products from the products of the sample means for array1 and array2..
    • sxy

      public static double sxy(double[] array1, double[] array2)
      Parameters:
      array1 - a double array.
      array2 - a double array, same length as array1.
      Returns:
      the sum of the squared differences of the products from the products of the sample means for array1 and array2..
    • sxy

      public static double sxy(long[] array1, long[] array2, int N)
      Parameters:
      array1 - a long array.
      array2 - a long array.
      N - the number of values of array which should be considered.
      Returns:
      the sum of the squared differences of the products from the products of the sample means for the first N values in array1 and array2..
    • sxy

      public static double sxy(double[] array1, double[] array2, int N)
      Parameters:
      array1 - a double array.
      array2 - a double array.
      N - the number of values of array which should be considered.
      Returns:
      the sum of the squared differences of the products from the products of the sample means for the first N values in array1 and array2..
    • sxy

      public static double sxy(Vector data1, Vector data2, int N)
      Parameters:
      data1 - a column vector of doubles.
      data2 - a column vector of doubles.
      N - the number of values of array which should be considered.
      Returns:
      the sum of the squared differences of the products from the products of the sample means for the first N values in array1 and array2..
    • variance

      public static double variance(long[] array)
      Parameters:
      array - a long array.
      Returns:
      the variance of the values in array.
    • variance

      public static double variance(double[] array)
      Parameters:
      array - a double array.
      Returns:
      the variance of the values in array.
    • variance

      public static double variance(long[] array, int N)
      Parameters:
      array - a long array.
      N - the number of values of array which should be considered.
      Returns:
      the variance of the first N values in array.
    • variance

      public static double variance(double[] array, int N)
      Parameters:
      array - a double array.
      N - the number of values of array which should be considered.
      Returns:
      the variance of the first N values in array.
    • sd

      public static double sd(long[] array)
      Parameters:
      array - a long array.
      Returns:
      the standard deviation of the values in array.
    • sd

      public static double sd(double[] array)
      Parameters:
      array - a double array.
      Returns:
      the standard deviation of the values in array.
    • sd

      public static double sd(long[] array, int N)
      Parameters:
      array - a long array.
      N - the number of values of array which should be considered.
      Returns:
      the standard deviation of the first N values in array.
    • sd

      public static double sd(double[] array, int N)
      Parameters:
      array - a double array.
      N - the number of values of array which should be considered.
      Returns:
      the standard deviation of the first N values in array.
    • covariance

      public static double covariance(long[] array1, long[] array2)
      Parameters:
      array1 - a long array.
      array2 - a second long array (same length as array1).
      Returns:
      the covariance of the values in array.
    • covariance

      public static double covariance(double[] array1, double[] array2)
      Parameters:
      array1 - a double array.
      array2 - a second double array (same length as array1).
      Returns:
      the covariance of the values in array.
    • covariance

      public static double covariance(long[] array1, long[] array2, int N)
      Parameters:
      array1 - a long array.
      array2 - a second long array.
      N - the number of values to be considered in array1 and array2.
      Returns:
      the covariance of the first N values in array1 and array2.
    • covariance

      public static double covariance(double[] array1, double[] array2, int N)
      Parameters:
      array1 - a double array.
      array2 - a second double array (same length as array1).
      N - the number of values to be considered in array1 and array2.
      Returns:
      the covariance of the first N values in array1 and array2.
    • correlation

      public static double correlation(long[] array1, long[] array2)
      Parameters:
      array1 - a long array.
      array2 - a second long array (same length as array1).
      Returns:
      the Pearson's correlation of the values in array1 and array2.
    • correlation

      public static double correlation(double[] array1, double[] array2)
      Parameters:
      array1 - a double array.
      array2 - a second double array (same length as array1).
      Returns:
      the Pearson's correlation of the values in array1 and array2.
    • correlation

      public static double correlation(Vector data1, Vector data2)
    • compressedCorrelation

      public static short compressedCorrelation(Vector data1, Vector data2)
    • correlation

      public static double correlation(long[] array1, long[] array2, int N)
      Parameters:
      array1 - a long array.
      array2 - a second long array.
      N - the number of values to be considered in array1 and array2.
      Returns:
      the Pearson's correlation of the first N values in array1 and array2.
    • correlation

      public static double correlation(double[] array1, double[] array2, int N)
      Parameters:
      array1 - a double array.
      array2 - a second double array.
      N - the number of values to be considered in array1 and array2.
      Returns:
      the Pearson correlation of the first N values in array1 and array2.
    • rankCorrelation

      public static double rankCorrelation(double[] arr1, double[] arr2)
    • kendallsTau

      public static double kendallsTau(double[] x, double[] y)
    • getRanks

      public static double[] getRanks(double[] arr)
    • sSquare

      public static double sSquare(long[] array)
      Parameters:
      array - a long array.
      Returns:
      the unbaised estimate of the variance of the distribution of the values in array asuming the mean is unknown.
    • sSquare

      public static double sSquare(double[] array)
      Parameters:
      array - a double array.
      Returns:
      the unbaised estimate of the variance of the distribution of the values in array asuming the mean is unknown.
    • sSquare

      public static double sSquare(long[] array, int N)
      Parameters:
      array - a long array.
      N - the number of values to be considered in array.
      Returns:
      the unbaised estimate of the variance of the distribution of the first N values in array asuming the mean is unknown.
    • sSquare

      public static double sSquare(double[] array, int N)
      Parameters:
      array - a double array.
      N - the number of values to be considered in array.
      Returns:
      the unbaised estimate of the variance of the distribution of the first N values in array asuming the mean is unknown.
    • varHat

      public static double varHat(long[] array)
      Parameters:
      array - a long array.
      Returns:
      the unbaised estimate of the variance of the distribution of the values in array asuming the mean is known.
    • varHat

      public static double varHat(double[] array)
      Parameters:
      array - a double array.
      Returns:
      the unbaised estimate of the variance of the distribution of the values in array asuming the mean is known.
    • varHat

      public static double varHat(long[] array, int N)
      Parameters:
      array - a long array.
      N - the number of values to be considered in array.
      Returns:
      the unbaised estimate of the variance of the distribution of the first N values in array asuming the mean is known.
    • varHat

      public static double varHat(double[] array, int N)
      Parameters:
      array - a double array.
      N - the number of values to be considered in array.
      Returns:
      the unbaised estimate of the variance of the distribution of the first N values in array asuming the mean is known.
    • mu

      public static double mu(long[] array)
      Parameters:
      array - a long array.
      Returns:
      the unbaised estimate of the mean of the distribution of the values in array.
    • mu

      public static double mu(double[] array)
      Parameters:
      array - a double array.
      Returns:
      the unbaised estimate of the mean of the distribution of the values in array.
    • mu

      public static double mu(long[] array, int N)
      Parameters:
      array - a long array.
      N - the number of values to be considered in array.
      Returns:
      the unbaised estimate of the mean of the distribution of the first N values in array.
    • mu

      public static double mu(double[] array, int N)
      Parameters:
      array - a double array.
      N - the number of values to be considered in array.
      Returns:
      the unbaised estimate of the mean of the distribution of the first N values in array.
    • muHat

      public static double muHat(long[] array)
      Parameters:
      array - a long array.
      Returns:
      the maximum likelihood estimate of the mean of the distribution of the values in array.
    • muHat

      public static double muHat(double[] array)
      Parameters:
      array - a double array.
      Returns:
      the maximum likelihood estimate of the mean of the distribution of the values in array.
    • muHat

      public static double muHat(long[] array, int N)
      Parameters:
      array - a long array.
      N - the number of values to be considered in array.
      Returns:
      the maximum likelihood estimate of the mean of the distribution of the first N values in array.
    • muHat

      public static double muHat(double[] array, int N)
      Parameters:
      array - a long array.
      N - the number of values to be considered in array.
      Returns:
      the maximum likelihood estimate of the mean of the distribution of the first N values in array.
    • averageDeviation

      public static double averageDeviation(long[] array)
      Parameters:
      array - a long array.
      Returns:
      the average deviation of the values in array.
    • averageDeviation

      public static double averageDeviation(double[] array)
      Parameters:
      array - a double array.
      Returns:
      the average deviation of the values in array.
    • averageDeviation

      public static double averageDeviation(long[] array, int N)
      Parameters:
      array - a long array.
      N - the number of values to be considered in array.
      Returns:
      the average deviation of the first N values in array.
    • averageDeviation

      public static double averageDeviation(double[] array, int N)
      Parameters:
      array - a double array.
      N - the number of values to be considered in array.
      Returns:
      the average deviation of the first N values in array.
    • skewness

      public static double skewness(long[] array)
      Parameters:
      array - a long array.
      Returns:
      the skew of the values in array.
    • skewness

      public static double skewness(double[] array)
      Parameters:
      array - a double array.
      Returns:
      the skew of the values in array.
    • skewness

      public static double skewness(long[] array, int N)
      Parameters:
      array - a long array.
      N - the number of values of array which should be considered.
      Returns:
      the skew of the first N values in array.
    • skewness

      public static double skewness(double[] array, int N)
      Parameters:
      array - a double array.
      N - the number of values of array which should be considered.
      Returns:
      the skew of the first N values in array.
    • removeNaN

      public static double[] removeNaN(double[] x1)
    • kurtosis

      public static double kurtosis(long[] array)
      Parameters:
      array - a long array.
      Returns:
      the kurtosis of the values in array.
    • kurtosis

      public static double kurtosis(double[] array)
      Parameters:
      array - a double array.
      Returns:
      the curtosis of the values in array.
    • kurtosis

      public static double kurtosis(long[] array, int N)
      Parameters:
      array - a long array.
      N - the number of values of array which should be considered.
      Returns:
      the curtosis of the first N values in array.
    • standardizedFifthMoment

      public static double standardizedFifthMoment(double[] array)
    • standardizedFifthMoment

      public static double standardizedFifthMoment(double[] array, int N)
    • standardizedSixthMoment

      public static double standardizedSixthMoment(double[] array)
    • standardizedSixthMoment

      public static double standardizedSixthMoment(double[] array, int N)
    • kurtosis

      public static double kurtosis(double[] array, int N)
      Parameters:
      array - a double array.
      N - the number of values of array which should be considered.
      Returns:
      the curtosis of the first N values in array.
    • gamma

      public static double gamma(double z)
      GAMMA FUNCTION (From DStat, used by permission).

      Calculates the value of gamma(double z) using Handbook of Mathematical Functions AMS 55 by Abromowitz page 256.

      Parameters:
      z - nonnegative double value.
      Returns:
      the gamma value of z.
    • beta

      public static double beta(double x1, double x2)
      Calculates the value of beta for doubles
      Parameters:
      x1 - the first double
      x2 - the second double.
      Returns:
      beta(x1, x2).
    • igamma

      public static double igamma(double a, double x)
      Calculates the incomplete gamma function for two doubles
      Parameters:
      a - first double.
      x - second double.
      Returns:
      incomplete gamma of (a, x).
    • erf

      public static double erf(double x)
      Calculates the error function for a double
      Parameters:
      x - argument.
      Returns:
      error function of this argument.
    • poisson

      public static double poisson(double k, double x, boolean cum)
      Calculates the Poisson Distribution for mean x and k events for doubles. If third parameter is boolean true, the cumulative Poisson function is returned.
      Parameters:
      k - # events
      x - mean
      cum - true if the cumulative Poisson is desired.
      Returns:
      the value of the Poisson (or cumPoisson) at x.
    • chidist

      public static double chidist(double x, int degreesOfFreedom)
      Calculates the one-tail probability of the Chi-squared distribution for doubles
      Returns:
      value of Chi at x with the stated degrees of freedom.
    • dieToss

      public static int dieToss(int n)
    • fdrCutoff

      public static double fdrCutoff(double alpha, List<Double> pValues, boolean negativelyCorrelated, boolean pSorted)
      Calculates the cutoff value for p-values using the FDR method. Hypotheses with p-values less than or equal to this cutoff should be rejected according to the test.
      Parameters:
      alpha - The desired effective significance level.
      pValues - An list containing p-values to be tested in positions 0, 1, ..., n. (The rest of the array is ignored.) Note: This array will not be changed by this class. Its values are copied into a separate array before sorting.
      negativelyCorrelated - Whether the p-values in the array pValues are negatively correlated (true if yes, false if no). If they are uncorrelated, or positively correlated, a level of alpha is used; if they are not correlated, a level of alpha / SUM_i=1_n(1 / i) is used.
      Returns:
      the FDR alpha, which is the first p-value sorted high to low to fall below a line from (1.0, level) to (0.0, 0.0). Hypotheses less than or equal to this p-value should be rejected.
    • fdrCutoff

      public static double fdrCutoff(double alpha, List<Double> pValues, boolean negativelyCorrelated)
    • fdrCutoff

      public static double fdrCutoff(double alpha, List<Double> pValues, int[] _k, boolean negativelyCorrelated, boolean pSorted)
    • fdr

      public static int fdr(double alpha, List<Double> pValues)
      Returns:
      the index, >=, in the sorted list of p values of which all p values are rejected. It the index is -1, all p values are rejected.
    • fdr

      public static int fdr(double alpha, List<Double> pValues, boolean negativelyCorrelated, boolean pSorted)
    • fdrQ

      public static double fdrQ(List<Double> pValues, int k)
    • partialCovarianceWhittaker

      public static double partialCovarianceWhittaker(Matrix submatrix)
      Assumes that the given covariance matrix was extracted in such a way that the order of the variables (in either direction) is X, Y, Z1, ..., Zn, where the partial covariance one wants is covariance(X, Y | Z1,...,Zn). This may be extracted using DataUtils.submatrix().
      Returns:
      the given partial covariance.
    • partialCovarianceWhittaker

      public static double partialCovarianceWhittaker(Matrix covariance, int x, int y, int... z)
      Returns:
      the partial covariance(x, y | z) where these represent the column/row indices of the desired variables in covariance
    • partialVariance

      public static double partialVariance(Matrix covariance, int x, int... z)
    • partialStandardDeviation

      public static double partialStandardDeviation(Matrix covariance, int x, int... z)
    • partialCorrelation

      public static double partialCorrelation(Matrix submatrix) throws org.apache.commons.math3.linear.SingularMatrixException
      Assumes that the given covariance matrix was extracted in such a way that the order of the variables (in either direction) is X, Y, Z1, ..., Zn, where the partial correlation one wants is correlation(X, Y | Z1,...,Zn). This may be extracted using DataUtils.submatrix().
      Returns:
      the given partial correlation.
      Throws:
      org.apache.commons.math3.linear.SingularMatrixException
    • partialCorrelationPrecisionMatrix

      public static double partialCorrelationPrecisionMatrix(Matrix submatrix) throws org.apache.commons.math3.linear.SingularMatrixException
      Throws:
      org.apache.commons.math3.linear.SingularMatrixException
    • partialCorrelation

      public static double partialCorrelation(Matrix covariance, int x, int y, int... z)
      Returns:
      the partial correlation(x, y | z) where these represent the column/row indices of the desired variables in covariance
    • logCoshScore

      public static double logCoshScore(double[] _f)
    • meanAbsolute

      public static double meanAbsolute(double[] _f)
    • pow

      public static double pow()
    • expScore

      public static double expScore(double[] _f)
    • logCoshExp

      public static double logCoshExp()
    • entropy

      public static double entropy(int numBins, double[] _f)
    • maxEntApprox

      public static double maxEntApprox(double[] x)
    • standardizeData

      public static double[] standardizeData(double[] data)
    • factorial

      public static double factorial(int c)
    • getZForAlpha

      public static double getZForAlpha(double alpha)
    • logsum

      public static double logsum(List<Double> logs)
    • sum

      public static double sum(double[] x)
    • cov

      public static double[] cov(double[] x, double[] y, double[] condition, double threshold, double direction)
    • covMatrix

      public static double[][] covMatrix(double[] x, double[] y, double[][] z, double[] condition, double threshold, double direction)
    • getRows

      public static List<Integer> getRows(double[] x, double threshold, double direction)
    • getRows

      public static List<Integer> getRows(double[] x, double[] condition, double threshold, double direction)
    • E

      public static double[] E(double[] x, double[] y, double[] condition, double threshold, double direction)