Class WelchsTStat

java.lang.Object
org.bzdev.math.stats.Statistic
org.bzdev.math.stats.WelchsTStat

public class WelchsTStat extends Statistic
Statistic for Welch's T Test. Welch's t-test compares two independent data sets X1 and X2 to determine if a difference in their mean values is statistically significant.

The statistic (See https://www.datanovia.com/en/lessons/types-of-t-test/unpaired-t-test/welch-t-test/) is $$t = \frac{\mbox{x̅}_1 - \mbox{x̅}_2}{ \sqrt{\frac{s_{X_1}^2}{n_1} + \frac{s_{X_2}^2}{n_2}} }$$ where

  • $\mbox{x̅}_1$ is the mean for data set X1.
  • $\mbox{x̅}_2$ is the mean for data set X2.
  • sX1 is the sample standard deviation for data set X1.
  • sX2 is the sample standard deviation for data set X2.
  • n1 is the size of data set X1
  • n2 is the size of data set X2
The number of degrees of freedom $\nu$ is approximated by the equation $$\nu \approx \frac{(\frac{s_{X_1}^2}{n_1} + \frac{s_{X_2}^2}{n_2})^2}{ \frac{s_{X_1}^4}{n_1^2\nu_1} + \frac{s_{X_2}^4}{n_2^2\nu_2} }$$ ν ≅ (sX12/n1 + sX22/n2)2 / (sX14/(n1ν1 + sX24/n2)2ν1), where
  • ν1 = n1 - 1,
  • ν2 = n2 - 1,
and is rounded down to an integral value.
  • Constructor Details

    • WelchsTStat

      public WelchsTStat()
      Constructor. To add data to each of the two data sets X1 and X2, the methods add1(double) and add2(double) must be used.
    • WelchsTStat

      public WelchsTStat(double mean1, double variance1, long n1, double mean2, double variance2, long n2)
      Constructor given a description of two data sets.
      Parameters:
      mean1 - the mean value of the first data set
      variance1 - the sample variance of the first data set
      n1 - the size of the first data set
      mean2 - the mean value of the second data set
      variance2 - the sample variance of the second data set
      n2 - the size of the second data set
    • WelchsTStat

      public WelchsTStat(double[] x1, double[] x2)
      Constructor given two data sets. Additional data can be added by calling the methods add1(double) and add2(double).
      Parameters:
      x1 - values to add to data set X1
      x2 - values to add to data-set X2
  • Method Details

    • setDegreesOfFreedom

      protected void setDegreesOfFreedom(double d)
      Set the number of degrees of freedom for this instance. This must be called by a subclass whenever the statistics are updated.
      Parameters:
      d - the degrees of freedom; 0 no data is available
    • getDegreesOfFreedom

      public double getDegreesOfFreedom()
      Get the number of degrees of freedom for this instance.
      Returns:
      the number of degress of freedom
    • getDistribution

      public ProbDistribution getDistribution()
      Description copied from class: Statistic
      Get the probability distribution for this statistic. The distribution is the distribution for the statistic, not the the distribution for the data the statistic describes.
      Specified by:
      getDistribution in class Statistic
      Returns:
      the probability distribution
    • add1

      public void add1(double x1)
      Add an entry to data set X1.
      Parameters:
      x1 - the value to add
    • add2

      public void add2(double x2)
      Add an entry to data set X2.
      Parameters:
      x2 - the value to add
    • getMean1

      public double getMean1()
      Get the mean for data-set 1.
      Returns:
      the mean for data-set 1
    • getSDev1

      public double getSDev1()
      Get the sample standard deviation for data-set 1.
      Returns:
      the standard deviation for data-set 1
    • getMean2

      public double getMean2()
      Get the mean for data-set 2.
      Returns:
      an object that records the mean and standard deviation for data-set 2
    • getSDev2

      public double getSDev2()
      Get the sample standard deviation for data-set 2.
      Returns:
      the sample standard deviation for data-set 2
    • getValue

      public double getValue()
      Get the value of the statistic.
      Specified by:
      getValue in class Statistic
      Returns:
      the value of the statistic
    • getNCParameter

      public double getNCParameter(double diff)
      Get the noncentrality parameter given a difference in mean values. Two-Sample T-Tests Allowing Unequal Variance describes how to compute the noncentrality parameter. The difference is equal to μ1 - μ0 where μ0 = 0 (the value assumed by the null hypothesis H0) and μ1 is the value assumed by an alternate hypothesis H1.
      Overrides:
      getNCParameter in class Statistic
      Parameters:
      diff - the difference of the H1 mean value and the H0 mean value.
      Returns:
      the noncentrality parameter