Week 1 · Sampling distributions and hypothesis testing

the coat rack — what the other six weeks will hang on

It was already getting light when the bat came home, and now he knew for sure.

“Poor sleepers worry more than other animals,” he said to the dormouse, who woke up because he said it.

“I don’t have to believe it, I know it,” he said, “I saw three of them last night.”

“Who?” she asked.

“Me, the moth, and someone by the stream I couldn’t see properly,” he said.

“And if you’d flown the other way?” she asked, and she turned over.

What you learn this week

  • the difference between population and sample, and between μx\mu_x and x‾\bar{x}
  • three distributions with almost the same name
  • the null hypothesis and the alternative hypothesis
  • reading the p-value off a dot plot, by counting
  • deciding: reject or do not reject
  • why “not significant” is something other than “equal”
  • in R, choosing rows from a dataset, and turning your script into a report

The question beneath all seven weeks

Remember? Statistics has no other goal than to predict and explain differences, in the population. This week you link differences in worry to how people sleep.

You measure something in a small group of people, and you see a difference. For example, in your sample poor sleepers worry a bit more than average. And then comes the question this whole practice book turns on:

Is that difference also there in the population, or could you just as easily have drawn these people by chance?

For seven weeks you ask that one question, each time wearing a different coat: with one mean, with two means, with categories, with and without a bell shape. This first week doesn’t go deep. It puts up the coat rack: the hooks that every later week will hang on. You hardly calculate anything here; you count dots. Wherever something is worked out later, the page tells you in which week.

Only God knows the mean

You want to say something about all poor sleepers: the population. Their mean worry score is called μx\mu_x (mu). You don’t know that number, and you never will. That is why it gets a Greek letter: vague letters for vague things.

What you do know is your sample: the 25 people you actually measured. Their mean is called x‾\bar{x} (x-bar). You can simply calculate that number.

Population in Greek letters, sample in Latin ones
population sample
what it is everyone you want to say something about the people you actually measured
mean μx\mu_x x‾\bar{x}
standard deviation σx\sigma_x sxs_x
size N n
do you know it? no — a parameter yes — a statistic

And then the sentence never to forget: it is all about the population. Nobody writes an article about the 25 people who happened to take part. You use their mean x‾\bar{x} to say something about μx\mu_x. Put formally: the statistic x‾\bar{x} estimates the parameter μx\mu_x. Your sample itself estimates nothing; your sample is what you calculate with.

Three distributions with almost the same name

Three names, and two of them differ by one small ending.

  • The population distribution: the scores of everyone in the population.
  • The sample distribution: the scores of the people in your one sample.
  • The sampling distribution: the distribution of a statistic — for example x‾\bar{x} — over all possible samples of the same size n from the same population.

That third one is the heart of everything that comes after, and it is the hardest to picture. So, a game. Suppose a hundred people each draw a sample of their own, of 25 poor sleepers. Each of them works out the mean, writes it on a card, and hangs the card on a line — in order, small numbers on the left, big ones on the right. That row of cards is the sampling distribution. One card is not one person; one card is one sample. Really, all possible samples belong on that line, but a hundred is enough to see the shape.

TipSample distribution or sampling distribution?

Look at the ending. Sampling distribution: many samples, and one number from each. Sample distribution: one sample, and many people in it.

Two dot plots stand side by side on the same axis, worry score from 20 to 80. On the left, under the heading 'only one sample: 25 individual scores', 25 open circles lie flat and widely spread, from 33 to 63. On the right, under the heading 'as many as 100 samples: 100 calculated means', 100 open squares stand in tall stacks, close together between 45 and 55.
Figure 1: On the left, the sample distribution: only one sample, with the individual scores of 25 people, from 33 to 63. On the right, the sampling distribution: as many as 100 samples. Each square is the mean of its own sample of 25 people; together they lie from 45 to 55. Same axis. Circle = one person, square = one mean.

How to read it: on the left, the scores of 25 individual people are spread over 30 points (from 33 to 63); on the right, the means of 100 samples are spread over only 10 points (from 45 to 55). On the right there are four times as many dots, and yet the individual scores lie three times as far apart: so you meet a mean far from 50 much less often than a single score far from 50.

Why those cards form a bell shape around the middle, and how wide that bell is, we work out in week 2 (Hypothesis tests for one mean). The bell is then called the normal distribution, the reason it forms is called the central limit theorem, and its width is called the standard error. This week we only count.

Want to brush up on the normal distribution and z-scores first? You can, in week 0: what you need for week 2.

Two hypotheses: nothing going on, or something

In every test you set two statements about the population against each other.

  • The null hypothesis H0H_0: nothing is going on. No difference, no change. With the null, always think: absent — the difference is absent.
  • The alternative hypothesis HaH_\text{a}: something is going on. This is usually what the researcher expects.

For the poor sleepers, if the worry questionnaire is designed so that the mean in the general population is 50:

H0H_0: μx=50\mu_x = 50 — poor sleepers worry the same amount as everyone else, on average
HaH_\text{a}: μx≠50\mu_x \neq 50 — poor sleepers do not worry the same amount as everyone else, on average

