Class CorrelationStats


  • public class CorrelationStats
    extends Object
    Statistical evaluation and transformation tools for correlations.
    Author:
    Paul Pavlidis
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double byteToCorrel​(int correlByte)  
      static double byteToPvalue​(int pvalByte)  
      static double compare​(double correl1, int n1, double correl2, int n2)
      Statistical comparison of two Pearson correlations.
      static double correl​(double[] ival, double[] jval)
      Compute the Pearson correlation, missing values are permitted.
      static int correlAsByte​(double correl)  
      static double correlationForPvalue​(double pval, int count)
      Find the approximate Pearson correlation required to meet a particular pvalue.
      static double correlationTstat​(double correl, int dof)
      Compute the t-statistic associated with a Pearson correlation.
      static double correlFast​(double[] ival, double[] jval, double meani, double meanj, double sqrti, double sqrtj)
      Compute Pearson correlation when there are no missing values.
      static double fisherTransform​(double r)
      Compute the Fisher z transform of the Pearson correlation.
      static cern.colt.list.DoubleArrayList fisherTransform​(cern.colt.list.DoubleArrayList e)
      Fisher-transform a list of Pearson correlations.
      static boolean isValidPearsonCorrelation​(double r)
      Test if a value is a reasonable Pearson correlation (in the range -1 to 1; values outside of this range are acceptable within a small roundoff.
      static double pvalue​(double correl, int count)
      Compute pvalue for the pearson correlation, using the t distribution method.
      static int pvalueAsByte​(double correl, int count)
      Convert a p value into a value between 0 and 255 inclusive.
      static double spearmanPvalue​(double correl, int count)  
      static double unFisherTransform​(double z)
      Reverse the Fisher z-transform of Pearson correlations
    • Constructor Detail

      • CorrelationStats

        public CorrelationStats()
    • Method Detail

      • byteToCorrel

        public static double byteToCorrel​(int correlByte)
        Parameters:
        correlByte - int
        Returns:
        double
      • byteToPvalue

        public static double byteToPvalue​(int pvalByte)
        Parameters:
        pvalByte - int
        Returns:
        double
      • compare

        public static double compare​(double correl1,
                                     int n1,
                                     double correl2,
                                     int n2)
        Statistical comparison of two Pearson correlations. Assumes data are bivariate normal. Null hypothesis is that the two correlations are equal. See Zar (Biostatistics)
        Parameters:
        correl1 - First correlation
        n1 - Number of values used to compute correl1
        correl2 - Second correlation
        n2 - Number of values used to compute correl2
        Returns:
        double p value.
      • correl

        public static double correl​(double[] ival,
                                    double[] jval)
        Compute the Pearson correlation, missing values are permitted.
        Parameters:
        ival -
        jval -
        Returns:
      • correlAsByte

        public static int correlAsByte​(double correl)
        Parameters:
        correl - double
        Returns:
        int
      • correlationForPvalue

        public static double correlationForPvalue​(double pval,
                                                  int count)
        Find the approximate Pearson correlation required to meet a particular pvalue. If the pvalue is <=0 or >= 1, returns 1 and 0 respectively.
        Parameters:
        pval - double
        count - int
        Returns:
        double
      • correlationTstat

        public static double correlationTstat​(double correl,
                                              int dof)
        Compute the t-statistic associated with a Pearson correlation.
        Parameters:
        correl - Pearson correlation
        dof - Degrees of freedom (n - 2)
        Returns:
        double
      • correlFast

        public static double correlFast​(double[] ival,
                                        double[] jval,
                                        double meani,
                                        double meanj,
                                        double sqrti,
                                        double sqrtj)
        Compute Pearson correlation when there are no missing values.
        Parameters:
        ival -
        jval -
        meani -
        meanj -
        sqrti -
        sqrtj -
        Returns:
      • fisherTransform

        public static double fisherTransform​(double r)
        Compute the Fisher z transform of the Pearson correlation.
        Parameters:
        r - Correlation coefficient.
        Returns:
        Fisher transform of the Correlation.
      • fisherTransform

        public static cern.colt.list.DoubleArrayList fisherTransform​(cern.colt.list.DoubleArrayList e)
        Fisher-transform a list of Pearson correlations.
        Parameters:
        e -
        Returns:
      • isValidPearsonCorrelation

        public static boolean isValidPearsonCorrelation​(double r)
        Test if a value is a reasonable Pearson correlation (in the range -1 to 1; values outside of this range are acceptable within a small roundoff.
        Parameters:
        r -
        Returns:
      • pvalue

        public static double pvalue​(double correl,
                                    int count)
        Compute pvalue for the pearson correlation, using the t distribution method.
        Parameters:
        correl - Pearson correlation.
        count - Number of items used to calculate the correlation. NOT the degrees of freedom.
        Returns:
        double one-side pvalue
      • pvalueAsByte

        public static int pvalueAsByte​(double correl,
                                       int count)
        Convert a p value into a value between 0 and 255 inclusive. This is done by taking the log, multiplying it by a fixed value (currently 8). This means that pvalues less than 10^-32 are rounded to 10^-32.
        Parameters:
        correl - double
        count - int
        Returns:
        int
      • spearmanPvalue

        public static double spearmanPvalue​(double correl,
                                            int count)
        Parameters:
        correl - Spearman's correlation
        count -
        Returns:
        pvalue, two-tailed pvalue, computed using t distribution for large sample sizes or exact computation for small sample sizes.
      • unFisherTransform

        public static double unFisherTransform​(double z)
        Reverse the Fisher z-transform of Pearson correlations
        Parameters:
        z -
        Returns:
        r