15  Independent-Samples t-Test

NoteWhat you’ll be able to do

By the end of this chapter you will be able to:

  1. Distinguish independent from paired designs, and choose the right t-test accordingly.
  2. Explain why Welch’s t is this book’s default, and identify which variant R ran from the df.
  3. Read Welch output: direction, significance, and the 95% CI — including one that spans zero.
  4. Correctly interpret a non-significant p-value, and state what it does not mean.
  5. Report results in APA 7 style, with the effect size reported regardless of significance.

Two sections of the same course are taught with two different methods. On the common final, Method B’s section averages a few points higher. Is that a real difference between methods — or just two classrooms’ worth of ordinary student-to-student variation? Whenever the question is “do these two separate groups differ?”, this is the test.

The independent-samples t-test compares the means of two independent groups. It is the workhorse test of experimental research: treatment vs. control, male vs. female, condition A vs. condition B.

NoteWhy do we care? See it with real data first

Before the formal machinery below, work through the t-test preview activity — a real two-group question, answered start to finish with real data, before t, df, or Cohen’s d are ever named.

15.1 When to use it

Use this test when you have:

  • One continuous outcome variable.
  • One categorical grouping variable with exactly two levels.
  • Two groups that are independent of each other (different people in each group, not the same person measured twice).

Examples:

  • Do students in two different teaching methods score differently on the exam?
  • Does reaction time differ between caffeine and decaf conditions?
  • Do men and women report different levels of self-reported empathy?

If the two groups are the same people measured twice (pre/post), use the paired test in Chapter 16.

15.2 Hypotheses

  • \(H_0\): The two group means are equal (\(\mu_1 = \mu_2\)).
  • \(H_1\): The two group means differ (\(\mu_1 \neq \mu_2\)).

15.3 Welch’s vs. Student’s t-test

There are two flavors of the two-sample t-test:

  • Student’s t-test assumes the two groups have equal variances.
  • Welch’s t-test does not assume equal variances; it adjusts the degrees of freedom for the discrepancy.

R’s default is Welch’s, and you should keep it that way. The variance-equality assumption is rarely safe in real data, and Welch’s gives nearly-identical results when variances are equal. There is essentially no downside to using Welch’s by default. If you want Student’s specifically, add var.equal = TRUE.

WarningWhy Welch’s is the default in this book

Older textbooks teach a workflow where you first test for equal variances (Levene’s test or F-test for variances), then choose Student’s or Welch’s based on the result. This is now considered outdated practice for two reasons:

  1. The variance test itself has problems with non-normal data, so its result is unreliable.
  2. The post-test choice of Welch vs. Student introduces a “garden of forking paths” problem.

Modern practice — and what R does by default — is to just use Welch’s. We follow that convention.

15.4 Assumptions

  1. Independence. Observations within and between groups are independent.
  2. Continuous outcome. The outcome variable is interval or ratio.
  3. Approximate normality. Each group’s data should be roughly normal. Check Shapiro-Wilk per group, or do the visual check. With \(n > 30\) per group, normality matters less.

Homogeneity of variance is not required when using Welch’s (the default).

WarningWhat Could Go Wrong?

Confounding in non-experimental designs: If participants were not randomly assigned to groups, a significant t-test tells you the groups differ — not why. Suppose students in teaching method B also happened to have more prior math experience. What third variable might explain the score difference, and how would you rule it out?

Overclaiming from observational data: A study compares reaction times in people who self-selected a caffeine condition versus a decaf condition. Even with a significant result, what prevents a causal conclusion? What design change would be needed to support one?

TipTry It: Simulation First

Before running the formula, build intuition with the Rossman/Chance two-means randomization applet.

Predict first: if the null is true and you randomly shuffle group labels many times, how often would a difference as large as yours arise by chance? Run the simulation and compare your prediction to the result.

15.5 R syntax

The standard pattern uses the formula syntax outcome ~ group:

t.test(outcome ~ group, data = data)

This says “test whether outcome differs by group.” data = data tells R where to find the variables.

Other forms (less common but sometimes useful):

# Two separate vectors
t.test(group1_scores, group2_scores)

# Specifying direction (one-tailed)
t.test(outcome ~ group, data = data, alternative = "greater")

15.5.1 Worked example

You want to know whether students in two teaching methods (A and B) score differently on an exam. The data are 26 students: 12 taught with method A, 14 with method B.

# Step 0: Load the data
data <- read.csv("https://jkoxford-a11y.github.io/awesomesaucestats/data/ch15_teaching_methods.csv")

# Step 1: Inspect
str(data)
table(data$method)   # how many in each group?