Three rules, and every pair you ever write down has to pass all three:

  1. About the population, so about μx\mu_x. Never about x‾\bar{x}: you already know that number, so there is nothing to test.
  2. The equals sign goes in H0H_0. The null hypothesis names one exact value; that is what you calculate from.
  3. Together they cover everything. Whatever does not fall under H0H_0 falls under HaH_\text{a}. No gap in between.

Two-tailed. HaH_\text{a} has ≠, and not equal means: it can go up or down. That is called two-tailed testing, and in this practice book it is what you do by default. There are four reasons to do it even when you do expect a direction:

  • Often you have no direction. You don’t know whether poor sleepers worry more or worry less; you want to know whether it is different.
  • If you do have an expectation, you still want to know when things go the other way. Training that makes the worrying worse is not something you want to miss.
  • Some tests pick no side. For those, a one-sided version doesn’t even exist; you will meet them in week 4 (Probabilities and tests for categorical variables).
  • Anyone who picks the direction after seeing the data is cheating. That is called post hoc hypothesising. Two-tailed, decided beforehand, prevents it.

You will also come across HaH_\text{a} as H1H_1. Same thing, different name.

Counting dots

Now the heart of the week. You can’t answer the question “is my difference real?” directly. What you can do: pretend that H0H_0 is true, and see how strange your result would then be.

NoteThe example: worrying

A researcher measures how much 25 poor sleepers worry, with a questionnaire designed so that the mean in the general population is 50 and the standard deviation 10.

Suppose H0H_0 is true: poor sleepers worry the same amount as everyone else, on average. A hundred researchers each draw 25 poor sleepers and work out the mean, rounded to a whole number. Each mean becomes one dot, drawn as a square: a mean, not a person. This is what that looks like:

This dot plot shows open squares, stacked above the numbers 45 to 55. The tallest stack is above 50; towards both sides the stacks get lower, down to one square above 45 and one above 55.
Figure 2: A hundred means of samples of 25 poor sleepers, if H0H_0 is true (μx\mu_x = 50). Each square is the mean of one sample. How to read it: the stack at 50 is the tallest: 20 of the 100 samples had a mean of 50. The one at 54 is only 3 squares high: the further a mean lies from 50, the rarer it is.

This is a sampling distribution: each dot is a card from the game. Look at where the dots are. Most of them sit close to 50 — which makes sense, because in this world the mean is 50. But not all of them: by pure chance a sample sometimes comes out at 54 or 46, and every now and then at 55 or 45. That is how far chance can take you, even when nothing is going on.

Now your own sample. Suppose the real sample of 25 poor sleepers gives x‾=55\bar{x} = 55. How strange is that, if H0H_0 is true?

Count the dots that lie at least as far from 50 as your 55. Your 55 is 5 above 50. Just as far on the other side is 45. So:

At x‾\bar{x} = 55: the dots that lie at least as far from 50
dots
55 or higher 1
45 or lower 1
together 2

p=2100=.02 p = \dfrac{2}{100} = .02

This is the same dot plot. The squares above 45 and above 55 are coloured orange; all the other squares are dark.
Figure 3: The same hundred squares. Orange: the squares that lie at least as far from 50 as 55, on both sides. Together 2 of the 100. How to read it: on the left there is one orange square (at 45) and on the right one (at 55); the other 98 are dark: 98 of the 100 samples came out closer to 50 than your 55.

That number is the p-value. In words: if poor sleepers really score 50 on average, then only 2 of the 100 samples come out as far from 50 as yours did, or further.

In week 0, every piece of the bell had a p next to it: the probability of that piece. The p-value is just such a p. Now H0H_0 is in the middle, and the boundary is at your result, on both sides.

And at x‾=53\bar{x} = 53? Same recipe. 53 is 3 above 50; on the other side, that is 47. Count:

  • 53 or higher: 11 dots;
  • 47 or lower: 11 dots.

p=11+11100=.22 p = \dfrac{11 + 11}{100} = .22

In this world without a difference, a mean like that simply turns up regularly.

TipWith a dot plot: always count both sides

Two-tailed means: this side and the mirror side. In a dot plot, then, you count both of them, and add them up.

Here the two tails happen to hold exactly the same number of dots, so one side times two gives the same: 2×1100=.022 \times \dfrac{1}{100} = .02. But don’t count on it. A dot plot of a hundred samples is rarely that tidy — in exercise 1.5 it isn’t, and then “times two” gives a wrong number.

That shortcut only comes back with a smooth, symmetrical bell, in week 2. There the two sides are always exactly the same size.

You counted by hand. R can count along with you, so you can see that it adds up. New to R? Then read In R: choosing rows first, further on this week: it explains what the square brackets [ ] do. This box can wait.

Copy the stacks from the figure, from left to right:

# the stacks from the figure, from left to right
value <- 45:55
dots <- c(1, 3, 7, 12, 17, 20, 17, 12, 7, 3, 1)

