Week 3 · Hypothesis tests for two means and confidence intervals

the same people twice, or two groups — and a margin around your estimate

After the sleep training the bat hung above the lake and looked sourly at the moth, who was fluttering carefree around the reeds.

“I still worry more than he does,” he said.

“He always worries less, that takes no training, just being a moth,” said the dormouse, “you’d do better to compare yourself with a bat.”

The bat looked down, and in the still water hung a bat, the right way up, looking back at him.

“Then from now on I’ll hang next to myself,” he said, “the one from before the training next to the one from now.”

He looked at the water once more and chuckled: “At least then I’ve got someone who worries exactly the way I do.”

What you learn this week

  • telling whether two means come from the same people or from two groups
  • the paired t-test: first difference scores, then the test from week 2
  • the independent t-test, in Welch’s version
  • why you don’t use the pooled version here, and what Levene’s test does
  • the confidence interval: for μx\mu_x, for a paired difference and for μ₁ − μ₂
  • what the 95% of a 95% interval does and does not mean
  • in R: t.test() paired and independent, boxplot(), hist(), plot() with abline(), and qt()

Two means, two kinds of data

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

So far you have set one mean against one fixed number: do poor sleepers have a mean worry score different from 50? This week you set two means side by side.

Take the practice dataset sleepstudy from week 1: 30 students in their first year who sleep badly. Half of them got sleep training, the other half didn’t. Everyone’s worry was measured, before and after. Two questions you can ask with these data:

  1. Does the training group worry less after than before? Those are two measurements of the same people. That is called paired: paired samples, or dependent measurements.
  2. Does the training group worry differently afterwards from the control group? Those are two different groups of people. That is called independent (independent samples).

The difference is not in the numbers but in how they belong together. Ask yourself one question: does this score belong to that score, from the same person or from a fixed pair? Then it is paired.

TipThree uses of independent

Independent can be the opposite of three different things. In the independent t-test, it refers to the groups.

  • Independent groups (independent samples) versus paired samples. Paired scores tell you something about each other: whoever worried a lot before usually still worries a lot after. That is why paired samples are also called dependent measurements: dependent on each other.
  • Independent versus dependent variable: the group (training or control) versus what you measure (the worry score). That is a role, and it has nothing to do with the name of the test.
  • Independent versus related variables, in week 4: one tells you nothing about the other, and then you may multiply their probabilities. Week 4 also calls related variables dependent: again, on each other.

So for groups, and for the variables in week 4, the question is the same: does one tell you something about the other? With two groups, the design tells you. With two variables, you test it in week 4: are they related in the population?

Two ways in which two means belong together
paired independent
who the same people twice, or fixed pairs two separate groups
examples before and after; twins; the partners in a couple training and control; students and non-students
in your data two columns of scores side by side one column of scores, one column with the group
the test the paired t-test the independent t-test (Welch)
TipA pair doesn’t have to be the same person

Twins of whom one gets the training, or the two partners in a couple: that is paired too. Each score in one row belongs to exactly one score in the other row. With two separate groups, the third person in the training group belongs to nobody in the control group.

Paired: one column of differences

The training group: 15 people, each measured twice. The trick of the paired test is that you straight away bring those two measurements down to one number per person: the difference.

d=after−before d = \text{after} - \text{before}

The first five participants in the training group; another ten follow
person before after difference d
1 54 51 −3
3 48 47 −1
4 54 55 1
7 67 63 −4
8 44 35 −9
… … … …

The numbers are the ones from the dataset; anyone missing in between is in the control group.

From here on you no longer have two columns, just one little column of differences. And on one column of numbers you can run the test from week 2: one mean, against zero.

You choose the direction yourself. Here it is after minus before, so a negative difference means: less worry after the training. The other way round is fine too; then all the signs flip. Agree on it beforehand and stick to it.

The mean of those differences is called d‾\bar{d} (d-bar), and it is exactly the difference between the two means: the mean after is 51.27, before 54.73, so d‾\bar{d} = −3.47. But the standard deviation of the differences, sds_d, you cannot get from the two separate standard deviations. For that you need the pairs themselves: sds_d is simply the standard deviation of the column of differences. R works it out (sd()), and in an exam it is given. Here it is 2.973.

A scatterplot with 15 open circles and a dashed diagonal from bottom left to top right. The circles lie along the diagonal, spread from 37 to 72 on the horizontal axis. Of these, 12 lie below the diagonal, up to 9 points lower; 2 exactly on it and 1 above it.
Figure 1: The 15 participants in the training group. Each dot is one person: left to right is their worry score before, bottom to top their score after. On the dashed line, after equals before. Below it lie 12 dots (less worry afterwards), on it 2 and above it 1.

How to read it: how far a dot lies below the line, measured straight down, is that person’s difference d. Take the dot furthest to the right (before 72, after 63) and the one furthest to the left (before 37, after 33): sideways they lie far apart, downwards they both shift only a little, 9 and 4 points. Whoever worried a lot before still worries a lot after, and that large difference between people drops out of d.

The same holds for everyone: nobody shifts more than 9 points off the line, and almost everyone shifts the same way: down.

The hypotheses

Under H0H_0 nothing changes, on average. Then you expect a mean difference of zero: bread at the baker’s. Not exactly zero in every sample, because chance always shifts things a little, but in the population, yes.

H0H_0: μd=0\mu_d = 0 — on average, poor sleepers who do the training worry as much after as before
HaH_\text{a}: μd≠0\mu_d \neq 0 — on average, something changes

μd\mu_d is the mean difference in the population: Greek, because that is a number you don’t know. You’ll also come across it as δ (delta).

The test

NoteThe paired t-test

t=d‾−0𝑆𝐸d‾=d‾sdndf=n−1 t = \dfrac{\bar{d} - 0}{\mathit{SE}_{\bar{d}}} = \dfrac{\bar{d}}{\dfrac{s_d}{\sqrt{n}}} \qquad df = n - 1

With n the number of pairs: the number of difference scores, not the number of measurements.

That is the t-test for one mean from week 2, on the column of differences, with μ₀ = 0.

Is −3.467 a lot? You can’t tell. Raw is rubbish: a difference of three points can be big or small, depending on how much chance shifts things around. So you ask: how many times does the standard error, the ruler, fit into that difference?

First the ruler:

𝑆𝐸d‾=sdn=2.97315=2.9733.873=0.7676 \mathit{SE}_{\bar{d}} = \dfrac{s_d}{\sqrt{n}} = \dfrac{2.973}{\sqrt{15}} = \dfrac{2.973}{3.873} = 0.7676

Keep those four decimals until the end. Then divide:

t=−3.4670.7676=−4.52df=15−1=14 t = \dfrac{-3.467}{0.7676} = -4.52 \qquad df = 15 - 1 = 14

The ruler fits into it more than four times, downwards: the difference is negative. You get the two-tailed p-value from the t-distribution, just as in week 2: one tail, times two. That is allowed because the t-distribution is symmetric; the other tail is exactly as heavy.

2 * pt(-4.52, df = 14)
[1] 0.0004804551

That is p < .001. (Further down, R calculates with the unrounded t and gets 0.0004839: the same, apart from the rounding of t.) In an exam you are given a p like that. If you want to see for yourself where it lies, bracket it in table D. In row 14, the last column is the column .0005, and the number there is 4.140; your |t| = 4.52 lies beyond even that. So one tail holds less than .0005, and the two tails together less than .001: p < .001, just as in R.

Deciding. p ≤ .05, so you reject the null hypothesis that poor sleepers who do the training worry as much after as before, on average: that is your statistical conclusion. In plain words, your conclusion in context: after the training the participants worry differently, on average, from before; in this sample their scores are 3.47 points lower.

NoteHow to write it up

The participants’ worry scores differed between before and after the training, t(14) = −4.52, p < .001; afterwards their scores were on average 3.47 points lower.

WarningDoes that mean the training works?

This test doesn’t tell you that yet. It compares after with before, in the same people. But worry can also go down without any training: the exam week is over, or whoever scored extra high at the first measurement scores a bit lower the second time all by itself. To judge the training you need a group that got no training. That comes at the end of this week, in So does the training work?.

