I am trying to check my understanding of the relationship between p-values and type I error rates. I am going to use the following example to do so, so I would appreciate any feedback on it.
Suppose we are given an i.i.d. sample $\mathbf{X}$ of size $n$ from $N(\mu,\sigma^2)$, where $\mu = 0$ and $\sigma^2 = 1$. Suppose that we did not know the true values of $\mu$ and $\sigma^2$ beforehand, and that we want to test the null hypothesis \begin{align} H_0 &: \mu = 0 \end{align} This can be done using a simple $t$-test. If $\overline{\mathbf{X}}$ is the sample mean of $\mathbf{X}$ and $\hat{\sigma}^2$ is its sample variance, then we define the test statistic $T(\mathbf{X},\mu)$ as $$ T(\mathbf{X},\mu) = \frac{\overline{\mathbf{X}} - \mu}{\sqrt{\hat{\sigma}^2 / n}} $$ Under the null hypothesis, this test statistic becomes $$ T(\mathbf{X},0) = \frac{\overline{\mathbf{X}}}{\sqrt{\hat{\sigma}^2 / n}} $$ which is $t$-distributed with $n$ degrees of freedom. To decide whether to reject $H_0$ or not, we compute a p-value, and if it is less than some significance level $\alpha$ (say 0.05), then we reject $H_0$. However, as p-values are random variables that depend on the sample $\mathbf{X}$, then there is a chance that we observe some sample $\mathbf{X}$ for which we compute a p-value that is less than $\alpha$, and therefore reject $H_0$, even though it is actually true. This chance is the type I error rate.
Is my understanding, as demonstrated by this example, correct?