# are there a hundred?
sum(dots)
[1] 100
# 55 or higher, and 45 or lower
sum(dots[value >= 55])
[1] 1
sum(dots[value <= 45])
[1] 1
# and at 53: 53 or higher, and 47 or lower
sum(dots[value >= 53])
[1] 11
sum(dots[value <= 47])
[1] 11

The same counts as by hand: at 55, 2 of the 100 together; at 53, 22 of the 100 together.

The hundred dots above are a thought experiment. In R you can simply do it: draw a sample of 25 a hundred times from a population with μx\mu_x = 50 and σx\sigma_x = 10, and write down each mean.

set.seed(2600)

# one sample of 25, and its mean
# (without mean and sd, R picks mean = 0 and sd = 1: then it lies around 0)
mean(rnorm(n = 25, mean = 50, sd = 10))
[1] 51.80573
# a hundred times: a hundred cards, rounded to whole numbers
# (digits = 0 is the default; leave it out and R picks it)
cards <- replicate(100,
  round(mean(rnorm(n = 25, mean = 50, sd = 10)), digits = 0))
table(cards)
cards
46 47 48 49 50 51 52 53 54 55 56 
 1 11 13 15 24 12 12  8  2  1  1 

Every argument in the code has its name. A shorter form works too: round(mean(rnorm(25, mean = 50, sd = 10))) gives the same card as the long line inside replicate().

Your hundred lie slightly differently from the ones in the figure — that is chance itself. The shape is the same: a hill around 50, sloping away to the sides. How wide that hill is, you can even work out without drawing a single sample; that is for week 2.

The p-value: what it says, and what it doesn’t

NoteThe p-value

The probability of a result that is at least as extreme as yours, if the null hypothesis is true.

That result is called the test statistic. This week it is simply the sample mean x‾\bar{x}; from week 2 on, a number derived from it.

Three parts, and all three have to be in it:

  1. it is a probability — a number between 0 and 1;
  2. of this or a more extreme result — with a two-tailed test, on both sides;
  3. given that H0H_0 is true — you calculate in the world where nothing is going on.

You can think of the p-value as your surprise value: how surprised you should be by your data, if H0H_0 is true. The smaller p, the bigger the surprise.

TipThe bakery

At the end of the street there was always a bakery. You haven’t been there in a long time. Is it still a bakery? You may go and look, but only blindfolded and with a clothes peg on your nose. You may say nothing except: “Surprise me.” That is your sample.

Under H0H_0 — it is still the bakery — you expect bread in your hands. A croissant could happen too. But you get a bicycle. Is that possible under H0H_0? Yes, once, perhaps, as a special offer. But the probability of a bicycle, if it is a bakery, is so small that it makes you jump. When p is low, H0H_0 must go. It must have turned into a bike shop.

Now look carefully at what this does and doesn’t say. The p-value is the probability of a bicycle if it is a bakery. It is not the probability that it is a bakery, now that you have a bicycle. The two look alike, and they are very different probabilities.

WarningThe reversal

“p = .02, so the probability that H0H_0 is true is .02.” Wrong.

The p-value works from H0H_0 to the data, not back. It says how strange your data are in a world without a difference. How likely that world itself is, it doesn’t say.

Deciding

A p-value is a number; a test ends with a decision. For that, you agree on a boundary beforehand: the significance level α (alpha). In this practice book it is always α = .05, unless an exercise says otherwise.

  • If p≤αp \leq \alpha, you reject H0H_0. The result is significant.
  • If p>αp > \alpha, you do not reject H0H_0.

In other books and explanations, the rule is also given as p<αp < \alpha: reject H0H_0 only if p is smaller than α. With a calculated p, that difference hardly ever matters, because a calculated p is practically never exactly equal to α. If you count dots out of a hundred, p can come out at exactly .05: five dots out of the hundred. Then you reject H0H_0, because the rule is p≤αp \leq \alpha.

Still, it can matter when you see a rounded p. A p of .0504 is written as .050 with three decimals and as .05 with two. If all you read is that .05, then by p≤αp \leq \alpha you reject H0H_0, and by p<αp < \alpha you don’t. In a case like that, look at more decimals. Then both rules say the same thing: .0504 is bigger than .05, so you do not reject H0H_0. With a p of .0496, which looks exactly the same when rounded, you do reject H0H_0. In an exam you don’t need to worry about that rounding: you won’t be given a rounded p that seems to sit right on .05. You read the p as it stands: if it says .05, it is .05.

For the poor sleepers with x‾=55\bar{x} = 55, p=.02p = .02, and .02 ≤ .05. You reject the null hypothesis that poor sleepers score 50 on average on the worry questionnaire. With x‾=53\bar{x} = 53, p=.22p = .22: you do not reject that null hypothesis.

Always say what you reject. Not “we reject it”, but “we reject the null hypothesis that …”.

The other route: the critical value

You can also draw a boundary in the dot plot beforehand. Which means are so far from 50 that the p-value drops below .05?

How Far From 50 Does a Mean Have to Lie to Be Significant?
distance from 50 means that far out p decision at α = .05
3 47 or lower, 53 or higher .22 do not reject
4 46 or lower, 54 or higher .08 do not reject
5 45 or lower, 55 or higher .02 reject