In R you can do it in two ways, and they give exactly the same result. How you select the training group is in week 1, in In R: choosing rows.

training <- sleepstudy[sleepstudy$group == "training", ]

# 1. the two columns, and tell R that they are paired
t.test(training$worry_after, training$worry_before, paired = TRUE)

    Paired t-test

data:  training$worry_after and training$worry_before
t = -4.5163, df = 14, p-value = 0.0004839
alternative hypothesis: true mean difference is not equal to 0
95 percent confidence interval:
 -5.113000 -1.820333
sample estimates:
mean difference 
      -3.466667 
# 2. first the difference scores, then the test for one mean against 0
training$difference <- training$worry_after - training$worry_before
t.test(training$difference, mu = 0)

    One Sample t-test

data:  training$difference
t = -4.5163, df = 14, p-value = 0.0004839
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
 -5.113000 -1.820333
sample estimates:
mean of x 
-3.466667 

Both give t = −4.5163, df = 14, just as by hand. The interval at the bottom is the same too; what that is comes in The confidence interval.

Independent: two groups

Now the second question: does the training group worry differently afterwards from the control group? There are no pairs here. Person 1 in the training group belongs to nobody in the control group. You have two separate groups, each with a mean and a standard deviation.

Worry afterwards, per group
group n mean after sxs_x
1 training 15 51.267 9.468
2 control 15 52.533 9.078

H0H_0: μ1=μ2\mu_1 = \mu_2 — afterwards, both groups worry equally on average
HaH_\text{a}: μ1≠μ2\mu_1 \neq \mu_2 — afterwards, they worry differently on average

You can also write the null hypothesis as H0H_0: μ1−μ2=0\mu_1 - \mu_2 = 0. That is the same statement, and it shows what it is all about: a difference, and whether that is zero.

The standard error of a difference

Each group brings its own uncertainty. The mean of group 1 shifts from sample to sample, so does that of group 2, and the difference shifts with both. You add the two uncertainties up, but not just like that: squared.

Each fraction below is a standard error from week 2, squared, because (sxn)2=sx2n\left(\dfrac{s_x}{\sqrt{n}}\right)^2 = \dfrac{s_x^2}{n}. A squared standard error like that is the variance of the mean: how far it shifts from sample to sample, but squared.

Variances add up, as long as the two groups are independent, even for a difference, where you subtract one mean from the other. Why that is so, you don’t need for the calculation; if you want to see it for a sum: week 2, If you want to go further — where that square root comes from.

𝑆𝐸x‾1−x‾2=s12n1+s22n2 \mathit{SE}_{\bar{x}_1 - \bar{x}_2} = \sqrt{\dfrac{s_1^2}{n_1} + \dfrac{s_2^2}{n_2}}

Fill it in. First the squares, then the two fractions, then add up, and only then the square root:

𝑆𝐸x‾1−x‾2=9.468215+9.078215=89.64315+82.41015=5.976+5.494=11.470=3.3867 \begin{aligned} \mathit{SE}_{\bar{x}_1 - \bar{x}_2} &= \sqrt{\dfrac{9.468^2}{15} + \dfrac{9.078^2}{15}} = \sqrt{\dfrac{89.643}{15} + \dfrac{82.410}{15}} \\ &= \sqrt{5.976 + 5.494} = \sqrt{11.470} = 3.3867 \end{aligned}

The ruler for group 1, the standard error of its mean, is 9.46815=5.976=2.4446\dfrac{9.468}{\sqrt{15}} = \sqrt{5.976} = 2.4446 points; the ruler for group 2 is 9.07815=5.494=2.3439\dfrac{9.078}{\sqrt{15}} = \sqrt{5.494} = 2.3439.

Just like Pythagoras: the two rulers are the two sides at the right angle, and the standard error of the difference is the hypotenuse. In a right-angled triangle, too, you don’t add up the sides but their squares, a2+b2=c2a^2 + b^2 = c^2, and only then take the square root. Here those squares are the two fractions from above: 5.976+5.494=11.4705.976 + 5.494 = 11.470, and the square root of that is the hypotenuse.

A right-angled triangle. The bottom side is labelled ruler for group 1 and is 2.4446 long; the upright side on the right is labelled ruler for group 2 and is 2.3439 long. Between those two, at the bottom right, is the right angle, marked with the usual small corner symbol. The hypotenuse runs from bottom left to top right, is orange and thicker, is labelled ruler for the difference and is 3.3867 long: shorter than the detour along the two other sides, 4.7885.

The standard error of the difference as the hypotenuse. The two sides at the right angle are the rulers for group 1 (2.4446) and group 2 (2.3439); the hypotenuse, the ruler for the difference, is 3.3867: shorter than the two put together (4.7885).

Walk along the bottom side of the figure first and then up the upright side, and that detour is 4.7885: the two rulers simply added up. The orange hypotenuse is only 3.3867. The angle is a right angle because the groups are independent: what the mean of one group happens to do says nothing about the mean of the other.

The test

NoteThe independent t-test (Welch)

t=(x‾1−x‾2)−(μ1−μ2)𝑆𝐸x‾1−x‾2=x‾1−x‾2s12n1+s22n2 t = \dfrac{(\bar{x}_1 - \bar{x}_2) - (\mu_1 - \mu_2)}{\mathit{SE}_{\bar{x}_1 - \bar{x}_2}} = \dfrac{\bar{x}_1 - \bar{x}_2}{\sqrt{\dfrac{s_1^2}{n_1} + \dfrac{s_2^2}{n_2}}}

R works out the degrees of freedom; see Welch, pooled and Levene.

Why does μ1−μ2\mu_1 - \mu_2 drop out? Because you calculate in the world of H0H_0, just as in week 1. There μ1−μ2\mu_1 - \mu_2 is zero, and subtracting zero does nothing.

t=51.267−52.5333.3867=−1.2663.3867=−0.37 t = \dfrac{51.267 - 52.533}{3.3867} = \dfrac{-1.266}{3.3867} = -0.37

The ruler here is 3.3867 points, and the difference isn’t even half a ruler. R gives df = 27.95 with it, and then p = .71.

Deciding. p > .05, so you do not reject the null hypothesis that both groups worry equally on average afterwards. Afterwards, no difference between the groups has been shown. That is not the same as “the groups worry equally”: see week 1.

NoteHow to write it up

Afterwards, worry scores did not differ significantly between the training group and the control group, t(27.95) = −0.37, p = .71.

TipWhy paired is so much more sensitive

Take the training group again, with the same difference of −3.47. Now pretend that before and after are two separate groups, and work out the ruler from this section:

  • as two separate groups: 3.4982, because people differ a lot from one another (the standard deviation is 9.69 before and 9.47 after);
  • as pairs: 0.7676, because each person is compared with themselves (sds_d is only 2.97).

Same people, same difference, and a ruler more than four times as long. As separate groups p = .33; as pairs p < .001.

Someone who worries a lot worries a lot before and after. In the difference per person that drops out; between two separate groups it stays, and a small difference drowns in it. You can see it in Figure 1 too: the dots run from 37 to 72, but they all lie close to the line.

# one column of scores, and after the tilde (~) the column with the group
t.test(sleepstudy$worry_after ~ sleepstudy$group,
       alternative = "two.sided", mu = 0, var.equal = FALSE, conf.level = 0.95)

    Welch Two Sample t-test

data:  sleepstudy$worry_after by sleepstudy$group
t = 0.37401, df = 27.951, p-value = 0.7112
alternative hypothesis: true difference in means between group control and group training is not equal to 0
95 percent confidence interval:
 -5.671257  8.204590
sample estimates:
 mean in group control mean in group training 
              52.53333               51.26667 

Look at the sign. R says t = 0.37, you calculated t = −0.37. R subtracts the groups in the order they come in, and that is alphabetical: first control, then training. So R calculates control minus training, and you calculated training minus control. Same test, same df, same p; only the sign flips, and the interval is mirrored with it.

