Usage of $\hat p$ and $p_0$ in confidence intervals/hypothesis testing Cheers, I have a question about the usage of $\hat p$ and $p_0$ when talking about the confidence intervals of proportion problems.
My professor and my textbook both state that for Bernoulli trials (So $X_1, X_2, \cdots X_n$, $X_i \sim Bernoulli(p)$), with $n \geq 30$, then $$Z = \frac{\hat p - p_0}{\sqrt{\frac{\hat p (1- \hat p)}{n}}}$$, and $Z \sim N(0,1)$
However, I came across a webpage, and some tutorials which instead of the above type, they used the following one: $$Z = \frac{\hat p - p_0}{\sqrt{\frac{ p_0 (1- p_0)}{n}}}$$
Why is that change there on the variance? Does it have to do with the sample size, or is it something I am omitting or understanding wrong? Thanks a lot.
EDIT: An answer is given in the note here, but I would like a more intuitive explanation if possible =)
 A: Before answering your question, let me clear a few things up.
I assume that $\hat{p}$ is the empirical estimator for the unknown parameter $p$, that is $\hat{p} = \frac{1}{n} \cdot \sum_{i=1}^n \mathbf{1} \{ X_i = 1 \}$.
The test statistic
$$
Z_n = \frac{\hat{p}_n - p}{\sqrt{ \frac{\hat{p}_n (1-\hat{p}_n)}{n}}}
$$
is not distributed as $Z_n \sim \mathcal{N}(0,1)$ for $n \geq 30$.
The formally correct statement is that distribution of the test statistic $Z_n$ approaches a normal distribution as $n$ grows.
The formal statement is that $Z_n$ approaches $Z \sim \mathcal{N}(0,1)$ in distribution.
When we construct confidence intervals, we often make the "asymptotic approximation" by pretending that $Z_n \sim \mathcal{N}(0,1)$.
This is how we get $(1 - \alpha)$-confidence intervals of the form
$\hat{p}_n \pm \Phi^{-1}(1 - \alpha)\sqrt{ \frac{\hat{p}_n (1-\hat{p}_n)}{n}}$, where $\Phi^{-1}: [0,1] \rightarrow \mathbb{R}$ is the quantile function of the normal distribution.
We can only prove the validity of these confidence intervals asymptotically as $n \rightarrow \infty$.
But, we often smudge things by saying that a finite sample size $n$ (say, 30) is close enough in practice.

Okay, to answer your question: your professor gave you $\sqrt{ \frac{\hat{p}_n (1-\hat{p}_n)}{n}}$ as an estimate for the variance. This is something that you can obtain from your data - it is a quantity that is known to you.
On the other hand, using $\sqrt{ \frac{p (1-p)}{n}}$ would be great, but it's impractical because you do not know the true parameter $p$ from your data.
So, the relevant test statistic to analyze is $\sqrt{ \frac{\hat{p}_n (1-\hat{p}_n)}{n}}$.
Both of these quantities would yield a test statistic $Z_n$ is asymptotically normal. But, again, only on of them is computable from your data.
