← Course home
MODULE 7 · FIRST-YEAR LEVEL

Comparing two means and t-tests

Under what conditions can we compare two group means?

70–90 minutesConcepts first, R optionalSynthetic data

Learning outcomes

Conceptual lesson

An independent-samples t-test compares means between different individuals. Welch's t-test does not assume equal group variances and is often a sensible starting choice. A paired t-test examines within-person differences such as before and after measurements.

Choose the test based on the design. Treating before/after records from the same students as independent ignores the pairing. Normality assumptions often concern differences or errors rather than every raw variable; small samples and outliers warrant caution.

Report the mean difference, interval and design limitations. A pre/post increase does not by itself show causality: time, external studying or familiarity with the task could also affect scores.

Worked research example

For 36 fictional students, `score_pre` and `score_post` are paired within the same people. Post scores in groups A and B come from different individuals, so a Welch independent-samples comparison can be used.

Common reasoning trap

Do not interchange paired and independent t-tests simply because both share the name “t-test”.

Practice tasks

  1. 1. Choose the correct test for a before/after design and justify it.
  2. 2. Estimate and report the mean difference and interval between groups A and B.
  3. 3. Before interpreting a p-value, name two concerns about assumptions, pairing or confounders.

Explain your reasoning, not just the numerical result.

Optional R practice

Download the fictional CSV into your working folder, then run the script below or download the .R file. No additional packages are needed.

Download CSV · Download R lab · Module 0 refresher

# Statistics Lab / ferdo — synthetic data (no real student records)
# Save stats_synthetic.csv in your working directory.
d <- read.csv("stats_synthetic.csv", stringsAsFactors = TRUE)
stopifnot(nrow(d) == 36, all(c("score_pre","score_post","group") %in% names(d)))
# Groups are observational labels: differences cannot establish a treatment effect.

d <- read.csv("stats_synthetic.csv")
t.test(d$score_post, d$score_pre, paired=TRUE)
ab <- subset(d, group %in% c("A","B"))
t.test(score_post ~ group, data=ab) # Welch by default
# Neither observational contrast establishes causality.

Stretch: mathematical track

Explain how a standardised mean difference differs from a test statistic and what it communicates about magnitude.

Exit ticket

Write one evidence-bounded claim and one limitation about this week's example.

Student workbook for this module

Four written problems, marking guide and a formative four-question quiz.

Open week 7 workbook →

Optional mathematical derivations

Extend this topic with worked mathematics, written exercises and base R checks.

Math M6 · Math M7 · Full math pathway