The second line has four arguments by name. These are the defaults; leave them out and R picks these: two-tailed (alternative = "two.sided"), a difference of 0 under H0H_0 (mu = 0), each group keeps its own spread (var.equal = FALSE) and a 95% interval (conf.level = 0.95). var.equal = FALSE is Welch’s test, the one you use in this book; that is why the top says Welch Two Sample t-test. So the short version gives exactly the same: t.test(sleepstudy$worry_after ~ sleepstudy$group, var.equal = FALSE). In this book you always keep that one argument, so you can see which test you are running.

Welch, pooled and Levene

There are two versions of the independent t-test. Here you use one of them.

Welch (the test above, and R’s default) lets each group keep its own spread. The standard error is the square root of s12/n1+s22/n2s_1^2/n_1 + s_2^2/n_2, as you just worked out. R works out the degrees of freedom; you don’t need to be able to do the formula by hand. You do need to recognise it, so this is what it looks like:

𝑑𝑓Welch=(s12n1+s22n2)2(s12n1)2n1−1+(s22n2)2n2−1 \mathit{df}_\text{Welch} = \dfrac{\left(\dfrac{s_1^2}{n_1} + \dfrac{s_2^2}{n_2}\right)^2} {\dfrac{\left(\dfrac{s_1^2}{n_1}\right)^2}{n_1 - 1} + \dfrac{\left(\dfrac{s_2^2}{n_2}\right)^2}{n_2 - 1}}

What you do need to know is between which two limits the result lies:

min⁡(n1−1,n2−1)≤𝑑𝑓Welch≤n1+n2−2 \min(n_1 - 1,\ n_2 - 1) \;\leq\; \mathit{df}_\text{Welch} \;\leq\; n_1 + n_2 - 2

For the sleep study: between 14 and 28, and R gave 27.95. Where it lands between those limits depends on the spread and the size of the two groups together. With groups of equal size, as here, it is simple: the more the two spreads differ, the further the df drops.

Without R you take the lower limit as df: the smaller of n1−1n_1 - 1 and n2−1n_2 - 1. That is the cautious side. The fewer degrees of freedom, the further out the boundary (week 2), so with the lower limit your p comes out a little higher than R’s, never lower. If you reject with the lower limit, R rejects too. If you don’t reject, then in a close case R may still reject after all. In a report you use R’s df.

Pooled (also called Student’s, or equal variances assumed) is not what you use here, but you need to recognise it:

  • it assumes that the two groups spread equally widely in the population (equal variances);
  • so it combines the two variances into one, the pooled variance: pooling is averaging;
  • its degrees of freedom are n1+n2−2n_1 + n_2 - 2, a whole number.

Why not? If the groups spread equally widely, Welch gives practically the same. If they spread unequally, pooled can give a wrong p. So Welch is right in both cases.

For the sleep study it makes no difference. The groups are the same size, and then the pooled standard error is exactly Welch’s (3.3867); only the df differs (28 against 27.95). In exercise 3.3 the groups are unequal, and there it does matter.

NoteAnd Levene’s test?

Read the name, as it appears in output: Levene’s test for equality of variances. It tests whether the two groups spread equally widely in the population.

H0H_0: σ12=σ22\sigma_1^2 = \sigma_2^2 — the variances are equal
HaH_\text{a}: σ12≠σ22\sigma_1^2 \neq \sigma_2^2 — the variances differ

So a small p for Levene means: the spreads differ. You come across it in the output of other programs, as an aid for choosing between pooled and Welch.

But a preliminary test like that is a poor aid for choosing. With small groups it often misses a difference in spread, while that is exactly when it matters most. With large groups it is quickly significant, while that is exactly when it matters little. With Welch you don’t have to choose. Know what Levene tests and what its p says; you need no more than that.

The confidence interval

Week 1 made a promise: which values of μx\mu_x do your data still allow? A test gives one answer to one question: is μx\mu_x equal to 50, yes or no? A confidence interval gives you, in one go, all the values of μx\mu_x that your data don’t rule out.

Back to the poor sleepers

The worry example from week 1: a questionnaire with σx\sigma_x = 10, and a sample of 25 poor sleepers. The standard error is then 1025=2\dfrac{10}{\sqrt{25}} = 2. Suppose you find x‾\bar{x} = 53.

Your best guess for μx\mu_x is 53: the point estimate. But you know that 53 may be off, because a sample mean shifts. So you put a margin around it: so many standard errors to the left, and so many to the right. For 95%, that is 1.96 of them.

NoteThe interval for μx\mu_x, when you know σx\sigma_x

x‾±z*⋅σxn \bar{x} \pm z^* \cdot \dfrac{\sigma_x}{\sqrt{n}}

z*z^* (z-star) is the number of standard errors you walk: 1.645 for 90%, 1.96 for 95%, 2.576 for 99%. Those three are best simply known by heart. z*z^* is the critical value from week 1, now as a number of standard errors; you’ll also see it written as zα/2z_{\alpha/2}. The part z*⋅σx/nz^* \cdot \sigma_x / \sqrt{n} is called the margin of error: how far you go to the left and to the right.

53±1.96×2=53±3.92so from 49.08 to 56.92 53 \pm 1.96 \times 2 = 53 \pm 3.92 \quad \text{so from } 49.08 \text{ to } 56.92

That is the 95% confidence interval: [49.08, 56.92]. Does 50 lie in it? Yes. A population with μx\mu_x = 50 fits these data just fine, and that is why you do not reject H0H_0: μx\mu_x = 50. The dots in week 1 said so too, and so did the z-test in week 2.

And with x‾\bar{x} = 55? Then the interval runs from 51.08 to 58.92. Now 50 is not in it: you reject the null hypothesis that μx\mu_x = 50.

When you don’t know σx: t

Usually you don’t know σx\sigma_x, and you fill in the standard deviation sxs_x from your sample. Then you don’t walk z*z^* standard errors but t*t^*, from the t-distribution with df=n−1df = n - 1. That one is a little bigger: if you are estimating rather than knowing, everything gets a little wider.

NoteThe interval for μx\mu_x, with t

x‾±t*⋅sxndf=n−1 \bar{x} \pm t^* \cdot \dfrac{s_x}{\sqrt{n}} \qquad df = n - 1

t*t^* is the critical t-value; you’ll also see it written as tα/2(df)t_{\alpha/2}(df).

Take all 30 poor sleepers from the sleep study, and their worry score before the training: x‾\bar{x} = 54.167, sxs_x = 9.311.

𝑆𝐸x‾=9.31130=9.3115.477=1.700t*=2.045(df=29) \mathit{SE}_{\bar{x}} = \dfrac{9.311}{\sqrt{30}} = \dfrac{9.311}{5.477} = 1.700 \qquad t^* = 2.045 \;\; (df = 29)

54.167±2.045×1.700=54.167±3.477 54.167 \pm 2.045 \times 1.700 = 54.167 \pm 3.477

The interval is [50.69, 57.64]. Fifty lies just outside it. With z*z^* = 1.96 you would have got [50.83, 57.50]: a little narrower, and that is precisely too narrow, because you didn’t know σx\sigma_x.

You can see where that t*t^* lies in Figure 2: it is the boundary where .025 of the t-distribution is still left to the right, and just as much to the left of −t*-t^*. Together .05 outside, .95 in between.

A bell-shaped curve around zero, from −4 to 4. At −2.045 and at 2.045 there is a dashed vertical line; the narrow strip under the curve beyond each line is orange, labelled 'right of 2.045: p = .025' and 'left of −2.045: p = .025'. In the middle it says 'in the middle: p = .95'.
Figure 2: The t-distribution with df = 29. Between −2.045 and 2.045 lies .95; in each orange tail, .025. t*t^* = 2.045 is the boundary of the right tail.

How to read it: the two orange tails are mirror images of each other, and that is why in the interval above you walk equally far to each side: 2.045 standard errors.

You get t*t^* in R with qt(). In full, with every argument by name:

qt(p = 0.025, df = 29, lower.tail = FALSE)
[1] 2.04523

