Wolfram Research

Function Repository Resource:

WelchTest

Source Notebook

Compare the means of two observational samples using the Welch test

Contributed by: András Aszódi  |  Andras Aszodi

ResourceFunction["WelchTest"][data1,data2]

tests whether the two lists of observations data1 and data2 have equal means.

Details

The Welch test is a modification of the Student t-test which does not require equality of variances.
The Welch test is used to compare the means of two groups of observations (samples) if the samples were drawn from (approximately) normal populations with unequal variances.
WelchTest returns an association containing the following keys:
"PValue"p-values
"TestStatistic"value of the t-statistic
“DegreesOfFreedom"approximate (non-integer) degrees of freedom
WelchTest takes the following option:
AlternativeHypothesis"Unequal"the inequality for the alternative hypothesis
With the setting AlternativeHypothesis"Unequal", WelchTest performs the two-sided Welch test.
Use AlternativeHypothesis"Greater" or AlternativeHypothesis"Less" to perform the one-sided Welch test.

Examples

Basic Examples (2) 

Two samples with unequal length:

In[1]:=
x1 = {2.970794, 3.639524, 2.475263, 3.627425, 2.916037, 3.064092, 3.487566, 2.857041, 3.478470, 2.301809, 2.610873};
x2 = {5.6249932, 2.2246327, 3.6890269, 4.7565668, 4.1545929, 1.9943043, 2.6960969, 3.3570305, 3.6784494, -0.1559634, 2.4236762, 3.9508845, 1.6016226, 0.3065061, 3.2132993};

Perform the two-sided Welch test on the two samples:

In[2]:=
ResourceFunction["WelchTest"][x1, x2]
Out[2]=

Options (3) 

AlternativeHypothesis (3) 

Two samples with unequal length:

In[3]:=
x1 = {2.970794, 3.639524, 2.475263, 3.627425, 2.916037, 3.064092, 3.487566, 2.857041, 3.478470, 2.301809, 2.610873};
x2 = {5.6249932, 2.2246327, 3.6890269, 4.7565668, 4.1545929, 1.9943043, 2.6960969, 3.3570305, 3.6784494, -0.1559634, 2.4236762, 3.9508845, 1.6016226, 0.3065061, 3.2132993};

Test H0:μ1-μ20 versus Ha:μ1-μ2<0:

In[4]:=
ResourceFunction["WelchTest"][x1, x2, AlternativeHypothesis -> "Less"]
Out[4]=

Test H0:μ1-μ2<0 versus Ha:μ1-μ20:

In[5]:=
ResourceFunction["WelchTest"][x1, x2, AlternativeHypothesis -> "Greater"]
Out[5]=

Resource History

Source Metadata

Author Notes

This very simple implementation does not check the t-test pre-requisite that the samples must come from (approximately) Normal distributions. In particular, the VerifyTestAssumptions option of the TTest function is not implemented.

License Information