# Step 2: Visualize
boxplot(score ~ method, data = data)

# Step 3: Check normality per group
A <- data$score[data$method == "A"]   # the scores where method is A
B <- data$score[data$method == "B"]
hist(A, main = "Method A")
hist(B, main = "Method B")
qqnorm(A, main = "Method A"); qqline(A)
qqnorm(B, main = "Method B"); qqline(B)
shapiro.test(A)
shapiro.test(B)
TipPause & Predict

Before running the test: which teaching method do you expect to produce higher exam scores — A or B? By roughly how many points? Write down your prediction before reading the output below.

# Step 4: Run the test
t.test(score ~ method, data = data)

# Step 5: Descriptives
aggregate(score ~ method, data = data, FUN = mean)
aggregate(score ~ method, data = data, FUN = sd)

15.5.2 Reading the output


    Welch Two Sample t-test

data:  score by method
t = -2.8817, df = 16.036, p-value = 0.01083
alternative hypothesis: true difference in means between group A and group B is not equal to 0
95 percent confidence interval:
 -11.508056  -1.753848
sample estimates:
mean in group A mean in group B 
       16.58333        23.21429 

The pieces:

  • t = -2.8817 — test statistic. Sign indicates direction (group A is lower than B here).
  • df = 16.036 — Welch’s adjusted degrees of freedom. It will not equal \(n_1 + n_2 - 2\) (here 12 + 14 − 2 = 24) and is usually non-integer.
  • p-value = 0.01083 — significant at \(\alpha = .05\).
  • 95 percent confidence interval: -11.51 to -1.75 — plausible range for the true difference A minus B (R subtracts the second group from the first, in the order shown under “sample estimates”). Negative means A is lower. Does not include zero.
  • Group means: 16.58 (A) vs. 23.21 (B).
ImportantCommon Misconception: p > .05 means “no effect”

A non-significant result does not mean the groups are equal or that there is no difference. It means the data did not provide sufficient evidence to reject the null hypothesis. The effect could be real but the study underpowered, or it could genuinely be small. The absence of evidence is not evidence of absence.

What to say instead: “There was no statistically significant difference” — not “There was no difference.”

TipTry It: A Real Effect Can Miss the .05 Line

The Dance of the Confidence Intervals holds a real effect fixed at Cohen’s d = 0.50 and repeats the same Welch study. Watch the confidence interval and significance verdict change across samples, then practice reporting both significant and non-significant results without turning either verdict into a claim about effect size.

Worked in pairs and printed to PDF to hand in. The same module is introduced in Chapter 5 for confidence-interval coverage; here, focus on Steps 4–9.

NoteInterpret the Output

Read this output carefully. The R code that produced it is not shown.


    Welch Two Sample t-test

data:  anxiety by condition
t = 2.1801, df = 17.192, p-value = 0.04343
alternative hypothesis: true difference in means between group CBT and group Control is not equal to 0
95 percent confidence interval:
 0.1119082 6.6573226
sample estimates:
    mean in group CBT mean in group Control 
            12.230769              8.846154 
  1. What is the name of the test that was run?
  2. What is the outcome variable? What are the two groups being compared?
  3. Which group has the higher mean anxiety score?
  4. Is the result statistically significant at α = .05? How do you know?
  5. Interpret the 95% confidence interval in plain language. What does the range [0.11, 6.66] tell you about the true difference?
  6. Write one APA 7 sentence reporting this result. Include Cohen’s d = 0.86.
  7. Name one limitation of this result that is not shown in the output (think: design, sample, or assumptions).

15.6 Effect size: Cohen’s d

\[ d = \frac{\bar{x}_1 - \bar{x}_2}{s_{pooled}} \]

where \(s_{pooled}\) is the pooled standard deviation of the two groups.

library(effsize)
cohen.d(score ~ method, data = data)

Interpretation:

Cohen’s d Effect size
0.2 Small
0.5 Medium
0.8 Large

Report Cohen’s d regardless of whether the result is statistically significant. Effect size describes the magnitude of the difference; that magnitude is informative whether or not it clears a significance threshold. (Some courses and older textbooks use a convention of omitting d for non-significant results. APA 7 and current consensus do not support this.)

15.7 Reporting

A Welch’s independent-samples t-test was conducted to compare exam scores between teaching methods A and B; scores in neither group showed evidence of non-normality (Shapiro-Wilk p = .265 and .666). There was a significant difference, t(16.04) = −2.88, p = .011, Cohen’s d = −1.06 (large). Students in method A (M = 16.58, SD = 2.61) scored lower than students in method B (M = 23.21, SD = 8.14), 95% CI for the difference (A − B) [−11.51, −1.75].

