The five steps
Every hypothesis test follows the same five steps: state the hypotheses, check the validity conditions, compute the test statistic, compute the p-value, and state the conclusion. Tests differ only in the statistic and its null distribution, the distribution of the statistic when H\(_0\) is true.
The test statistic
A standardized statistic measures how far the statistic is from the null mean (the mean of its null distribution), in null SDs (the standard deviation of that distribution). When H\(_0\) is true, \(\hat{p}\) has mean \(\pi_0\) and standard deviation \(\sqrt{\pi_0(1-\pi_0)/n}\).
$$\text{standardized statistic} = \dfrac{\text{statistic} - \text{null mean}}{\text{null SD}}$$
$$Z = \frac{\hat{p} - \pi_0}{\sqrt{\pi_0(1-\pi_0)/n}}, \qquad \hat{p} = \frac{k}{n}$$
Validity conditions
The standard normal is a good approximation to the null distribution when \(n\pi_0 \geq 10\) and \(n(1-\pi_0) \geq 10\): at least 10 expected successes and 10 expected failures. When the conditions fail, use the simulated p-value.
The simulation
Each simulated sample draws \(k^* \sim \text{Binomial}(n, \pi_0)\), the number of successes in \(n\) trials when H\(_0\) is true, and computes \(Z^*\) from it with the same standard error. The simulated p-value is the fraction of the \(Z^*\) values at least as extreme as the observed \(Z\), in the direction of H\(_a\).
Why the two p-values differ
The count \(k\) is a whole number, so the simulated null distribution is a set of separate bars. The simulated p-value counts the whole bar at the observed \(k\). The normal curve's area starts at the middle of that bar and covers about half of it. At the starting values, samples with exactly 30 or exactly 20 successes have probability 0.084 together, and half of that is most of the gap between the theory p-value, 0.157, and the simulated p-value, near 0.20. R's prop.test() moves \(k\) half a success toward \(n\pi_0\) by default (the continuity correction) for this reason, which gives 0.2031. The course's Z-tests, and the p-values on these tabs, use correct = FALSE.
Strength of evidence
p > 0.10: little or weak evidence against H\(_0\).
0.05 < p ≤ 0.10: moderate evidence.
0.01 < p ≤ 0.05: strong evidence.
p ≤ 0.01: very strong evidence.
In R
2 * (1 - pnorm(abs(z))) gives the two-tailed p-value, 1 - pnorm(z) the right-tailed, and pnorm(z) the left-tailed. prop.test(30, 50, p = 0.5, correct = FALSE) runs the whole test; its X-squared is \(Z^2\).