- Enclosing class:
- StudentsTStat
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$.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.bzdev.math.stats.StudentsTStat
StudentsTStat.Mean1, StudentsTStat.Mean2, StudentsTStat.PairedDiff, StudentsTStat.Slope
Nested classes/interfaces inherited from class org.bzdev.math.stats.Statistic
Statistic.PValueMode
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
add1
(double x1) Add an entry to data set A.void
add2
(double x2) Add an entry to data set B.double
getMean1()
Get the mean for data set A.double
getMean2()
Get the mean for data set B.double
getNCParameter
(double diff) Get the noncentrality parameter given a difference in mean values.double
getSDev1()
Get the sample standard deviation for data set A.double
getSDev2()
Get the sample standard deviation for data set B.double
getValue()
Get the value of this statistic.Methods inherited from class org.bzdev.math.stats.StudentsTStat
getDegreesOfFreedom, getDistribution, getDistribution, setDegreesOfFreedom
Methods inherited from class org.bzdev.math.stats.Statistic
getBeta, getBeta, getCriticalValue, getNCParameter, getPower, getPower, getPValue, optimalValue
-
Constructor Details
-
Mean2
public Mean2()Constructor. To add data to each of the two data sets, the methodsadd1(double)
andadd2(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 setvariance1
- the sample variance of the first data setn1
- the size of the first data setmean2
- the mean value of the second data setvariance2
- the sample variance of the second data setn2
- 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 Ab
- 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. -
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
- Sample Size & Power Calculations and Sample size and power calculations using the noncentral t-distribution for two-sample case.
- Statistical power of the t-tests for the one-sample case.
- Specified by:
getNCParameter
in classStudentsTStat
- Parameters:
diff
- the difference of the H1 mean value and the H0 mean value.- Returns:
- the noncentrality parameter
-