From a distance of 5 on, p drops below .05. So the boundaries are 45 and 55: those are the critical values. Everything on or beyond those boundaries is the rejection region — so 55 itself belongs to it. If your x‾\bar{x} falls in that region, you reject H0H_0.

This is the same dot plot again, with all the squares dark and two orange dashed vertical lines, one at 45 and one at 55; each line runs through the stack on its value.
Figure 4: The critical values 45 and 55 (dashed lines). The rejection region is everything on or beyond those lines.

How to read it: the right-hand line runs through the stack at 55: that one square lies on the boundary, so it belongs to the rejection region. The stack at 54 (3 squares) stands just inside the line: here, at a mean of 54, you do not reject H0H_0, even though the difference is only one point.

It’s like a fever. From 38 degrees on, you have a fever; that 38 is a critical value, agreed on before anyone put the thermometer in. The lines themselves are the critical values; everything on and beyond the lines is the rejection region. In an exam, those two are a favourite mix-up.

Two routes, the same decision:

  • the p-value route — count both sides, and set that p next to α = .05;
  • the critical-value route — draw the boundaries beforehand, and see whether x‾\bar{x} lies on or beyond a boundary.

They always come out the same. What goes wrong is switching halfway: setting a p from only one side next to .05, for example. Pick one route per exercise and see it through.

The means in the dot plot are rounded to whole numbers. So “53 or higher” counts everything from 52.5 up. That is why counting dots gives a rough p, and rough boundaries.

In week 2 you work out the same example exactly, without rounding. Then the p at 53 is not .22 but .13, and the boundaries are not at 45 and 55 but at 46.08 and 53.92. You can look up the p at 53 yourself, at z = 1.50 in table A, or have R calculate it; both give .13. At a mean of exactly 54, the decision even flips: counting says .08, calculating says .046.

That is not a fault of the dots. That is how a picture of a hundred rounded numbers works: it shows the shape, not the third decimal.

Two ways to be wrong

You decide without ever knowing how things really are. So you can be wrong, in two ways.

Four possible outcomes of one test
H0H_0 is actually true H0H_0 is actually not true
you reject H0H_0 Type I error: false alarm (probability α) correct
you do not reject H0H_0 correct Type II error: missed (probability β)
  • A Type I error is a false positive: you shout “difference!” and there is nothing there. You set the probability of that yourself, with α: it is at most .05. In the dot plot of the poor sleepers it is even just .02: that many dots (2 of the 100) lie on or beyond the boundaries. With the boundaries one step closer in, at 46 and 54, it would already have been .08: more than α, so the boundaries cannot lie there.
  • A Type II error is a false negative: there is a difference, but your test doesn’t see it.

How big that second probability is, and how you make it smaller, is for week 5 (Effect sizes and power).

Not significant is not the same as equal

With x‾=53\bar{x} = 53 you did not reject H0H_0. Does that mean that poor sleepers score exactly 50 on average? No.

You may say only two things: “reject H0H_0” or “do not reject H0H_0”. Never “accept H0H_0”, and never “retain H0H_0” either. Some books do write retain, meaning only that H0H_0 was not rejected. You may think it to yourself for a moment, but you never say it or write it. Not rejecting means: the evidence is not strong enough. It does not mean that there is nothing. The difference may well be there, just too small to see with this sample.

WarningThe classic trap

“There was no significant difference in X between group A and group B, so the groups are the same.”

Absence of evidence is not evidence of absence. With a small sample you miss even a big difference.

The confidence interval shows which values of μx\mu_x your data still do allow; that comes in week 3 (Hypothesis tests for two means and confidence intervals). And significant is not the same as large or important either. A difference that is large or important is called practically significant; that comes in week 5.

The six-step plan

Every test in this practice book goes through the same six steps. This week you fill them in with dots; from week 2 on, with formulas.

  1. Hypotheses. Write down H0H_0 and HaH_\text{a}, about μx\mu_x. Agree on α.
  2. Sampling distribution. What do the results look like if H0H_0 is true?
  3. Test statistic. Which number from your sample do you set against it? This week, that is x‾\bar{x} itself.
  4. p-value. How extreme is your result? Compare p with α.
  5. Statistical conclusion. Reject H0H_0 or do not reject it.
  6. Conclusion in context. Answer the research question, in plain words.

For the poor sleepers with x‾=55\bar{x} = 55:

  1. H0H_0: μx\mu_x = 50; HaH_\text{a}: μx\mu_x ≠ 50; α = .05.
  2. The dot plot in Figure 2: a hundred means under H0H_0.
  3. x‾=55\bar{x} = 55.
  4. p=.02p = .02, and that is ≤ .05.
  5. Reject the null hypothesis that the mean worry score of poor sleepers is 50.
  6. On average, poor sleepers do not worry the same amount as the general population: they worry more, in this sample.

Which test you choose in steps 2 and 3 depends on your question: one mean, two, or categories. That overview comes at the end: week 7 (Choosing a test, and an overview). And when you are actually allowed to use that smooth bell in step 2: week 6 (Assumptions and alternative tests).