You ask for the t-value with .025 still above it on the right (p = 0.025): half of the .05 that falls outside the 95% interval. That right is in lower.tail = FALSE: not the left tail (the lower tail), but the right one. The default is lower.tail = TRUE: leave that argument out and R counts the probability from the left, so qt(p = 0.025, df = 29) gives −2.045, the boundary of the left tail. So the short version works too, with the probability from the left: qt(0.975, df = 29) gives the same 2.045.

Without R, you look up t*t^* in table D: row df = 29, and 95% at the bottom. The picture there shows why that is the same cell as the column .025.

What 95% means: the horseshoe

This is the hardest part of the week.

Throw a horseshoe at a post. Sometimes the post ends up between its arms, sometimes not. An interval is a horseshoe like that, and μx\mu_x is the post: it stands still, and you don’t know where. The 95% belongs to the throwing: if you draw a sample very many times and make an interval like this each time, 95 out of 100 intervals catch μx\mu_x. Drawing very many times like that is called repeated sampling.

Twenty horizontal bars, one below the other, all the same length, with an open square in the middle. A vertical grey line at 50 runs through 19 of the bars. One orange bar, number 8 from the top, lies entirely to the right of the line and does not touch it.
Figure 3: Twenty samples of 25 poor sleepers, from a population in which μx\mu_x = 50 (the grey line). Each bar is the 95% interval of one sample; the square on it is that sample’s mean. All the bars are the same length, because σx\sigma_x and n are fixed; only their middle shifts. Of the 20 bars, 19 catch μx\mu_x; the orange bar misses.

How to read it: of the 20 squares, 19 lie between 46.08 and 53.92, less than half a bar from μx\mu_x (3.92, the same margin as with x‾\bar{x} = 53 above), and their bars reach the grey line. Only the orange square lies outside, at 56.17, and its bar does not reach it. Over very many samples, 95% of the squares lie that close to μx\mu_x, and that is why 95% of the bars hit.

In Figure 3 you know μx\mu_x, because the samples are invented. That exactly one misses is chance, in these twenty: the next series may miss none, or three. Only over very many series does it become one in twenty. In real research you throw once, and you don’t see the post. You only know that your way of throwing hits in 95% of cases.

NoteWhat a 95% confidence interval means

If you draw a sample very many times and make an interval like this each time, then 95% of those intervals contain the true μx\mu_x.

In plain words you say: “with 95% confidence, μx\mu_x lies between 49.08 and 56.92”. The word confidence does the work there: it says something about the method, the throwing. About this one interval there is no probability left to state; it catches μx\mu_x, or it doesn’t.

So in a multiple-choice question you pick the repeated-sampling reading (“if you draw very many times … then 95% of the intervals contain μx\mu_x”), if it is among the options. You’ll also meet it in a shorter form, as “the range in which μx\mu_x lies in 95% of cases”. That is the same reading: “the cases” are the repeated samples.

WarningThree readings that are wrong
  • “95% of poor sleepers score between 49.08 and 56.92.” Wrong: the interval is about the mean μx\mu_x, not about individual people. Individual scores spread much more widely than means (week 1: the scores of one sample next to the sampling distribution).
  • “There is a 95% probability that x‾\bar{x} lies in the interval.” Wrong: x‾\bar{x} is the middle of the interval. It always lies in it.
  • “There is a 95% probability that μx\mu_x lies in this interval.” Strictly speaking, no: μx\mu_x stands still, and this one horseshoe lies around it or it doesn’t. The 95% belongs to the throwing. If the repeated-sampling reading is among the options, that is the right answer.

Interval and test say the same thing

You already saw it with 53 and 55. It always holds, as long as interval and test calculate in the same way (the same standard error, both with z or both with t) and you test two-tailed:

  • if μ₀ lies in the 95% interval, then p > .05 and you do not reject H0H_0;
  • if μ₀ lies outside the 95% interval, then p ≤ .05 and you reject H0H_0.

A 99% interval goes with α = .01, a 90% interval with α = .10. The interval gives you something extra for free: roughly how big the difference is.

Wider or narrower

Three dials set how wide an interval is. All three are in the formula x‾±z*⋅σx/n\bar{x} \pm z^* \cdot \sigma_x / \sqrt{n}:

  • The confidence level (z*z^*). If you want to be surer, you throw a wider horseshoe.
  • The sample size (n). A bigger n makes the standard error smaller, and the interval narrower. It goes with the square root: four times as many people gives an interval half as wide.
  • The spread (σx\sigma_x, or sxs_x). The more the scores differ, the wider.

The first dial for the poor sleepers, with x‾\bar{x} = 53:

The same mean, three confidence levels
confidence level z*z^* interval width
90% 1.645 [49.71, 56.29] 6.58
95% 1.96 [49.08, 56.92] 7.84
99% 2.576 [47.85, 58.15] 10.30

The confidence level is also called the coverage: what share of the horseshoes hit.

The interval for a difference

The same recipe works for this week’s two tests. You put the margin around the difference you found, and look whether 0 lies in it.

NoteIntervals for a difference

Paired, with df=n−1df = n - 1:

d‾±t*⋅sdn \bar{d} \pm t^* \cdot \dfrac{s_d}{\sqrt{n}}

Independent, with Welch’s df:

(x‾1−x‾2)±t*⋅s12n1+s22n2 (\bar{x}_1 - \bar{x}_2) \pm t^* \cdot \sqrt{\dfrac{s_1^2}{n_1} + \dfrac{s_2^2}{n_2}}

Paired, the training group. t*t^* = 2.145 with df = 14, and the ruler was 0.7676:

−3.467±2.145×0.7676=−3.467±1.647 -3.467 \pm 2.145 \times 0.7676 = -3.467 \pm 1.647

The interval is [−5.11, −1.82]. Zero is not in it, just as the test said. And you can see straight away roughly how big the drop is: drops of 1.82 to 5.11 points fit these data.

Independent, training against control. t*t^* = 2.0486 with df = 27.95:

−1.266±2.0486×3.3867=−1.266±6.938 -1.266 \pm 2.0486 \times 3.3867 = -1.266 \pm 6.938

The interval is [−8.20, 5.67]. Zero is in it. And look how wide it is: afterwards the training group may score 8.20 points lower on worry than the control group, but also 5.67 points higher. Not significant here mainly means: these data don’t know yet.

NoteHow to write up an interval

From before to after the training, worry scores changed by −3.47 points on average, 95% CI [−5.11, −1.82].

t.test() always gives you the 95% interval as well, under 95 percent confidence interval. You ask for another level with conf.level, and you get just the limits out with $conf.int:

# the 95% interval for μₓ, worry before, all 30
t.test(sleepstudy$worry_before)$conf.int
[1] 50.68987 57.64346
attr(,"conf.level")
[1] 0.95
# the paired interval for the training group, now 90%
t.test(training$worry_after, training$worry_before, paired = TRUE,
       conf.level = 0.90)$conf.int
[1] -4.818644 -2.114689
attr(,"conf.level")
[1] 0.9

The 90% interval is narrower than the 95% interval [−5.11, −1.82]: less sure, so a narrower horseshoe.

So does the training work?

Back to the question from the beginning. The training group worries less afterwards than before. But the control group, which got nothing, does too, a little: on average 1.07 points, against 3.47 in the training group.

So the fair question is: does the training group go down more than the control group? Take everyone’s difference, after minus before, and compare those differences between the two groups. No new test comes in: it is the independent t-test from above, on the column difference instead of the column worry_after.

After minus before, per group
group n mean difference sds_d
training 15 −3.47 2.97
control 15 −1.07 4.76

The difference between the groups is −3.467 − (−1.067) = −2.400: the training group goes down 2.40 points more. The ruler, with the same formula as above:

𝑆𝐸=2.973215+4.758215=0.5892+1.5092=1.449t=−2.4001.449=−1.66 \mathit{SE} = \sqrt{\dfrac{2.973^2}{15} + \dfrac{4.758^2}{15}} = \sqrt{0.5892 + 1.5092} = 1.449 \qquad t = \dfrac{-2.400}{1.449} = -1.66

R gives df = 23.49 and p = .11 with it, and the 95% interval for the difference between the two drops (training minus control) is [−5.39, 0.59].

