java.lang.Object
org.bzdev.math.stats.Statistic
org.bzdev.math.stats.WelchsTStat
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
- ν1 = n1 - 1,
- ν2 = n2 - 1,
-
Nested Class Summary
Nested classes/interfaces inherited from class org.bzdev.math.stats.Statistic
Statistic.PValueMode
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor.WelchsTStat
(double[] x1, double[] x2) Constructor given two data sets.WelchsTStat
(double mean1, double variance1, long n1, double mean2, double variance2, long n2) Constructor given a description of two data sets. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add1
(double x1) Add an entry to data set X1.void
add2
(double x2) Add an entry to data set X2.double
Get the number of degrees of freedom for this instance.Get the probability distribution for this statistic.double
getMean1()
Get the mean for data-set 1.double
getMean2()
Get the mean for data-set 2.double
getNCParameter
(double diff) Get the noncentrality parameter given a difference in mean values.double
getSDev1()
Get the sample standard deviation for data-set 1.double
getSDev2()
Get the sample standard deviation for data-set 2.double
getValue()
Get the value of the statistic.protected void
setDegreesOfFreedom
(double d) Set the number of degrees of freedom for this instance.Methods inherited from class org.bzdev.math.stats.Statistic
getBeta, getBeta, getCriticalValue, getDistribution, getNCParameter, getPower, getPower, getPValue, optimalValue
-
Constructor Details
-
WelchsTStat
public WelchsTStat()Constructor. To add data to each of the two data sets X1 and X2, the methodsadd1(double)
andadd2(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 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
-
WelchsTStat
public WelchsTStat(double[] x1, double[] x2) Constructor given two data sets. Additional data can be added by calling the methodsadd1(double)
andadd2(double)
.- Parameters:
x1
- values to add to data set X1x2
- 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
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 classStatistic
- 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. -
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 classStatistic
- Parameters:
diff
- the difference of the H1 mean value and the H0 mean value.- Returns:
- the noncentrality parameter
-