In R: choosing rows

This week you do one thing in R: take the rows you need out of a dataset. The practice dataset sleepstudy has 30 first-year students who sleep badly. Half of them took part in sleep training, the other half didn’t (the control group). For everyone, the table holds their age and a worry score before and after.

Download sleepstudy.RData and put it in your project folder. (No project yet? In RStudio: File > New Project…, then New Directory > New Project. The folder you choose there is your project folder.) Then:

## Load the data ----
# load() puts the object sleepstudy in your Environment
load("sleepstudy.RData")
# the first six rows
head(sleepstudy)
  id    group age worry_before worry_after
1  1 training  19           54          51
2  2  control  24           49          45
3  3 training  19           48          47
4  4 training  26           54          55
5  5  control  34           61          58
6  6  control  21           54          56

A data frame has rows and columns. You need three things:

  • data[rows, columns] picks rows and columns; leave one side empty and you get all of them;
  • data$name takes one column, by its name;
  • == asks is this equal to?, and gives TRUE or FALSE for each row.
## Choosing rows on a condition ----
# which rows belong to the control group? TRUE or FALSE per row
keep <- sleepstudy$group == "control"

# the row numbers where it is TRUE
which(keep)
 [1]  2  5  6 10 11 13 14 15 18 19 21 23 26 28 30
# only those rows, all columns
control <- sleepstudy[keep, ]

# how many people is that?
nrow(control)
[1] 15
# the youngest and the oldest
range(control$age)
[1] 18 34
# the mean age in the control group
mean(control$age)
[1] 22.33333

The control group has 15 people, aged 18 to 34, with a mean age of 22.33.

hist(control$age, breaks = "Sturges", right = TRUE,
     main = "", xlab = "age", ylab = "count")
This histogram shows the ages in the control group, in bins of 5 years from 15 to 35. Most people are in the bins up to 25; above that there are 2 more.
Figure 5: Age in the control group of the sleep study.

How to read it: the bar from 20 to 25 is the tallest: 8 of the 15 people in the control group fall in it. The bar to its right, from 25 to 30, is only 1 high: the bar from 20 to 25 (older than 20, up to and including 25) holds eight times as many people as the one from 25 to 30.

breaks = "Sturges" and right = TRUE are the defaults; leave them out and R picks these. breaks = "Sturges" lets R choose where the bars start and end: here every 5 years. right = TRUE says: anyone exactly on a boundary counts in the bar to the left of it. So the one person aged 20 in the control group is in the bar from 15 to 20; with right = FALSE, that bar would have been 4 high instead of 5, and the next one 9 instead of 8. The short form is hist(control$age, main = "", xlab = "age", ylab = "count").

library(dplyr)
# R now reports which functions dplyr takes over ("masked"), such as filter(): not an error

# filter() picks rows, pull() takes one column out
# (var is the column; leave var out and pull() takes the last one)
sleepstudy |>
  filter(group == "control") |>
  pull(var = age) |>
  mean()
[1] 22.33333

A report from your script

With one command you turn a script into a report: your code, with the output and the figures underneath, in one HTML file. It looks like the R part above. In RStudio: File > Compile Report… (or Ctrl+Shift+K, on a Mac Cmd+Shift+K), and choose HTML. The report appears next to your script, with the same name.

Compile Report runs your whole script again, from top to bottom, and starts with an empty Environment. If something is in your Environment only because you typed it in the console, the report doesn’t know about it: it only knows what is in your script. If it doesn’t work, check four things:

  • are your script and your data in the same project folder?
  • are library() and load() at the top of your script, before the lines that need them?
  • is there a View() or install.packages() in it? Take them out: they belong in the console.
  • does your script itself stop with an error somewhere? Run it from top to bottom first (Code > Run Region > Run All); where it stops there, the report stops too.

Practice

NoteExercise 1.1 — Concepts
  1. Which symbol goes with the population mean, and which with the sample mean?
  2. What is the difference between the population distribution, the sample distribution and the sampling distribution?
  3. What is the difference between H0H_0 and HaH_\text{a}?
  4. Give the definition of the p-value. Name all its parts.
  5. What is the significance level α?
  1. Population: μx\mu_x. Sample: x‾\bar{x}.

  2. The population distribution: the scores of everyone in the population. The sample distribution: the scores of the people in your one sample. The sampling distribution: the distribution of a statistic (such as x‾\bar{x}) over all possible samples of the same size from the same population.

  3. H0H_0 says that nothing is going on in the population (no difference, for example μx\mu_x = 50) and contains the equals sign. HaH_\text{a} says that something is going on (μx\mu_x ≠ 50). Together they cover every possibility.

  4. The probability of a result (a test statistic) that is at least as extreme as the result you found, if the null hypothesis is true. Three parts: a probability; this or more extreme, with two-tailed on both sides; given H0H_0.

  5. The boundary you agree on beforehand: if p≤αp \leq \alpha, you reject H0H_0. It is also the probability of a Type I error that you are willing to take. Here α = .05.