15.7.1 Non-significant example

From the Baby Dataset (after the Chapter 7 prep script): birth weight by whether the mother had given birth before, t.test(bwt ~ par_bi, data = babies).

A Welch’s independent-samples t-test indicated no significant difference in birth weight between babies of first-time mothers (M = 118.14 oz, SD = 17.15) and of mothers who had given birth before (M = 120.07 oz, SD = 18.58), t(584.54) = −1.69, p = .092, Cohen’s d = −0.11 (negligible), 95% CI for the difference [−4.18, 0.32].

Note what the effect size adds: with 315 and 921 babies per group, the test had about 86% power to detect even a small effect (d = 0.2), and d shows the observed difference is negligible — about 2 oz.

15.8 Common mistakes

Wrong Right
t.test(data$score, data$group) — treats group codes as scores t.test(score ~ group, data = data) — formula syntax
A typo creating a third group (“morning” vs. “Morning”) — R stops with grouping factor must have exactly 2 levels Run table(data$group) first; there must be exactly two values. (The group itself can be text, 0/1, or a factor — t.test() converts it. Making it a factor with levels = c(...) sets which group is subtracted first, and ANOVA will require it: Chapter 7.)
Reporting df = 38 (raw \(n_1 + n_2 - 2\)) for Welch’s Use whatever df R reports — Welch’s is non-integer
Using Student’s t without justification Stick with Welch’s (default)
Omitting Cohen’s d when \(p > .05\) Report effect size regardless of significance (APA 7)
Skipping the per-group descriptives Always include \(M\) and \(SD\) for each group

15.9 Quick reference

Element R code
Welch’s t-test (default) t.test(y ~ group, data = data)
Student’s t-test (rare) t.test(y ~ group, data = data, var.equal = TRUE)
One-tailed t.test(y ~ group, data = data, alternative = "greater")
Group means aggregate(y ~ group, data = data, FUN = mean)
Group SDs aggregate(y ~ group, data = data, FUN = sd)
Effect size library(effsize); cohen.d(y ~ group, data = data)
Non-parametric alternative wilcox.test(y ~ group, data = data)
TipReporting checklist for an independent-samples t-test

15.10 The same test, different disciplines

The independent-samples t-test is the workhorse of two-group comparison across the behavioral and biological sciences. The logic is identical across fields; only the research question changes.

Discipline Typical comparison Outcome variable
Psychology Treatment vs. control on a cognitive or self-report measure Reaction time, accuracy, Likert scale score
Biology Two species, strains, or experimental conditions Heart rate, enzyme activity, growth rate
Sociology Two demographic groups on a social outcome Income, years of education, attitude score

15.11 Power and sample size

Whether a study can reliably detect an effect of the size you observed depends on sample size, effect magnitude, and α. For an introduction to power analysis and the pwr package functions relevant to the t-test (pwr.t.test, and pwr.t2n.test for unequal groups), see Appendix E.

Next: the paired version, for when the two scores come from the same person.


TipChapter Summary

Core idea: The independent-samples t-test compares the means of two unrelated groups. Welch’s version (R’s default) handles unequal variances automatically — you do not need to test variances first and then decide which t-test to use.

You should understand:

  • What makes two groups “independent” (different participants, no pairing or matching)
  • Why Welch’s t-test is preferred over Student’s t-test as a default
  • What Cohen’s d measures and what “small / medium / large” mean in practice

You should be able to do in R:

  • Run the test: t.test(score ~ group, data = data)
  • Get descriptives: aggregate(score ~ group, data = data, FUN = mean)
  • Effect size: library(effsize); cohen.d(score ~ group, data = data)
  • Check normality per group: split each group out (A <- data$score[data$group == "A"]), then hist(A), qqnorm(A); qqline(A), and shapiro.test(A), and the same for B

Plain-language check: Your output shows t(37.2) — a non-integer df. What does this tell you about which version of the t-test R ran, and why?

The one mistake to avoid: Running separate t-tests for every pair of groups when you have three or more groups. With three groups, use ANOVA + Tukey post-hoc. Three separate t-tests inflate your Type I error rate.

Practice: A researcher wants to know if sleep-deprived participants (n = 20) perform worse on a memory task than well-rested participants (n = 20). Write the complete R workflow: import, assumption check, test, descriptives, and effect size.

Key terms from this chapter are defined in the Glossary.

NoteBaby Dataset Assignment

Practice the skills from this chapter using real data: Assignment 3 — Independent-Samples t-Test

Notet-Test Practice: In-Class Worksheet & Homework

Practice all three t-test types together: In-Class Worksheet — Dataset A and Homework — Dataset B.