Not significant. But read the interval: the training group may go down up to 5.39 points more than the control group, but also 0.59 points less. With 15 people per group, you simply don’t know yet. How to express the size of such an effect of the training on worry, and how many people you need to see it, comes in week 5 (Effect sizes and power).

Look at the degrees of freedom too: 23.49, not 28. The standard deviations of the differences are far apart (2.97 against 4.76), and then Welch’s df drops.

In R: comparing two means

This week you do three things in R: look at the data in a plot, run the test, and ask for the interval. With sleepstudy, as in week 1:

## Load the data ----
load("sleepstudy.RData")

Paired: two columns side by side

## The training group ----
training <- sleepstudy[sleepstudy$group == "training", ]

A boxplot of the two columns side by side:

boxplot(training$worry_before, training$worry_after, names = c("before", "after"),
        ylab = "worry score")
Two boxplots side by side, before and after. The box for after sits a little lower; the median drops from 54 to 51. The two boxes are the same height, 10.5 points: before from 48.5 to 59, after from 47 to 57.5.
Figure 4: Worry before and after in the training group (n = 15). The median drops from 54 to 51.

How to read it: the thick line in each box is the median; it drops from 54 to 51. The boxes themselves, the middle half of the scores, are both 10.5 points tall: after, people are spread just as far apart as before. Next to that height, a drop of 3 points is small, and the two boxes largely overlap.

That boxplot doesn’t see the pairs: it puts two groups next to each other. For paired data a scatterplot says more. Each point is one person, and the line abline(a = 0, b = 1) is where after is exactly equal to before (a = 0: the line starts at zero; b = 1: one step up for every step to the side):

plot(training$worry_before, training$worry_after,
     xlab = "worry score before", ylab = "worry score after")
abline(a = 0, b = 1)
A scatterplot of worry before against worry after, with a solid diagonal; 12 of the 15 points lie below the line.
Figure 5: Worry before against after in the training group, with the line after = before.

How to read it: a point below the line is someone who worries less after than before. There are 12 below it, 2 exactly on it and only 1 above it, and that one point (before 54, after 55) worries only 1 point more after. So almost everyone goes down, and the boxplot above didn’t show that: it only put two groups next to each other.

Then the test:

## The paired test ----
t.test(training$worry_after, training$worry_before, paired = TRUE)

    Paired t-test

data:  training$worry_after and training$worry_before
t = -4.5163, df = 14, p-value = 0.0004839
alternative hypothesis: true mean difference is not equal to 0
95 percent confidence interval:
 -5.113000 -1.820333
sample estimates:
mean difference 
      -3.466667 

Note the order: worry_after first, then worry_before. R calculates the first minus the second.

And how are those differences spread? Make the column, and a histogram:

training$difference <- training$worry_after - training$worry_before
hist(training$difference, main = "", xlab = "difference (after minus before)", ylab = "count")
A histogram with bins of 2 points, from −10 to 2. From left to right the bars are 2, 0, 6, 3, 3 and 1 high; the tallest is the bin from −6 to −4. In all, 12 of the 15 differences lie below zero, 2 are exactly zero and are counted in the bar from −2 to 0, and 1 lies above zero.
Figure 6: The 15 difference scores (after minus before) of the training group, from −9 to 1.

How to read it: the tallest bar, from −6 to −4, counts 6 people; the only bar to the right of zero, from 0 to 2, counts 1. So almost everyone worries less after: 12 of the 15, because the bar from −2 to 0 also counts the 2 people with a difference of exactly 0 (R puts a number on a boundary in the bar to its left).

The paired test assumes that the differences in the population are roughly normally distributed. When that matters, and what you do if it isn’t so, comes in week 6 (Assumptions and alternative tests).

WarningDon’t forget paired = TRUE

Without paired = TRUE, R thinks you have two separate groups, and it does a Welch test. With these data:

t.test(training$worry_after, training$worry_before, var.equal = FALSE)$p.value
[1] 0.3301853

p = .33 instead of less than .001. No error message, no warning: just a different answer. It is exactly the calculation from Why paired is so much more sensitive: without the pairs, R counts the differences between people again.

Independent: one column of scores, one column for the group

## Two groups ----
# left of the tilde (~) the scores, right of it the group
boxplot(sleepstudy$worry_after ~ sleepstudy$group, xlab = "group", ylab = "worry score after")
t.test(sleepstudy$worry_after ~ sleepstudy$group, var.equal = FALSE)

    Welch Two Sample t-test

data:  sleepstudy$worry_after by sleepstudy$group
t = 0.37401, df = 27.951, p-value = 0.7112
alternative hypothesis: true difference in means between group control and group training is not equal to 0
95 percent confidence interval:
 -5.671257  8.204590
sample estimates:
 mean in group control mean in group training 
              52.53333               51.26667 
Two boxplots side by side, control on the left and training on the right. The box for training, from 47 to 57.5, lies entirely inside the box for control, from 44 to 58.5. The median line of control sits high in its box, at 56; that of training at 51.
Figure 7: Worry afterwards, per group (15 in control, 15 in training). The medians: 56 and 51.

How to read it: the box for training (47 to 57.5) lies entirely inside the box for control (44 to 58.5). The medians do differ by 5 points (56 against 51), but the median of control sits high in its box: the lower half of that group is stretched out, and that pulls the mean down. So the means, which the test looks at, differ by only 1.27 (52.53 against 51.27, at the bottom of the output), and the test finds no difference: p = .71.

Type the tilde yourself. If you copy it from a PDF, it is often a different character that only looks the same, and you get an error message.

Asking for the interval

## Another level, and only the limits ----
t_out <- t.test(sleepstudy$worry_after ~ sleepstudy$group, var.equal = FALSE, conf.level = 0.99)
t_out$conf.int
[1] -8.092912 10.626245
attr(,"conf.level")
[1] 0.99

t_out is what comes out of the test. With t_out$ you can also ask for $statistic (t), $parameter (df) and $p.value. R calls the degrees of freedom a parameter of the t-distribution. Type ?t.test and look under Value for the whole list.

Practice

NoteExercise 3.1 — Concepts
  1. What are H0H_0 and HaH_\text{a} for the independent t-test? And for the paired one?
  2. How many degrees of freedom does the paired t-test have? And between which two limits does Welch’s df lie?
  3. Give the formula of the test statistic for the paired and for the independent t-test.
  4. Why can you almost always leave out μ1−μ2\mu_1 - \mu_2 in the formula of the independent t-test?
  5. What does the 95% of a 95% confidence interval for μx\mu_x mean? Give the formal meaning.
  6. Give the formula of the 95% interval for μx\mu_x (with t), and the one for μ1−μ2\mu_1 - \mu_2.
  1. Independent: H0H_0: μ1=μ2\mu_1 = \mu_2 against HaH_\text{a}: μ1≠μ2\mu_1 \neq \mu_2. Paired: H0H_0: μd=0\mu_d = 0 against HaH_\text{a}: μd≠0\mu_d \neq 0, with μd\mu_d the mean difference in the population.

  2. Paired: df=n−1df = n - 1, with n the number of pairs. Welch: at least the smaller of n1−1n_1 - 1 and n2−1n_2 - 1, at most n1+n2−2n_1 + n_2 - 2. R works out the exact value, with the formula in Welch, pooled and Levene. Without R you take the lower limit.

  3. Paired and independent:

    t=d‾sdnt=x‾1−x‾2s12n1+s22n2 t = \dfrac{\bar{d}}{\dfrac{s_d}{\sqrt{n}}} \qquad\qquad t = \dfrac{\bar{x}_1 - \bar{x}_2}{\sqrt{\dfrac{s_1^2}{n_1} + \dfrac{s_2^2}{n_2}}}

  4. You calculate in the world of H0H_0, and there μ1=μ2\mu_1 = \mu_2, so μ1−μ2=0\mu_1 - \mu_2 = 0.

  5. If you draw a sample very many times and make an interval like this each time, then 95% of those intervals contain the true μx\mu_x. The 95% belongs to the method, not to one interval.

  6. For μx\mu_x and for μ1−μ2\mu_1 - \mu_2:

    x‾±t*⋅sxn(x‾1−x‾2)±t*⋅s12n1+s22n2 \bar{x} \pm t^* \cdot \dfrac{s_x}{\sqrt{n}} \qquad\qquad (\bar{x}_1 - \bar{x}_2) \pm t^* \cdot \sqrt{\dfrac{s_1^2}{n_1} + \dfrac{s_2^2}{n_2}}

    The first with df=n−1df = n - 1, the second with Welch’s df.

