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 and
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 (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). 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
standard deviation
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 to say something about . Put formally: the statistic estimates the parameter . 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 — 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.
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 : nothing is going on. No difference, no change. With the null, always think: absent — the difference is absent.
The alternative hypothesis : 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:
: — poor sleepers worry the same amount as everyone else, on average
: — 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:
About the population, so about . Never about : you already know that number, so there is nothing to test.
The equals sign goes in . The null hypothesis names one exact value; that is what you calculate from.
Together they cover everything. Whatever does not fall under falls under . No gap in between.
Two-tailed. 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 as . 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 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 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:
Figure 2: A hundred means of samples of 25 poor sleepers, if is true ( = 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 . How strange is that, if 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 = 55: the dots that lie at least as far from 50
dots
55 or higher
1
45 or lower
1
together
2
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 is in the middle, and the boundary is at your result, on both sides.
And at ? 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.
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: . 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.
NoteCheck in R — counting with sum()
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 rightvalue <-45:55dots <-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 lowersum(dots[value >=55])
[1] 1
sum(dots[value <=45])
[1] 1
# and at 53: 53 or higher, and 47 or lowersum(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.
NoteIf you want to go further — making the dots yourself in R
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 = 50 and = 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)
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 ; from week 2 on, a number derived from it.
Three parts, and all three have to be in it:
it is a probability — a number between 0 and 1;
of this or a more extreme result — with a two-tailed test, on both sides;
given that 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 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 — 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 ? 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, 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 is true is .02.” Wrong.
The p-value works from 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 , you reject . The result is significant.
If , you do not reject .
NoteIf you want to go further — p < α or p ≤ α?
In other books and explanations, the rule is also given as : reject 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, pcan come out at exactly .05: five dots out of the hundred. Then you reject , because the rule is .
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 you reject , and by 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 . With a p of .0496, which looks exactly the same when rounded, you do reject . 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 , , and .02 ≤ .05. You reject the null hypothesis that poor sleepers score 50 on average on the worry questionnaire. With , : 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 falls in that region, you reject .
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 , 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 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.
NoteIf you want to go further — why the boundaries shift a little in week 2
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
is actually true
is actually not true
you reject
Type I error: false alarm (probability α)
correct
you do not reject
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 you did not reject . Does that mean that poor sleepers score exactly 50 on average? No.
You may say only two things: “reject ” or “do not reject ”. Never “accept ”, and never “retain ” either. Some books do write retain, meaning only that 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 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.
Hypotheses. Write down and , about . Agree on α.
Sampling distribution. What do the results look like if is true?
Test statistic. Which number from your sample do you set against it? This week, that is itself.
p-value. How extreme is your result? Compare p with α.
Statistical conclusion. Reject or do not reject it.
Conclusion in context. Answer the research question, in plain words.
Reject the null hypothesis that the mean worry score of poor sleepers is 50.
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 Environmentload("sleepstudy.RData")
# the first six rowshead(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 rowkeep <- sleepstudy$group =="control"# the row numbers where it is TRUEwhich(keep)
[1] 2 5 6 10 11 13 14 15 18 19 21 23 26 28 30
# only those rows, all columnscontrol <- sleepstudy[keep, ]# how many people is that?nrow(control)
[1] 15
# the youngest and the oldestrange(control$age)
[1] 18 34
# the mean age in the control groupmean(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")
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").
NoteIf you want to go further — the same with dplyr
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
Which symbol goes with the population mean, and which with the sample mean?
What is the difference between the population distribution, the sample distribution and the sampling distribution?
What is the difference between and ?
Give the definition of the p-value. Name all its parts.
What is the significance level α?
CautionAnswer 1.1
Population: . Sample: .
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 ) over all possible samples of the same size from the same population.
says that nothing is going on in the population (no difference, for example = 50) and contains the equals sign. says that something is going on ( ≠ 50). Together they cover every possibility.
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 .
The boundary you agree on beforehand: if , you reject . 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?
: against :
: against :
: against :
: against :
: against :
CautionAnswer 1.2
No. This is about , and you already know that number. Hypotheses are about the population.
Yes. About , the equals sign in , and together they cover everything.
No. The wrong way round: the equals sign belongs in .
No. Together they don’t cover everything: what if = 105? has to be everything that is not.
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 (: = 250). They find and .
Which statements are correct? More than one can be right.
There is strong evidence that = 250.
There is evidence that ≠ 250.
The probability that is true is .004.
If = 250, then a sample mean at least as far from 250 as 262 is very unlikely.
So the difference in reaction time is large and important.
CautionAnswer 1.3
Correct: 2 and 4.
Wrong. A small p is evidence against , not for it.
Correct. You reject (.004 ≤ .05).
Wrong. This is the reversal: p is the probability of data like these if is true, not the probability that is true.
Correct. This is exactly the definition.
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.
Write down and , in terms of .
Is this a good sample for testing ?
Do you think the difference is significant? What does that depend on?
CautionAnswer 1.4
The hypotheses:
: = 7.2 — first-year students sleep the same number of hours as adults, on average
: ≠ 7.2 — first-year students sleep a different number of hours, on average
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.
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.
Write down and , in terms of .
Below are the means of 100 imaginary samples of 16 children, drawn from a population in which is true. Each mean is rounded to a whole number.
Figure 6: A hundred means of samples of 16 children, if is true ( = 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.
What does one dot represent? Is this a population distribution, a sample distribution or a sampling distribution?
In the real sample of 16 children who game a lot, the mean you find is . In this figure, what is the probability of a mean of 35 or higher?
What is the p-value at ? (Two-tailed: this or a more extreme value.)
Do you reject at ? What does that mean?
Do c, d and e again for .
From which means on do you reject ? What are those boundaries called?
CautionShort answer 1.5
: = 30; : ≠ 30.
The mean of one sample of 16 children; a sampling distribution.
.01.
p = .02.
Yes.
.11; p = .17; no.
At 25 or lower and at 35 or higher: the critical values.
CautionFull worked answer 1.5 — step by step
The hypotheses:
: = 30 — children who game a lot score the same as all children, on average
: ≠ 30 — children who game a lot score differently, on average
One dot is the mean of one imaginary sample of 16 children, from a population in which = 30. So not the score of one child. The figure is a sampling distribution: the distribution of over many samples.
Count the dots at 35 and higher: 1 dot. The probability is . Watch out: this is only one side.
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.
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.
At :
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 ;
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.
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 . Small enough.
Distance 4: 26 or lower is 3 dots, and 34 or higher is 5 dots; together 8, so . Too big.
So you reject 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.
Load the file sleepstudy.RData and look at the first rows. Which variables do you see?
Which row numbers belong to people older than 25? Use which().
Make a histogram of age in the control group.
What is the mean age in the control group?
What is the mean worry score after the training, in the training group?
Turn your script into an HTML report.
CautionAnswer 1.6
## 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")
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
Five variables: id, group, age, worry_before and worry_after.
Rows 4, 5, 23 and 29.
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.
22.33 years.
51.27.
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
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.
Explain why you may say “we do not reject ”, but not “we accept ”.
CautionAnswer 1.7
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.
A test can only gather evidence against . If that evidence is too weak, you still don’t know whether 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?
the population distribution of the working memory scores
the sample distribution of the 16 children who game a lot
a sampling distribution
the scores of 100 children
CautionAnswer question 1
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?
the score of one child who games a lot
the mean of the 16 children who game a lot, from the study
the mean of a sample of 16 children from a population with = 30
the score of one child from a population with = 30
CautionAnswer question 2
C. The dots were made in the world of . 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.
CautionAnswer question 3
.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)?
CautionAnswer question 4
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?
The probability that is true is .012.
If is true, the probability of a result at least as extreme is .012.
The probability that is true is .988.
The probability that the result is due to chance is .012.
CautionAnswer question 5
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 ( true);
D: the probability that it is chance, now that you have this result.
In other words, D is the probability that 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?
a Type I error
a Type II error
a correct decision
you can’t tell without the p-value
CautionAnswer question 6
A. The researcher rejected while 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?
CautionAnswer question 7
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?
: , :
: , :
: , :
: , :
CautionAnswer question 8
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?
the p-value
the rejection region
the critical values
the significance level α
CautionAnswer question 9
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
you estimate, you calculate
every week
the sampling distribution
a hundred cards, counting dots
why a bell: week 2
and , 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 is true