NoteExercise 1.2 — Can you test with this?

For each pair, say whether you can do a hypothesis test with it. If not: why not?

  1. H0H_0: x‾=12\bar{x} = 12 against HaH_\text{a}: x‾≠12\bar{x} \neq 12
  2. H0H_0: μx=3.5\mu_x = 3.5 against HaH_\text{a}: μx≠3.5\mu_x \neq 3.5
  3. H0H_0: μx≠20\mu_x \neq 20 against HaH_\text{a}: μx=20\mu_x = 20
  4. H0H_0: μx=100\mu_x = 100 against HaH_\text{a}: μx=110\mu_x = 110
  5. H0H_0: μ1=μ2\mu_1 = \mu_2 against HaH_\text{a}: μ1≠μ2\mu_1 \neq \mu_2
  1. No. This is about x‾\bar{x}, and you already know that number. Hypotheses are about the population.
  2. Yes. About μx\mu_x, the equals sign in H0H_0, and together they cover everything.
  3. No. The wrong way round: the equals sign belongs in H0H_0.
  4. No. Together they don’t cover everything: what if μx\mu_x = 105? HaH_\text{a} has to be everything that H0H_0 is not.
  5. Yes. Two population means, equal against not equal. You test a pair like that in week 3.
NoteExercise 1.3 — What does p = .004 say?

Researchers look at whether the mean reaction time of people who have just stayed up all night differs from 250 milliseconds, the mean for well-rested people (H0H_0: μx\mu_x = 250). They find x‾=262\bar{x} = 262 and p=.004p = .004.

Which statements are correct? More than one can be right.

  1. There is strong evidence that μx\mu_x = 250.
  2. There is evidence that μx\mu_x ≠ 250.
  3. The probability that H0H_0 is true is .004.
  4. If μx\mu_x = 250, then a sample mean at least as far from 250 as 262 is very unlikely.
  5. So the difference in reaction time is large and important.

Correct: 2 and 4.

  1. Wrong. A small p is evidence against H0H_0, not for it.
  2. Correct. You reject H0H_0 (.004 ≤ .05).
  3. Wrong. This is the reversal: p is the probability of data like these if H0H_0 is true, not the probability that H0H_0 is true.
  4. Correct. This is exactly the definition.
  5. Wrong. Significant says whether there is a difference, not how large or important it is.
NoteExercise 1.4 — A convenient sample

You want to know whether first-year students sleep a different number of hours, on average, from adults in general, who sleep 7.2 hours a night on average. You ask the twelve students who are already in the library at nine in the morning. On average, they sleep 6.8 hours.

  1. Write down H0H_0 and HaH_\text{a}, in terms of μx\mu_x.
  2. Is this a good sample for testing H0H_0?
  3. Do you think the difference is significant? What does that depend on?
  1. The hypotheses:

    H0H_0: μx\mu_x = 7.2 — first-year students sleep the same number of hours as adults, on average
    HaH_\text{a}: μx\mu_x ≠ 7.2 — first-year students sleep a different number of hours, on average

  2. No. The sample was not drawn at random: anyone who is already in the library at nine has probably got up early. A group like that is not like all first-year students, and twelve is not many either.

  3. You don’t know yet. It depends on:

    • how big the difference is (here 0.4 hours);
    • how much sleep varies between students (the spread);
    • how big the sample is.

    How those three together decide the test, you work out in week 2.

NoteExercise 1.5 — Counting dots

A researcher thinks that children who play a lot of video games score differently on a working memory test from children in general. In general, children score 30 on that test, on average.

  1. Write down H0H_0 and HaH_\text{a}, in terms of μx\mu_x.

Below are the means of 100 imaginary samples of 16 children, drawn from a population in which H0H_0 is true. Each mean is rounded to a whole number.

This dot plot shows open squares above the numbers 25 to 35. The tallest stacks are above 28, 29 and 30; to the right of 30 the stacks slope down more gradually than on the left.
Figure 6: A hundred means of samples of 16 children, if H0H_0 is true (μx\mu_x = 30). Each square is the mean of one sample.

