The z test of proportions assumes your samples are independent (your single index $i$ for both $X$ and $Y$ and your indication of a regression context implies that these are paired, not independent observations).
Therefore, McNemar's test (1947) is an appropriate test for association in paired binary data:
The positivist null hypothesis is that $X$ and $Y$ are not associated, with the positivist alternative being that $X$ and $Y$ are associated. One way of expressing this is:
$$H_{0}{+}: P(Y=1|X=0) = P(Y=1|X=1)\text{, and}$$
$$H_{\text{A}}^{+}: P(Y=1|X=0) \ne P(Y=1|X=1)$$
Another way of expressing it is:
$$H_{0}{+}: P(Y=1|X=0) = P(X=1|Y=0)\text{, and}$$
$$H_{\text{A}}^{+}: P(Y=1|X=0) \ne P(X=1|Y=0)$$
There are still other ways (e.g., using odds ratios, etc.)
McNemar's test uses counts of pairs:
- $X=0, Y=0$ (concordant pair)
- $X=1, Y=0$ (discordant pair, call this count $r$)
- $X=0, Y=1$ (discordant pair, call this count $s$)
- $X=1, Y=1$ (concordant pair)
And specifically, McNemar's test only uses counts of discordant pairs (i.e. $r$ and $s$) to construct it's test statistic (the below formulation includes a continuity correction (i.e. counts are discrete by definition, but $\chi^{2}$ distribution is actually continuous):
$$\chi^{2} = \frac{|(r-s)|-1^{2}}{r+s}$$
This test statistic has a single degree of freedom, and $p = P(X^{2}_{\nu=1} > \chi^{2})$.
Per Bennett and Underwood (1970) "The McNemar test is in fact UMP for $p'=\frac{1}{2}$ against alternatives $p'\ne\frac{1}{2}$ by an argument similar to that of Lehmann ([1959], section 4.7)."
McNemar's test expresses the degree of association using an odds ratio $= \frac{r}{s}$, where $OR=1$ is consistent with no association, $OR>1$ are consistent with the odds of $Y=1$ being greater for $X=1$ relative to $X=0$, and vice versa. The confidence interval for this OR is $e^{\ln (\frac{r}{s})-z_{\alpha/2}\sqrt{(r+s)/rs}}$, $e^{\ln (\frac{r}{s})+z_{\alpha/2}\sqrt{(r+s)/rs}}$.
McNemar's test can also be framed as a test for equivalence with the negativist null hypothesis that $X$ and $Y$ are associated by at least $\Delta$ (your equivalence threshold, aka the relevant association you care about). $\Delta$ in this application takes values between 0 (zero association) and 1 (perfect association). The alternative hypothesis is that $X$ and $Y$ do not have an association as strong as $\Delta$ or stronger.
Interestingly, the test statistics for McNemar's equivalence test (in the TOST framework) are z distributed, not $\chi^{2}$ distributed (Liu, et all, 2002):
$z_{1} = \frac{n\Delta - [(r-s) - 1]}{\sqrt{(r+s)-n(\frac{r}{n}-\frac{s}{n})^{2}}}$, and
$z_{2} = \frac{[(r+s)+1]+n\Delta}{\sqrt{(r+s)-n(\frac{r}{n}-\frac{s}{n})^{2}}}$
These statistics have been constructed for upper tail rejection regions:
$p_{1} = P(Z > z_{1})$, and
$p_{2} = P(Z > z_{2})$
Only if both $p_{1} \le \alpha$ and $p_{2} \le \alpha$ can you reject the negativist null hypothesis, and conclude equivalence.
References
Bennett, B. M., & Underwood, R. E. (1970). 283. Note: On McNemar’s Test for the 2 $\times$ 2 Table and Its Power Function. Biometrics, 26(2), 339–343.
Liu, J., Hsueh, H., Hsieh, E., & Chen, J. J. (2002). Tests for equivalence or non-inferiority for paired binary data. Statistics In Medicine, 21, 231–245.
McNemar, Q. (1947). Note on the Sampling Error of the Difference Between Two Correlated Proportions or Percentages. Psychometrika, 12(2), 153–157.