NoteExercise 3.2 — Paired or independent?

Which test fits: the paired t-test, the independent t-test, or neither?

  1. Twenty people do a reaction test, once well rested and once after a night without sleep.
  2. Thirty psychology students and thirty law students fill in a stress questionnaire.
  3. In each of fifteen pairs of twins, one twin gets reading training and the other doesn’t. Afterwards they both read a text.
  4. In forty couples, both partners rate how satisfied they are with the relationship. Do men and women differ in this?
  5. Forty people are randomly assigned to two diets. After eight weeks you weigh everyone.
  6. Twenty-five children take an arithmetic test whose national mean is 100. Do they differ from it?
  1. Paired. The same people, twice.
  2. Independent. Two groups, nobody is in both.
  3. Paired. Each pair of twins is a fixed pair: each score with training belongs to exactly one score without.
  4. Paired. Each man belongs to one woman, his partner. That is easy to overlook, because it is about men and women.
  5. Independent. Two groups by random assignment, no pairs.
  6. Neither. One mean against a fixed number: the t-test for one mean from week 2.
NoteExercise 3.3 — The phone in another room

A researcher wants to know whether a phone on the desk affects learning. They randomly assign students to two groups. Group 1 leaves their phone in another room, group 2 keeps it on the desk (sound off). Everyone studies a text for twenty minutes and then takes a test of 40 questions. The researcher doesn’t know whether the phone makes learning better or worse.

Number of correct answers, per group
group n mean correct sxs_x
1 elsewhere (phone in another room) 14 28.1 4.2
2 desk (phone on the desk) 18 23.6 6.4
  1. Write down H0H_0 and HaH_\text{a}.
  2. Which test fits here?
  3. Calculate the standard error of the difference.
  4. Calculate t.
  5. R gives df = 29.29. Between which two limits did it have to lie?
  6. R gives p = .023. What is your decision (α = .05), and what is your conclusion in plain words?
  7. Calculate the 95% interval for μ1−μ2\mu_1 - \mu_2. Use t*t^* = 2.044.
  8. In R you get t = −2.39. How can that be?
  9. With the pooled test, t would be 2.27. Why is that different, and which one do you use?
  10. Without R. Take the lower limit from e as your df. Then, in three steps, with table D: bracket your p; look up the t*t^* that goes with a 95% interval; calculate the interval and put it next to the one from g.
  1. H0H_0: μ1=μ2\mu_1 = \mu_2; HaH_\text{a}: μ1≠μ2\mu_1 \neq \mu_2.
  2. The independent t-test (Welch).
  3. 1.8803.
  4. t = 2.39.
  5. Between 13 and 30.
  6. Reject. With and without a phone on the desk, students score differently on average; in this sample the group without the phone scores higher.
  7. [0.66, 8.34].
  8. R subtracts the groups alphabetically: desk minus elsewhere.
  9. Pooled assumes that both groups spread equally widely in the population. You don’t know that, and 4.2 against 6.4 doesn’t make it plausible. Welch doesn’t need that assumption.
  10. With df = 13: .02 < p < .04, and t*t^* = 2.160, so [0.44, 8.56]. Wider than in g, and 0 still lies outside it.
  1. The hypotheses:

    H0H_0: μ1=μ2\mu_1 = \mu_2 — with and without a phone on the desk, students score equally well on average
    HaH_\text{a}: μ1≠μ2\mu_1 \neq \mu_2 — they score differently on average

    Two-tailed, because the researcher doesn’t know which way it will go.

  2. Two groups by random assignment, nobody is in both: the independent t-test, in Welch’s version.

  3. First the squares, then the two fractions, then add up, then the square root:

    𝑆𝐸=4.2214+6.4218=17.6414+40.9618=1.2600+2.2756=3.5356=1.8803 \begin{aligned} \mathit{SE} &= \sqrt{\dfrac{4.2^2}{14} + \dfrac{6.4^2}{18}} = \sqrt{\dfrac{17.64}{14} + \dfrac{40.96}{18}} \\ &= \sqrt{1.2600 + 2.2756} = \sqrt{3.5356} = 1.8803 \end{aligned}

  4. The difference divided by the ruler:

    t=28.1−23.61.8803=4.51.8803=2.39 t = \dfrac{28.1 - 23.6}{1.8803} = \dfrac{4.5}{1.8803} = 2.39

  5. The lower limit is the smaller of n1−1n_1 - 1 = 13 and n2−1n_2 - 1 = 17, so 13. The upper limit is n1+n2−2n_1 + n_2 - 2 = 30. R sits neatly in between: 29.29.

  6. .023 ≤ .05, so you reject the null hypothesis that students with and without a phone on the desk score equally well on average. Those who left their phone in another room got 4.5 more questions right on average. In APA: t(29.29) = 2.39, p = .023.

  7. The difference, plus and minus t*t^* rulers:

    4.5±2.044×1.8803=4.5±3.843 4.5 \pm 2.044 \times 1.8803 = 4.5 \pm 3.843

    So [0.66, 8.34]. Zero is not in it, just as the test said. An advantage for the phone in another room of 0.66 to 8.34 questions fits these data.

  8. R puts the groups in alphabetical order. The groups are called elsewhere and desk, so R calculates desk minus elsewhere, and that is 23.6 − 28.1 = −4.5. Same test, same p, different sign.

  9. The pooled test combines the two variances, as if both groups spread equally widely in the population. Here the groups are unequal in size and spread unequally (4.2 against 6.4), and then pooling gives a different standard error. You use Welch: it is right even when the spreads differ.

  10. Without R you take the lower limit: df = 13. In row 13 of table D, your t = 2.39 lies between 2.282 (column .02) and 2.650 (column .01). So two-tailed, .02 < p < .04, and R’s p from f, .023, lies in between. Both below .05: reject.

    For the interval you look up the column .025 in the same row, and there you find t*t^* = 2.160.

    4.5±2.160×1.8803=4.5±4.061 4.5 \pm 2.160 \times 1.8803 = 4.5 \pm 4.061

    So [0.44, 8.56], against [0.66, 8.34] in g. With fewer degrees of freedom, t*t^* is bigger (2.160 against 2.044), and the interval wider. That is what we mean by cautious: without R you choose the df that makes it hardest for you to reject. Zero still lies outside it, so the decision stands. R works out Welch’s df exactly; in a report you use R’s.

NoteExercise 3.4 — A week without social media

