Record Class TTest

java.lang.Object
java.lang.Record
smile.stat.hypothesis.TTest
Record Components:
method - the type of test.
t - the t-statistic.
df - the degree of freedom.
pvalue - the p-value.

public record TTest(String method, double t, double df, double pvalue) extends Record
Student's t test. A t-test is any statistical hypothesis test in which the test statistic has a Student's t distribution if the null hypothesis is true. It is applied when the population is assumed to be normally distributed but the sample sizes are small enough that the statistic on which inference is based is not normally distributed because it relies on an uncertain estimate of standard deviation rather than on a precisely known value.

Among the most frequently used t tests are:

  • A test of whether the mean of a normally distributed population has a value specified in a null hypothesis.
  • A test of the null hypothesis that the means of two normally distributed populations are equal. Given two data sets, each characterized by its mean, standard deviation and number of data points, we can use some kind of t test to determine whether the means are distinct, provided that the underlying distributions can be assumed to be normal. All such tests are usually called Student's t tests, though strictly speaking that name should only be used if the variances of the two populations are also assumed to be equal; the form of the test used when this assumption is dropped is sometimes called Welch's t test. There are different versions of the t test depending on whether the two samples are
    • unpaired, independent of each other (e.g., individuals randomly assigned into two groups, measured after an intervention and compared with the other group),
    • or paired, so that each member of one sample has a unique relationship with a particular member of the other sample (e.g., the same people measured before and after an intervention).
    If the calculated p-value is below the threshold chosen for statistical significance (usually 0.05 or 0.01 level), then the null hypothesis which usually states that the two groups do not differ is rejected in favor of an alternative hypothesis, which typically states that the groups do differ.
  • A test of whether the slope of a regression line differs significantly from 0.
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    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.
    Returns the value of the method record component.
    double
    Returns the value of the pvalue record component.
    double
    t()
    Returns the value of the t record component.
    static TTest
    test(double[] x, double mean)
    Independent one-sample t-test whether the mean of a normally distributed population has a value specified in a null hypothesis.
    static TTest
    test(double[] x, double[] y)
    Test if the arrays x and y have significantly different means.
    static TTest
    test(double[] x, double[] y, boolean equalVariance)
    Test if the arrays x and y have significantly different means.
    static TTest
    test(double r, int df)
    Test whether the Pearson correlation coefficient, the slope of a regression line, differs significantly from 0.
    static TTest
    testPaired(double[] x, double[] y)
    Given the paired arrays x and y, test if they have significantly different means.
    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

    • TTest

      public TTest(String method, double t, double df, double pvalue)
      Creates an instance of a TTest record class.
      Parameters:
      method - the value for the method 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
    • test

      public static TTest test(double[] x, double mean)
      Independent one-sample t-test whether the mean of a normally distributed population has a value specified in a null hypothesis. Small values of p-value indicate that the array has significantly different mean.
      Parameters:
      x - the sample values.
      mean - the mean.
      Returns:
      the test results.
    • test

      public static TTest test(double[] x, double[] y)
      Test if the arrays x and y have significantly different means. The data arrays are assumed to be drawn from populations with unequal variances. Small values of p-value indicate that the two arrays have significantly different means.
      Parameters:
      x - the sample values.
      y - the sample values.
      Returns:
      the test results.
    • test

      public static TTest test(double[] x, double[] y, boolean equalVariance)
      Test if the arrays x and y have significantly different means. Small values of p-value indicate that the two arrays have significantly different means.
      Parameters:
      x - the sample values.
      y - the sample values.
      equalVariance - true if the data arrays are assumed to be drawn from populations with the same true variance. Otherwise, The data arrays are allowed to be drawn from populations with unequal variances.
      Returns:
      the test results.
    • testPaired

      public static TTest testPaired(double[] x, double[] y)
      Given the paired arrays x and y, test if they have significantly different means. Small values of p-value indicate that the two arrays have significantly different means.
      Parameters:
      x - the sample values.
      y - the sample values.
      Returns:
      the test results.
    • test

      public static TTest test(double r, int df)
      Test whether the Pearson correlation coefficient, the slope of a regression line, differs significantly from 0. Small values of p-value indicate a significant correlation.
      Parameters:
      r - the Pearson correlation coefficient.
      df - the degree of freedom. df = n - 2, where n is the number of samples used in the calculation of r.
      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
    • 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