
Statistical Methods with R
Unit B · Chapter 05 · Lecture 05a
Developed by Jeffrey M. Girard
Imagine that we study nutrition and obesity
Participants really like a brand of “low sugar” cereal
The label claims that it only contains 3 g of sugar per serving
However, we think this may be false advertising!
We buy a sample of 20 cereal boxes from various stores
We measure the amount of sugar per serving in each box
Is 3 g a reasonable estimate of the population mean?
\(H_1\) is a “one-sided” and \(H_2\) is a “two-sided” hypothesis.
In null hypothesis significance testing (NHST), the null hyp. is the defense and the alternative hyp. is the prosecution
The statistical test is the judge and jury (makes the decision)
NHST helps protect the null hypothesis from researchers who are incentivized to disprove it.
| Retain \(H_0\) | Reject \(H_0\) | |
|---|---|---|
| \(H_0\) is True | Correct Retain | Type I Error |
| \(H_0\) is False | Type II Error | Correct Reject |
| Retain \(H_0\) | Reject \(H_0\) | |
|---|---|---|
| \(H_0\) is True | \(1-\alpha\) | \(\text{[I] }\alpha\) |
| \(H_0\) is False | \(\text{[II] }\beta\) | \(1-\beta\) |
How far from zero is too far? When do we reject the null?
We look at the sampling distribution of \(\Delta\) under the null
We can use this to make our statistical decision
To set \(\alpha=.05\), we reject the null if the test statistic is outside the middle 95% of its null sampling distribution
The math becomes easier if we standardize the test statistic by dividing it by its standard error
\[ z_{\bar{x}} = \frac{\bar{x} - \mu_0}{\sigma / \sqrt{n}} \\ z_{\bar{x}} \sim \mathcal{N}(0, 1) \]

Critical values: \(|z_{\bar{x}}| > 1.96\) (i.e., it falls in the red regions)
This \(z\)-test is rarely used because \(\sigma\) is rarely known
Instead, we estimate \(\sigma\) using \(s\) and use the \(t\)-test
With a small sample, the critical values are now higher
\[ t_{\bar{x}} = \frac{\bar{x} - \mu_0}{s / \sqrt{n}} \\ t_{\bar{x}} \sim t(n-1, 0, 1) \]

Critical values: \(|t_{\bar{x}}| > 2.09\) (i.e., it falls in the red regions)
Imagine \(H_0\) is true \((\mu=3)\) and we collect the following sample of 20 cereal boxes


\(|t_{\bar{x}}|<t_{crit}: \text{Retain }H_0\)
Imagine \(H_0\) is false \((\mu=4)\) and we collect the following sample of 20 cereal boxes


\(|t_{\bar{x}}|>t_{crit}: \text{Reject }H_0\)
Correct p-value Definitions
The \(p\)-value is the smallest \(\alpha\) value that would reject the null hypothesis.
The \(p\)-value is the probability of observing a test statistic at least as extreme as ours.
Wrong p-value Definition
The \(p\)-value is the probability that the null hypothesis is true.
| Notation | Stars | Translation | Decision |
|---|---|---|---|
| p ≥ .05 | Test was NOT significant at α=.05 | Retain Null | |
| p < .05 | * | Test was significant at α=.05 | REJECT Null |
| p < .01 | ** | Test was significant at α=.01 | REJECT Null |
| p < .001 | *** | Test was significant at α=.001 | REJECT Null |
t.test()model_parameters()fit1 <- t.test(sugar_null, mu = 3)
library(easystats)
model_parameters(fit1)
## One Sample t-test
##
## Parameter | Mean | mu | Difference | 95% CI | t(19) | p
## ------------------------------------------------------------------
## sugar_null | 3.09 | 3 | 0.09 | [2.96, 3.22] | 1.42 | 0.171
##
## Alternative hypothesis: true mean is not equal to 3One Sample t-test
Parameter | Mean | mu | Difference | 95% CI | t(19) | p
------------------------------------------------------------------
sugar_null | 3.09 | 3 | 0.09 | [2.96, 3.22] | 1.42 | 0.171
Alternative hypothesis: true mean is not equal to 3
“The mean sugar content per serving in our sample was 3.09 g, 95% CI: [2.96, 3.22], which was not significantly different from the 3 g stated on the label, \(t(19)=1.42\), \(p=.171\). Thus, we retain the null hypothesis that there are 3 g of sugar per serving.”
fit2 <- t.test(sugar_alt, mu = 3)
model_parameters(fit2)
## One Sample t-test
##
## Parameter | Mean | mu | Difference | 95% CI | t(19) | p
## ------------------------------------------------------------------
## sugar_alt | 4.02 | 3 | 1.02 | [3.65, 4.39] | 5.70 | < .001
##
## Alternative hypothesis: true mean is not equal to 3One Sample t-test
Parameter | Mean | mu | Difference | 95% CI | t(19) | p
------------------------------------------------------------------
sugar_alt | 4.02 | 3 | 1.02 | [3.65, 4.39] | 5.70 | < .001
Alternative hypothesis: true mean is not equal to 3
“The mean sugar content per serving in our sample was 4.02 g, 95% CI: [3.65, 4.39], which was significantly greater than the 3 g stated on the label, \(t(19)=5.70\), \(p<.001\). Thus, we reject the null hypothesis that there are 3 g of sugar per serving.”