A group of 20 students fill in a mood questionnaire on Monday morning (higher is a better mood). Then they switch off all social media for a week, and on Friday afternoon they fill in the questionnaire again. For each student you work out the difference: after minus before. On average that difference is d‾\bar{d} = 1.9, with sds_d = 4.6.

  1. Write down H0H_0 and HaH_\text{a}.
  2. Why is this a paired test?
  3. Calculate the standard error, t and df.
  4. R gives p = .080. What is your decision (α = .05)?
  5. Calculate the 95% interval for μd\mu_d. Use t*t^* = 2.093.
  6. Another researcher calculates before minus after. What changes about d‾\bar{d}, t, p and the interval?
  7. Suppose the test had been significant. Could you then say that a week without social media improves mood?
  1. H0H_0: μd=0\mu_d = 0; HaH_\text{a}: μd≠0\mu_d \neq 0.
  2. The same students were measured twice.
  3. SE = 1.0286; t = 1.85; df = 19.
  4. Do not reject.
  5. [−0.25, 4.05].
  6. d‾\bar{d}, t and the interval change sign; p stays the same.
  7. No, there is no group that kept using social media.
  1. The hypotheses:

    H0H_0: μd=0\mu_d = 0 — on average, mood after is just as good as before
    HaH_\text{a}: μd≠0\mu_d \neq 0 — on average, mood changes

  2. Each score after belongs to exactly one score before, from the same student. So you work with one column of differences.

  3. The ruler, then t:

    𝑆𝐸d‾=4.620=1.0286t=1.91.0286=1.85df=20−1=19 \mathit{SE}_{\bar{d}} = \dfrac{4.6}{\sqrt{20}} = 1.0286 \qquad t = \dfrac{1.9}{1.0286} = 1.85 \qquad df = 20 - 1 = 19

  4. .080 > .05, so you do not reject the null hypothesis that mood after is just as good as before, on average. No change has been shown; that does not mean there is no change.

  5. The difference, plus and minus t*t^* rulers:

    1.9±2.093×1.0286=1.9±2.153 1.9 \pm 2.093 \times 1.0286 = 1.9 \pm 2.153

    So [−0.25, 4.05]. Zero is in it, just as the test said. Mood may have got a little worse, but it may also have improved by 4.05 points.

  6. All the differences flip, so d‾\bar{d} becomes −1.9, t becomes −1.85 and the interval [−4.05, 0.25]. The p stays .080: two-tailed, the side doesn’t matter.

  7. No. You only know that mood at the end of the week was different from at the beginning. That may also be down to something else: the weekend coming up, the weather, or the fact that whoever is gloomy on Monday tends to cheer up a bit by Friday anyway. For that you need a comparison group, just as in the sleep study.

NoteExercise 3.5 — Intervals by hand

A memory test has been built so that the standard deviation in the population is σx\sigma_x = 12. You give it to 36 students, and their mean score is x‾\bar{x} = 64.

  1. Calculate the standard error.

  2. Calculate the 95% interval for μx\mu_x. Take z*z^* from the z*z^* row of table D, below row 1000: in the column where the bottom row, C (the confidence level), says 95%.

  3. Also calculate the 90% and the 99% interval, with z*z^* from the same row. Which is the widest, and why?

  4. Test H0H_0: μx\mu_x = 60 two-tailed with α = .05, using only your interval. Do you reject? And with α = .01?

  5. Suppose you do not know σx\sigma_x, and 12 is the standard deviation sxs_x from your sample. Then you need t*t^*, at df = 35. Look it up in table D. That row is not in the table: which one do you take, and why? Calculate the 95% interval again. What does it say about μx\mu_x = 60 now?

  6. How many students do you need for a 95% interval that is half as wide?

  7. Which statement about the 95% interval from b is correct?

    1. 95% of the students score between 60.08 and 67.92.
    2. There is a 95% probability that x‾\bar{x} lies between 60.08 and 67.92.
    3. If you draw 36 students very many times and make an interval like this each time, 95% of those intervals contain μx\mu_x.
    4. μx\mu_x certainly lies between 60.08 and 67.92.
  1. The standard error is 2.
  2. [60.08, 67.92].
  3. 90%: [60.71, 67.29]; 99%: [58.85, 69.15]. The 99% interval is the widest.
  4. With α = .05: reject. With α = .01: do not reject.
  5. Row 30, so t*t^* = 2.042 and [59.92, 68.08]; with R (df = 35) [59.94, 68.06]. Both contain 60, so do not reject.
  6. Four times as many: 144.
  7. Statement C.
  1. SE=1236=126=2SE = \dfrac{12}{\sqrt{36}} = \dfrac{12}{6} = 2.

  2. In the z*z^* row of table D, the column with 95% below it shows the number 1.960: the anchor 1.96, in the column .025. That is because 95% in the middle leaves .025 in each tail.

    64±1.96×2=64±3.9264 \pm 1.96 \times 2 = 64 \pm 3.92, so the interval is [60.08, 67.92].

  3. Only z*z^* changes. In the same row, above 90% it says 1.645, and above 99% it says 2.576:

    • 90%: 64±1.645×2=64±3.2964 \pm 1.645 \times 2 = 64 \pm 3.29, so [60.71, 67.29];
    • 99%: 64±2.576×2=64±5.15264 \pm 2.576 \times 2 = 64 \pm 5.152, so [58.85, 69.15].

    The 99% interval is the widest (10.30 against 6.58). If you want to be surer that you catch μx\mu_x, you have to throw a wider horseshoe.

  4. With α = .05 you look at the 95% interval: 60 lies just below it, so you reject the null hypothesis that μx\mu_x = 60. With α = .01 you look at the 99% interval: 60 lies in it, so then you do not reject the null hypothesis that μx\mu_x = 60.

  5. Row 35 is not in table D: after 30 comes 40. You take the next smaller df that is in the table: 30. That is the cautious side: there the boundary lies a little further out, and your interval gets a little wider. In row 30, column .025: t*t^* = 2.042.

    64±2.042×2=64±4.08464 \pm 2.042 \times 2 = 64 \pm 4.084, so [59.92, 68.08]. R just uses df = 35 as it is: qt(.975, df = 35) = 2.030, and then 64±4.06064 \pm 4.060, so [59.94, 68.06]: on each side, 0.024 narrower. Now 60 lies in both intervals: do not reject. The same data, a different decision, only because you didn’t know σx\sigma_x. t*t^* is bigger than z*z^*, because if you are estimating rather than knowing, you have to throw wider.

  6. The width goes inversely with n\sqrt{n}, because n\sqrt{n} sits below the line in the fraction σxn\dfrac{\sigma_x}{\sqrt{n}}. Right now 36=6\sqrt{36} = 6. Half as wide needs a n\sqrt{n} twice as big, so 12, and 122=14412^2 = 144. In short: a n\sqrt{n} twice as big, so an n four times as big: 144 students. In Figure 8 the three horseshoes lie one below the other; the grey one is the trap of taking twice as many.

    Three horizontal bars, one below the other: the top and bottom ones dark blue, the middle one grey, all three with an open square exactly in the middle, at 64, the mean. The top bar runs from 60.08 to 67.92, labelled above 'n = 36: width 7.84, as in the exercise'. The middle one is shorter but clearly more than half as long, from 61.23 to 66.77, labelled 'n = 72, two times as many: width 5.54, not yet half as wide'. The bottom one is exactly half as long as the top one, from 62.04 to 65.96, labelled 'n = 144, four times as many: width 3.92, half as wide'. At the bottom, an axis 'mean memory score' from 59 to 69. There is no vertical line for μₓ: here you don't know it.
    Figure 8: Three horseshoes, all three 95%, around the same mean (the square, x‾\bar{x} = 64; suppose that with 72 or 144 students you also end up at 64). The grey one is the trap: twice as many people does not make it half as wide, because the width goes inversely with n\sqrt{n}. The narrow horseshoe is still 95%: with more people, x‾\bar{x} jumps around less from sample to sample (you can see that jumping in What 95% means), so a narrower horseshoe catches μx\mu_x just as often. There is no post: here you don’t know μx\mu_x.

    How to read it: the bottom bar, with 144 students, is 3.92 wide: exactly half of the top one, which is 7.84 wide with 36 students. The grey one in between has two times as many students as the top one and is 5.54 wide, more than half. So to halve the width you need four times as many people, not two times as many.

  7. C. A is about individual students, not about μx\mu_x. B is about x‾\bar{x}, and that always lies in the middle of its own interval. D is too sure: even a 95% interval sometimes misses.

NoteExercise 3.6 — In R

Use sleepstudy.

  1. Select the control group, and make a column difference: after minus before. What is the mean difference?
  2. Make a scatterplot of before against after, with the line after = before. How many points lie below the line?
  3. Do the paired t-test in the control group. Give t, df and p, and your conclusion.
  4. For the training group, ask for the 90% and the 99% interval of the paired difference. Which is wider? Does 0 lie in it?
## a. the control group, and the difference ----
control <- sleepstudy[sleepstudy$group == "control", ]
control$difference <- control$worry_after - control$worry_before
mean(control$difference)
[1] -1.066667
## b. the plot, and counting ----
plot(control$worry_before, control$worry_after,
     xlab = "worry score before", ylab = "worry score after")
