Testing hypotheses

Research Methods — Week 6

Recap

Where we are

  • Week 3: the logic of hypothesis testing (conceptual)
  • Week 5: experimental design, controls, confounders

This week: the formal machinery. You’ll learn to run a t-test in R.

And then you’ll learn why it can mislead you.

Questions?

Submit questions anonymously:

PollEv.com/geol

text geol to 07480 781235

The t-test

🎓💻 Concept block 1

What does a t-test do?

Compares two group means and asks:

“Is this difference larger than we’d expect by chance?”

The logic

  1. Assume no difference (null hypothesis)
  2. Calculate how far apart the means are, relative to the variability (→ t-statistic)
  3. Ask: if there were really no difference, how often would we see a t this extreme? (→ p-value)

Live demo

🖥️ Switching to WebR

t.test(temperature ~ site, data = borehole)

Reading the output

t = 2.34, df = 18, p-value = 0.031
95% CI: [0.12, 2.34]
Element Meaning
t-statistic How many SEs apart are the means
p-value How surprising, if H₀ is true
95% CI Plausible range for the true difference

Interpret a t-test

💬✏️ Exercise 1

Write one sentence

I’m showing you R output from a t-test.

Write one sentence interpreting this result for a policy audience.

Then we’ll compare.

A common mistake

“p = 0.03 means there’s a 3% chance the null is true.”

Wrong. But extremely common. We’ll come back to this.

Assumptions

🎓 Concept block 2

Every test rests on assumptions

For the t-test:

  1. Independence — observations don’t influence each other
  2. Normality — data within each group are roughly normal
  3. Equal variance — groups have similar spread (Student’s t; Welch’s t relaxes this)

How to check

Assumption Check
Normality Histogram, QQ plot, shapiro.test()
Equal variance Side-by-side boxplots, Levene’s test
Independence Think about the study design

When assumptions are violated

A skewed variable can produce misleading p-values.

“Geological Solutions Since 2019”

Statistical Analysis — Soil Permeability

t-test on raw values: p = 0.04 → “Significant difference!”

t-test on log-transformed values: p = 0.23 → “No significant difference.”

The “significant” result was an artefact of skewness.

Check your assumptions

✏️💻 Exercise 2

In WebR

Given a dataset:

  1. Make histograms of each group
  2. Decide whether to transform
  3. Run t.test() before and after transformation
  4. Compare: did the conclusion change?

The base rate fallacy

🎓💬 Concept block 3

The most important 25 minutes of the course

I’m going to show you why a statistically significant result can still be wrong most of the time.

Warm-up: Monty Hall

Some of you simulated the Monty Hall problem in first-year Python.

Switching wins 2/3 of the time. But your gut says 50/50.

Why? Because your gut ignores the information the host gave you when they opened a door.

That confusion — between P(win) and P(win | what you now know) — is exactly what this block is about.

The medical test

A disease affects 1 in 1,000 people.

A test is 99% accurate (99% sensitivity, 99% specificity).

You test positive.

What’s the probability you have the disease?

Cast your vote

PollEv.com/geol

text geol to 07480 781235

The arithmetic

Out of 100,000 people:

Has disease No disease Total
Test positive 99 999 1,098
Test negative 1 98,901 98,902
Total 100 99,900 100,000

P(disease | positive) = 99 / 1,098 ≈ 9%

Not 99%. Nine percent.

Why is it so low?

Because the disease is rare.

The base rate matters enormously.

Even a very accurate test produces many false positives when the condition is uncommon.

HolmesCo strikes gold

“Geological Solutions Since 2019”

Press Release — Major Gold Discovery in County Durham!

“Our geochemical assay (95% accuracy) detected gold in 50 out of 10,000 soil samples. Confirmed multi-element anomaly!”

The reality

Suppose 5 in 10,000 samples are actually gold-bearing.

Gold present No gold Total
Assay positive ~5 ~500 ~505
Assay negative ~0 ~9,495 ~9,495

HolmesCo’s 50 positives? Almost certainly all false.

The press release is nonsense.

Connection to p-values

A p-value tells you: P(data | H₀)

How surprising is this data if the null is true?

What you actually want: P(H₀ | data)

How likely is the null to be true given this data?

These are not the same thing. The difference depends on the base rate.

The new refrain

“How plausible was this before we tested?”

Plan your test

✏️ Integrative exercise

For your project

Discuss with your group:

  1. What comparison will you test?
  2. What’s your null hypothesis?
  3. What’s your prior expectation — plausible or a long shot?
  4. What assumptions should you check?

Write 3–4 sentences.

Wrap-up

Key points

  1. A t-test compares two groups — but check the assumptions first
  2. A p-value is P(data | H₀), not P(H₀ | data)
  3. The base rate determines whether a “significant” result is real
  4. Always ask: “How plausible was this before I tested?”

Exit ticket

A t-test comparing two groups returns p = 0.04. Which statement is correct?

PollEv.com/geol

text geol to 07480 781235

Next time

Application session: “First tests”

You’ll run your first real tests on your project data.

Remember: a significant p-value is the start of the conversation, not the end.