How to read it: the stack at 30 is the tallest: 21 of the 100 samples had a mean of 30. The one at 32 is less than half as tall (9 squares): a mean 2 above 30 already turned up much less often.

  1. What does one dot represent? Is this a population distribution, a sample distribution or a sampling distribution?
  2. In the real sample of 16 children who game a lot, the mean you find is x‾=35\bar{x} = 35. In this figure, what is the probability of a mean of 35 or higher?
  3. What is the p-value at x‾=35\bar{x} = 35? (Two-tailed: this or a more extreme value.)
  4. Do you reject H0H_0 at x‾=35\bar{x} = 35? What does that mean?
  5. Do c, d and e again for x‾=33\bar{x} = 33.
  6. From which means on do you reject H0H_0? What are those boundaries called?
  1. H0H_0: μx\mu_x = 30; HaH_\text{a}: μx\mu_x ≠ 30.
  2. The mean of one sample of 16 children; a sampling distribution.
  3. .01.
  4. p = .02.
  5. Yes.
  6. .11; p = .17; no.
  7. At 25 or lower and at 35 or higher: the critical values.
  1. The hypotheses:

    H0H_0: μx\mu_x = 30 — children who game a lot score the same as all children, on average
    HaH_\text{a}: μx\mu_x ≠ 30 — children who game a lot score differently, on average

  2. One dot is the mean of one imaginary sample of 16 children, from a population in which μx\mu_x = 30. So not the score of one child. The figure is a sampling distribution: the distribution of x‾\bar{x} over many samples.

  3. Count the dots at 35 and higher: 1 dot. The probability is 1100=.01\dfrac{1}{100} = .01. Watch out: this is only one side.

  4. 35 is 5 above 30. Just as far on the other side is 25. Count both sides:

    • 35 or higher: 1 dot;
    • 25 or lower: 1 dot.

    p=1+1100=.02 p = \dfrac{1 + 1}{100} = .02

  5. Yes: .02 ≤ .05. You reject the null hypothesis that children who game a lot score 30 on the working memory test, on average. If that mean really were 30, a result this far from 30 would turn up in only 2 of the 100 samples.

  6. At x‾=33\bar{x} = 33:

    • c: 33 or higher: 11 dots, so .11;
    • d: 33 is 3 above 30, the other side is 27. 27 or lower: that makes 6. So p=11+6100=.17p = \dfrac{11 + 6}{100} = .17;
    • e: .17 > .05, so you do not reject the null hypothesis. A mean like that simply turns up when there is no difference. That does not mean that children who game a lot score exactly 30 on average.

    Do you see that the two sides do not hold the same number of dots here? On the right you count 11, on the left 6. That is chance: a hundred drawn samples is a lot, but not infinitely many, and then the hill is rarely exactly symmetrical. That is why you really count both sides. One side times two would have given .22 here, and that is wrong.

  7. Look for the smallest distance from 30 at which p ≤ .05.

    • Distance 5: 25 or lower is 1 dot, 35 or higher is 1 dot. Together 2, so p=.02p = .02. Small enough.
    • Distance 4: 26 or lower is 3 dots, and 34 or higher is 5 dots; together 8, so p=.08p = .08. Too big.

    So you reject H0H_0 at a mean of 25 or lower and at 35 or higher. Those two boundaries are called the critical values; everything on or beyond those boundaries is the rejection region.

NoteExercise 1.6 — In R

Use the dataset sleepstudy.

  1. Load the file sleepstudy.RData and look at the first rows. Which variables do you see?
  2. Which row numbers belong to people older than 25? Use which().
  3. Make a histogram of age in the control group.
  4. What is the mean age in the control group?
  5. What is the mean worry score after the training, in the training group?
  6. Turn your script into an HTML report.
## a. load the data ----
load("sleepstudy.RData")
## a. have a look ----
head(sleepstudy)
  id    group age worry_before worry_after
1  1 training  19           54          51
2  2  control  24           49          45
3  3 training  19           48          47
4  4 training  26           54          55
5  5  control  34           61          58
6  6  control  21           54          56
## b. older than 25 ----
which(sleepstudy$age > 25)
[1]  4  5 23 29
## c. the control group, in two steps as above ----
keep <- sleepstudy$group == "control"
control <- sleepstudy[keep, ]
hist(control$age, main = "", xlab = "age", ylab = "count")
This histogram shows the ages in the control group, in bins of 5 years from 15 to 35. Most people are in the bins up to 25; above that there are 2 more.
Figure 7: Age in the control group of the sleep study (answer 1.6c).

How to read it: the two bars on the left, from 15 to 20 and from 20 to 25, are 5 and 8 high: together 13 of the 15 people. The two bars on the right are 1 high each: only 2 people in the control group are older than 25.

## d. the mean age in the control group ----
mean(control$age)
[1] 22.33333
## e. the training group, after ----
keep <- sleepstudy$group == "training"
training <- sleepstudy[keep, ]
mean(training$worry_after)
[1] 51.26667
  1. Five variables: id, group, age, worry_before and worry_after.

  2. Rows 4, 5, 23 and 29.

  1. See the histogram above: most people in the control group are in the bins up to 25, and only two are older. The data themselves give the exact ages: from 18 to 24, and 29 and 34 above that.

  2. 22.33 years.

  3. 51.27.

  4. File > Compile Report…, and choose HTML. Your project folder then has an HTML file with the same name as your script. If you get an error, go through the four questions under A report from your script, starting with the first: is sleepstudy.RData in the project folder?

NoteExercise 1.7 — No significant difference
  1. An article says: “there was no significant difference in sleep duration between students with and without a part-time job (p = .41).” May you conclude that students with and without a part-time job sleep equally long in the population? Explain.
  2. Explain why you may say “we do not reject H0H_0”, but not “we accept H0H_0”.
  1. No. p = .41 means that a difference like this one simply turns up when there is no difference in the population. It does not mean that there is no difference. The difference may be there and be too small for this sample to see it.

  2. A test can only gather evidence against H0H_0. If that evidence is too weak, you still don’t know whether H0H_0 is right; you just don’t have enough to rule it out. “Accepting” would say that you have shown there is no difference, and you haven’t.