abline(a = 0, b = 1)
sum(control$difference < 0)
[1] 9
## c. the paired test ----
t.test(control$worry_after, control$worry_before, paired = TRUE)

    Paired t-test

data:  control$worry_after and control$worry_before
t = -0.86827, df = 14, p-value = 0.3999
alternative hypothesis: true mean difference is not equal to 0
95 percent confidence interval:
 -3.701532  1.568199
sample estimates:
mean difference 
      -1.066667 
## d. the training group, 90% and 99% ----
t.test(training$worry_after, training$worry_before, paired = TRUE, conf.level = 0.90)$conf.int
[1] -4.818644 -2.114689
attr(,"conf.level")
[1] 0.9
t.test(training$worry_after, training$worry_before, paired = TRUE, conf.level = 0.99)$conf.int
[1] -5.751685 -1.181649
attr(,"conf.level")
[1] 0.99
A scatterplot of the control group with the line after = before; 9 points lie below the line, 1 on it and 5 above it.
Figure 9: Worry before against after in the control group (answer 3.6b).

How to read it: the point furthest above the line (before 46, after 57) worries 11 points more after, the point furthest below it (before 69, after 61) 8 points less. So in the control group people shift both ways: 9 below the line and 5 above it, against 12 and 1 in the training group (Figure 5). That back and forth largely averages out, and that is why the test in c finds no change.

  1. −1.07: the control group also worries a little less afterwards.

  2. 9 of the 15; 1 lies on it and 5 above it.

  3. t(14) = −0.87, p = .40. You do not reject the null hypothesis that the control group worries as much after as before, on average.

  4. 90%: [−4.82, −2.11]; 99%: [−5.75, −1.18]. The 99% interval is wider. Zero lies in neither: even at α = .01 you reject, for the training group, the null hypothesis that it worries as much after as before.

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: any p-value or t*t^* you need is given. The exam doesn’t ask you to look anything up in a table; you did that in exercises 3.3 and 3.5, to check yourself.

NoteQuestion 1 — multiple choice

Researchers measure, in 50 couples, how many hours a week each partner spends on housework. They want to know whether women spend more time on it on average than men. Which test fits?

  1. the independent t-test, because men and women are two groups
  2. the paired t-test, because each man belongs to one woman
  3. the t-test for one mean, against 0
  4. Levene’s test

B. They are men and women, but they come in pairs (paired samples): each woman has exactly one man, her partner. A is the trap.

NoteQuestion 2 — multiple choice

What is the null hypothesis of a paired t-test?

  1. d‾=0\bar{d} = 0
  2. μd=0\mu_d = 0
  3. μd≠0\mu_d \neq 0
  4. μ1≠μ2\mu_1 \neq \mu_2

B. A is about the sample: you simply calculate d‾\bar{d}. C and D are the alternative hypothesis.

NoteQuestion 3 — fill in

For 25 participants, the mean difference between two measurements is d‾\bar{d} = 2.0, with sds_d = 5.0. What is t? Give two decimals.

2.00. First the ruler, then divide:

𝑆𝐸d‾=5.025=1.0t=2.01.0=2.00 \mathit{SE}_{\bar{d}} = \dfrac{5.0}{\sqrt{25}} = 1.0 \qquad t = \dfrac{2.0}{1.0} = 2.00

with df = 24.

NoteQuestion 4 — yes or no

That t goes with p = .057. Do you reject the null hypothesis that the mean difference in the population is zero (α = .05)?

No. .057 > .05. Watch out: t = 2.00 is bigger than 1.96, but that is the boundary of the z-distribution. With df = 24, the boundary of the t-distribution lies further out, at 2.064.

NoteQuestion 5 — multiple choice

You compare two independent groups, of 12 and 20 people, with Welch’s test. What do you know for certain about the degrees of freedom?

  1. they are exactly 30
  2. they lie between 11 and 30
  3. they are exactly 11
  4. they lie between 19 and 32

B. At least the smallest group minus one (11), at most n1+n2−2n_1 + n_2 - 2 (30). Exactly 30 is the df of the pooled test.

NoteQuestion 6 — multiple choice

What does Levene’s test look at?

  1. whether the two group means are equal
  2. whether the two population variances are equal
  3. whether the two sample variances are equal
  4. whether the scores are normally distributed

B. H0H_0: σ12=σ22\sigma_1^2 = \sigma_2^2, about the population. C is the trap: you already know the sample variances, and they are almost never exactly equal.

NoteQuestion 7 — multiple choice

A researcher compares worry afterwards between two groups and gets this output:


    Welch Two Sample t-test

data:  sleepstudy$worry_after by sleepstudy$group
t = 0.37401, df = 27.951, p-value = 0.7112
alternative hypothesis: true difference in means between group control and group training is not equal to 0
95 percent confidence interval:
 -5.671257  8.204590
sample estimates:
 mean in group control mean in group training 
              52.53333               51.26667 

Which conclusion is correct?

  1. Reject H0H_0: afterwards, the groups worry differently on average.
  2. Do not reject H0H_0: the training has no effect on worry.
  3. Do not reject H0H_0: afterwards, no difference between the groups has been shown.
  4. The difference between the groups is 0.37 points.

C. p = .71 > .05. B says “no effect”: not rejecting is not the same as equal. D confuses t with the difference; the difference is 1.27 points.

NoteQuestion 8 — yes or no

The 95% interval for μ1−μ2\mu_1 - \mu_2 runs from −8.20 to 5.67. Do you reject H0H_0: μ1=μ2\mu_1 = \mu_2 at α = .05?

No. Zero lies in the interval: a difference of zero fits the data.

NoteQuestion 9 — multiple choice

A researcher reports a 95% interval for μx\mu_x of 12.4 to 15.8. Which statement is correct?

  1. 95% of the participants score between 12.4 and 15.8.
  2. There is a 95% probability that the sample mean lies between 12.4 and 15.8.
  3. If you repeat the study very many times and make an interval like this each time, 95% of those intervals contain μx\mu_x.
  4. With a 99% interval, the interval would have been narrower.

C. A is about individual people instead of μx\mu_x. B is about x‾\bar{x}, and that always lies in the middle. D gets it the wrong way round: surer is wider.

NoteQuestion 10 — fill in

Back to question 3: d‾\bar{d} = 2.0, SE = 1.0, df = 24, and t*t^* = 2.064. Calculate the 95% interval for μd\mu_d. Give two decimals.

[−0.06, 4.06]. 2.0±2.064×1.0=2.0±2.0642.0 \pm 2.064 \times 1.0 = 2.0 \pm 2.064. Zero lies just inside it, and that agrees with question 4: there you did not reject the null hypothesis that the mean difference is zero either.

Week 3 at a glance

This week’s two tests side by side
paired independent (Welch)
when the same people twice, or fixed pairs two separate groups
H0H_0 μd=0\mu_d = 0 μ1=μ2\mu_1 = \mu_2
test statistic t=d‾𝑆𝐸d‾t = \dfrac{\bar{d}}{\mathit{SE}_{\bar{d}}} t=x‾1−x‾2𝑆𝐸x‾1−x‾2t = \dfrac{\bar{x}_1 - \bar{x}_2}{\mathit{SE}_{\bar{x}_1 - \bar{x}_2}}
df n−1n - 1, with n the number of pairs R works it out; between min⁡(n1−1,n2−1)\min(n_1 - 1,\ n_2 - 1) and n1+n2−2n_1 + n_2 - 2; without R the lower limit
95% interval d‾±t*⋅𝑆𝐸d‾\bar{d} \pm t^* \cdot \mathit{SE}_{\bar{d}} (x‾1−x‾2)±t*⋅𝑆𝐸x‾1−x‾2(\bar{x}_1 - \bar{x}_2) \pm t^* \cdot \mathit{SE}_{\bar{x}_1 - \bar{x}_2}
in R t.test(after, before, paired = TRUE) t.test(score ~ group, var.equal = FALSE)

And for every interval: if the value of H0H_0 lies in it, you do not reject. The 95% belongs to the throwing, not to one horseshoe.

Back to top