Record Class CorTest

java.lang.Object
java.lang.Record
smile.stat.hypothesis.CorTest
Record Components:
method - the type of correlation.
cor - the correlation coefficient.
t - the t-statistic.
df - the degree of freedom. It is set to 0 in case of Kendall test as the test is non-parametric.
pvalue - the two-sided p-value.

public record CorTest(String method, double cor, double t, double df, double pvalue) extends Record
Correlation test. Correlation of two variables is a measure of the degree to which they vary together. More accurately, correlation is the covariation of standardized variables. In positive correlation, as one variable increases, so also does the other. In negative correlation, as one variable increases, the other variable decreases. Perfect positive correlation usually is calculated as a value of 1 (or 100%). Perfect negative correlation usually is calculated as a value of -1. A values of zero shows no correlation at all.

Three common types of correlation are Pearson, Spearman (for ranked data) and Kendall (for uneven or multiple rankings).

To deal with measures of association between nominal variables, we can use Chi-square test for independence. For any pair of nominal variables, the data can be displayed as a contingency table, whose rows are labels by the values of one nominal variable, whose columns are labels by the values of the other nominal variable, and whose entries are non-negative integers giving the number of observed events for each combination of row and column.

  • Constructor Summary

    Constructors
    Constructor
    Description
    CorTest(String method, double cor, double t, double df, double pvalue)
    Creates an instance of a CorTest record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    cor()
    Returns the value of the cor record component.
    double
    df()
    Returns the value of the df record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    static CorTest
    kendall(double[] x, double[] y)
    Kendall rank correlation test.
    Returns the value of the method record component.
    static CorTest
    pearson(double[] x, double[] y)
    Pearson correlation coefficient test.
    double
    Returns the value of the pvalue record component.
    static CorTest
    spearman(double[] x, double[] y)
    Spearman rank correlation coefficient test.
    double
    t()
    Returns the value of the t record component.
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • CorTest

      public CorTest(String method, double cor, double t, double df, double pvalue)
      Creates an instance of a CorTest record class.
      Parameters:
      method - the value for the method record component
      cor - the value for the cor record component
      t - the value for the t record component
      df - the value for the df record component
      pvalue - the value for the pvalue record component
  • Method Details

    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • pearson

      public static CorTest pearson(double[] x, double[] y)
      Pearson correlation coefficient test.
      Parameters:
      x - the sample values.
      y - the sample values.
      Returns:
      the test results.
    • spearman

      public static CorTest spearman(double[] x, double[] y)
      Spearman rank correlation coefficient test. The Spearman Rank Correlation Coefficient is a form of the Pearson coefficient with the data converted to rankings (i.e. when variables are ordinal). It can be used when there is non-parametric data and hence Pearson cannot be used.

      The raw scores are converted to ranks and the differences between the ranks of each observation on the two variables are calculated.

      The p-value is calculated by approximation, which is good for n > 10.

      Parameters:
      x - the sample values.
      y - the sample values.
      Returns:
      the test results.
    • kendall

      public static CorTest kendall(double[] x, double[] y)
      Kendall rank correlation test. The Kendall Tau Rank Correlation Coefficient is used to measure the degree of correspondence between sets of rankings where the measures are not equidistant. It is used with non-parametric data. The p-value is calculated by approximation, which is good for n > 10.
      Parameters:
      x - the sample values.
      y - the sample values.
      Returns:
      the test results.
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • method

      public String method()
      Returns the value of the method record component.
      Returns:
      the value of the method record component
    • cor

      public double cor()
      Returns the value of the cor record component.
      Returns:
      the value of the cor record component
    • t

      public double t()
      Returns the value of the t record component.
      Returns:
      the value of the t record component
    • df

      public double df()
      Returns the value of the df record component.
      Returns:
      the value of the df record component
    • pvalue

      public double pvalue()
      Returns the value of the pvalue record component.
      Returns:
      the value of the pvalue record component