Exam block

This is how you might meet it in the exam: as a multiple-choice question with four options. The exam has 30 of them. Below there are also a few questions you fill in yourself or answer with yes or no; the exam does not have those, they are extra practice. All you need is your calculator and your cheat sheet: where you need a p-value, it is given in the question, or you count it from the dots in the figure. The exam does not ask you to look anything up in table A; you did that in week 0, in exercises 0.3 and 0.5, to check yourself.

Questions 1 to 4 are about the figure in exercise 1.5.

NoteQuestion 1 — multiple choice

What do you see in the figure in exercise 1.5?

  1. the population distribution of the working memory scores
  2. the sample distribution of the 16 children who game a lot
  3. a sampling distribution
  4. the scores of 100 children

C. Each dot is the mean of a sample, and the figure shows how those means are distributed. D is the trap: they are 100 samples, not 100 children.

NoteQuestion 2 — multiple choice

What does one dot in that figure represent?

  1. the score of one child who games a lot
  2. the mean of the 16 children who game a lot, from the study
  3. the mean of a sample of 16 children from a population with μx\mu_x = 30
  4. the score of one child from a population with μx\mu_x = 30

C. The dots were made in the world of H0H_0. B is the trap: the mean from the study is just one number, and that is the very number you set against this figure.

NoteQuestion 3 — fill in

A sample of 16 children who game a lot has a mean of 25. What is the two-tailed p-value according to the figure? Give two decimals.

.02. 25 is 5 below 30; the other side is 35. 25 or lower: 1 dot; 35 or higher: 1 dot. Together 2 of the 100.

NoteQuestion 4 — yes or no

At that mean of 25, do you reject the null hypothesis (α = .05)?

Yes. .02 ≤ .05: you reject the null hypothesis that children who game a lot score 30 on average. Note: this mean lies below 30. Because you test two-tailed, that side counts just as much.

NoteQuestion 5 — multiple choice

A researcher finds p = .012. Which statement is correct?

  1. The probability that H0H_0 is true is .012.
  2. If H0H_0 is true, the probability of a result at least as extreme is .012.
  3. The probability that HaH_\text{a} is true is .988.
  4. The probability that the result is due to chance is .012.

B. A and C are the reversal.

D is the trickiest, because it sounds like B. Watch the small word:

  • B: the probability of such a result, if it is pure chance (H0H_0 true);
  • D: the probability that it is chance, now that you have this result.

In other words, D is the probability that H0H_0 is true — and that is A again. Back to the bakery: the probability of a bicycle if it is a bakery, against the probability that it is a bakery now that you have a bicycle.

NoteQuestion 6 — multiple choice

The researcher from exercise 1.5 concludes that children who game a lot score differently on the working memory test, when in reality there is no difference. What has the researcher made?

  1. a Type I error
  2. a Type II error
  3. a correct decision
  4. you can’t tell without the p-value

A. The researcher rejected H0H_0 while H0H_0 was true: a false alarm.

NoteQuestion 7 — yes or no

“There was no significant difference in concentration between the morning group and the evening group (p = .27). So the two groups concentrate equally well.” Is the second sentence right?

No. Not rejecting is not the same as equal. All you may say is that you could not show a difference.

NoteQuestion 8 — multiple choice

A researcher wants to know whether the mean IQ score of a group differs from 100. Which pair of hypotheses goes with that?

  1. H0H_0: x‾=100\bar{x} = 100, HaH_\text{a}: x‾≠100\bar{x} \neq 100
  2. H0H_0: μx=100\mu_x = 100, HaH_\text{a}: μx≠100\mu_x \neq 100
  3. H0H_0: μx≠100\mu_x \neq 100, HaH_\text{a}: μx=100\mu_x = 100
  4. H0H_0: μx=100\mu_x = 100, HaH_\text{a}: μx>100\mu_x > 100

B. A is about the sample, C is the wrong way round, and D only looks at one side, while the question says “differs”.

NoteQuestion 9 — multiple choice

What do the two dashed lines in Figure 4 (with the worry example) represent?

  1. the p-value
  2. the rejection region
  3. the critical values
  4. the significance level α

C. The lines are the boundaries themselves. The rejection region (B) is what lies on and beyond them.

The coat rack at a glance

What this week hangs up, and where it comes back
hook this week comes back in
population and sample μx\mu_x you estimate, x‾\bar{x} you calculate every week
the sampling distribution a hundred cards, counting dots why a bell: week 2
H0H_0 and HaH_\text{a}, two-tailed nothing going on, or something; ≠ is two sides every week; tests that pick no side in week 4
the p-value the probability of this or more extreme, if H0H_0 is true calculating instead of counting: week 2
deciding: α, critical value p≤.05p \leq .05: reject every week
Type I and Type II errors false alarm or missed the probability that you miss something: week 5
not significant ≠ equal not rejecting is not accepting week 3 and week 5
the six-step plan six steps, the same every week which test when: week 7
Back to top