Class StudentsTStat.Mean2

Enclosing class:
StudentsTStat

public static class StudentsTStat.Mean2 extends StudentsTStat
Statistic for Student's t-test for the comparison of two means given independent samples with the same variance.

The test determines if the difference between the mean values for two data sets is statistically significant.

" Student's t-test: Comparison of two means" has a description of the test. If the data sets are X1 and X2, then the statistic is $$t =\frac{\mbox{x̅}_1 - \mbox{x̅}_2}{ s_{X_1X_2}\sqrt{\frac{1}{n_1} + \frac{1}{n_2}}}$$ where

  • $s_{X_1X_2} = \sqrt{\frac{(n_1-1)s_{X_1}^2 + (n_2-1)s_{X_2}^2}{ n_1 + n_2 - 2}}$.
  • $\mbox{x̅}_1$ is the mean for the data set $X_1$.
  • $\mbox{x̅}_2$ is the mean for the data set $X_2$.
  • $n_1$ is the size of the data set $X_1$.
  • $n_2$ is the size of the data set $X_2$.
  • $s_{X_1}$ is the sample standard deviation for the data set $X_1$.
  • $s_{X_2}$ is the sample standard deviation for the data set $X_2$.
The notation differs slightly from that used in the citations due to a bug in mathjax that prevents overlines from being displayed reliably, and as a result, upper-case X was changed to a lower-case x when there is a bar over it.
  • Constructor Details

    • Mean2

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

      public Mean2(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
    • Mean2

      public Mean2(double[] a, double[] b)
      Constructor given two data sets.
      Parameters:
      a - values to add to data set A
      b - values to add to data set B
  • Method Details

    • add1

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

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

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

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

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

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

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

      public double getNCParameter(double diff)
      Description copied from class: StudentsTStat
      Get the noncentrality parameter given a difference in mean values. A Student's t-test can typically be written as $$ T = \frac{\mbox{x̅} - \mu_0}{ \frac{\sigma}{\sqrt{n}} \sqrt{\frac{S}{\sigma^2\nu}} }$$ where ν is the number of degrees of freedom, σ is the population standard deviation of a random variable for which x is the sample mean of X, μ0 is the population mean of X, n is the sample size, and S is a sum of squares. Note that $\sqrt{\frac{S}{\sigma^2\nu}}$ will be the sample standard deviation for a suitable choice of ν.

      If we set θ = μ1 - μ0, we can express T as $$T = \frac{\mbox{x̅} - \mu_0 +\theta - \theta }{ \frac{\sigma}{\sqrt{n}} \frac{S/\sigma^2}{\sqrt{\nu}} }$$ or $$T = \frac{\mbox{x̅} - \mu_1 + \theta }{ \frac{\sigma}{\sqrt{n}} \frac{S/\sigma^2}{\sqrt{\nu}} } \ .$$ If we set $Z = \frac{\mbox{x̅} - \mu_1}{\sigma/\sqrt{n}}$ and $\mu = \frac{\theta}{\sigma/\sqrt{n}}$, then T can be written as $\frac{Z+\mu}{\sqrt{V/\nu}}$. If the actual mean is μ1, then Z has a normal distribution with a mean of zero and a variance of 1. Meanwhile V has a χ2 distribution with ν degrees of freedom, and Z and V are independent. Consequently, the random variable $\frac{Z + \mu}{\sqrt{V/\nu}}$ has a noncentral t distribution characterized by the number of degrees of freedom ν and the noncentrality parameter μ.

      For citations for specific cases, please see

      The notation in this documentation will differ slightly due to the use of a lower-case x instead of an upper-case X as part of a work-around for a mathjax bug involving the LaTeX 'overline' command.
      Specified by:
      getNCParameter in class StudentsTStat
      Parameters:
      diff - the difference of the H1 mean value and the H0 mean value.
      Returns:
      the noncentrality parameter