Overview
The means test seeks to determine if two distributions, both assumed to be normal with the same variance, have the same mean based on a sample from both.
Distribution
Suppose that {% X %} is distributed as a normal variable with mean {% \mu_x %} and variance {% \sigma^2 %}, and {% Y %} is independent of {% X %}, with mean {% \mu_y %} and variance {% \sigma^2 %}, Then the statistic
{% t = \frac{\bar{X} - \bar{Y} - (\mu_x - \mu_y)}{s_p \sqrt{ 1/n + 1/m}} %}
follows a
t distribution
with {% n+m-2 %} degrees of freedom. Here, {% n %} is the number of sample points from the {% X %} distribution,
and {% m %} is the number of sample points from the {% Y %} distribution.
{% s_p^2 %} is the weighted average of the sample variances of {% X %} and {% Y %}.
{% s_p^2 = \frac{(n-1)s_x^2 + (m-1)s_y^2}{m+n-2} %}
where
{% s_x^2 = \frac{1}{n-1} \sum_{i=1}^n (X_i - \bar{X})^2%}
(see Rice chap 11)
Hypothesis Test of Equal Means
Assuming that the distribution means are equal, then {% (\mu_x - \mu_y) = 0 %}. That means that
{% t = \frac{\bar{X} - \bar{Y}}{s_p \sqrt{ 1/n + 1/m}} %}
is distributed as a t distribution with n+m-2 degrees of freedom.
Implementation
Testing the hypothesis that the means of the two populations are different can be implemented using the t-distrubtion module. The analyst can use the inverseCumulative
let td = await import('/lib/statistics/distributions/t-distribution/v1.0.0/t-distribution.mjs');
let val = td.inverseCumulative(3,0.8045);
if(Math.abs(val-0.5) > 0.05) $console.log('different means');
else $console.log('not significantly different means');
Try it!
As an alternative, the two-sample library provides a method for computing the t-stat and the inverse cumulative function.
let mn = await import('/lib/statistics/hypothesis/v1.0.0/two-sample.mjs');
let data1= [];
let data2 = [];
let testStat = mn.means(data1, data2);