The Difference between Two Means

Computations for Unequal Sample Sizes (optional)

The calculations are somewhat more complicated when the sample sizes are not equal. One consideration is that MSE, the estimate of variance, counts the group with the larger sample size more than the group with the smaller sample size. Computationally, this is done by computing the sum of squares error (SSE) as follows:

(S S E=\sum\left(X-M_{1}\right)^{2}+\sum\left(X-M_{2}\right)^{2}\)

where M_{1} is the mean for group 1 and M_{2} is the mean for group 2 . Consider the following small example:

Table 4. Unequal n.

Group 1 Group 2
3 2
4 4
5  

M_{1}=4 \text { and } M_{2}=3

\mathrm{SSE}=(3-4)^{2}+(4-4)^{2}+(5-4)^{2}+(2-3)^{2}+(4-3)^{2}=4

Then, MSE is computed by: MSE =\mathrm{SSE} / \mathrm{df}

where the degrees of freedom (df) is computed as before: \mathrm{df}=\left(\mathrm{n}_{1}-1\right)+\left(\mathrm{n}_{2}-1\right)=(3-1)+(2-1)=3 MSE =S S E / d f=4 / 3=1.333

The formula

s_{M_{1}-M_{2}}=\sqrt{\frac{2 M S E}{n}}

is replaced by

s_{M_{1}-M_{2}}=\sqrt{\frac{2 M S E}{n_{h}}}

where n_{h} is the harmonic mean of the sample sizes and is computed as follows:

\mathrm{n}_{\mathrm{h}}=\dfrac{2}{1 / n_{1}+1 / n_{2}}=\dfrac{2}{1 / 3+1 / 2}=2.4

and

s_{M_{1}-M_{2}}=\sqrt{\dfrac{(2)(1.333)}{2.4}}=1.054

Therefore,

t=(4-3) / 1.054=0.949

and the two-tailed \mathrm{p}=0.413.

R code

Data file

data=read.csv(file="animal.csv")
t.test(data$WRONG ~ data$GENDER,var.equal=TRUE)

Two Sample t-test

data: data$WRONG by data$GENDER
t = 2.5335, df = 32, p-value = 0.01639
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
0.2882231 2.6529534
sample estimates:
mean in group 1 mean in group 2
5.352941 3.882353

Callback before_footer in local_aigrade component should be migrated to new hook callback for core\hook\output\before_footer_html_generation
  • line 7225 of /lib/moodlelib.php: call to debugging()
  • line 7292 of /lib/moodlelib.php: call to {closure}()
  • line 71 of /lib/classes/hook/output/before_footer_html_generation.php: call to get_plugins_with_function()
  • line 987 of /lib/classes/output/core_renderer.php: call to core\hook\output\before_footer_html_generation->process_legacy_callbacks()
  • line 97 of /mod/book/tool/print/index.php: call to core\output\core_renderer->footer()