I have seen this, and this and a few YouTube videos, and I'm still stuck.
I understand how the probability integral transform gives rise to the result that the CDF of the p-values will have a uniform distribution.
What I don't understand is why that implies that the p-values themselves have a uniform distribution.
That is, I understand this much:
Suppose X ~ Unif(a, b). Then the CDF of X is:
$$P(X \le x) = \begin{cases} 0\ \ {\rm{if}}\ \ x \le a \\ (x-a)/(b-a)\ \ {\rm{if}} \ \ a \le x < b \\ 1\ \ {\rm{if}}\ x \ge b \end{cases}$$
So if X ~ Unif(0, 1), then $$P(X \le x) = x$$ (just substituting a=0 and b=1).
Now suppose $$Y = F(X)$$, and we want to know the probability distribution of Y. That is, we want to know the probability distribution of the CDF of X.
We know that the CDF of a distribution is a unique identifier of a distribution, so if you see, for example, $P(X \le x) = x$ then you know X ~ Unif(0, 1).
We also know that CDFs are right-continuous, and they go from 0 to 1. So it's reasonable to pick a value, f, that lies between 0 and 1 and try to find the probability that the CDF, Y, takes a value less than or equal to f:
$$\begin{align*} P(Y \le f) &= P(F(X) \le f) \\ &= P(X \le F^{-1}(f)) \ {\rm{assuming\ F\ is\ invertible}} \\ &= F(F^{-1}(f)) \\ &= f \end{align*}$$
So since $P(Y \le f) = f, Y = F(X)$ must follow a uniform distribution.
This implies that for any continuous random variable (that satisfies some properties that I'm not sure of), the CDF of that continuous random variable will have a Unif(0, 1) distribution.
It does NOT imply that the random variable itself has a Unif(0, 1) distribution. That is, it does not mean that X has a Unif(0, 1) distribution, only that F(X) has a Unif(0, 1) distribution.
So if a test statistic has a continuous distribution, then the CDF of that test statistic has a Unif(0, 1) distribution. Why does this mean that the p-values have a uniform distribution?
Wait...are p-values the CDF of a test statistic?
Clearly I'm tying myself in knots here. Any help would be appreciated.
EDIT (responding to a comment):
Here's my line of thinking since sleeping on it.
If we have $P(X \le x) = x$, then X ~ Unif(0,1).
Since $P(F(X) \le f) = f$, that means $F(X)$ ~ Unif(0,1), right?
But why does this lead us to think that p-values are uniformly distributed if the null hypothesis is true?
Suppose for instance we have:
$$H_0: \mu \ge 0$$ $$H_a: \mu < 0$$,
and $\sigma$ is known. Let $ts$ be the test statistic, which has a non-standard normal distribution. After standardization, let the z-score associated with the test statistic be $z_{ts}$.
Then we would reject $H_0$ if $P(Z < z_{ts}) < 0.05$. That is, we would reject $H_0$ if the p-value is less than 0.05.
The form $P(Z < z_{ts})$ is the same kind of form as a CDF, right? If the test statistic is continuous then this is the same as $P(Z \le z_{ts})$.
Now let $F(Z) = P(Z \le z_{ts})$.
Is this really a CDF? If so, then what?
What about when we have other alternative hypotheses (like $H_a: \mu > 0$ or $H_a: \mu \ne 0$)?