# Why does the required N differ for for the z-test vs logistic regression?

Why is the power analysis for a univariate logistic regression (one binary predictor) different depending on whether you

1. treat the power analysis as 'power for the difference in proportions between two independent samples', or
2. power for an odds ratio based on the same two proportions?

Specific example:
Some intervention is expected to produce a difference in the proportion of negative events from 23% to 15% in a randomized group design. G-power's power analysis gives:

# Input:
Test family:       z tests
Statistical test:  Proportions: Difference between two independent proportions
Analysis:          A priori: Compute required sample size
Tail(s)                 =   One
Proportion p2           =   .23
Proportion p1           =   .15
α err prob              =   0.05
Power (1-β err prob)    =   0.95
Allocation ratio N2/N1  =   1

# Output:
Critical z          =   1.6448536
Sample size group 1 =   518
Sample size group 2 =   518
Total sample size   =   1036


If I hand calculate the OR for this expected effect using $\text{odds(event group 1)} = .23/(1-.23) = .30$ and $\text{odds(event group 2)} = .15/(1-.15) = .18$. Then ${\rm OR} = .30/.18 = 1.67$. For that G-power gives:

# Input:
Test family:        z tests - Logistic regression
Statistical test:   Large sample z-Test, Demidenko (2007) with var corr
Analysis:           A priori: Compute required sample size
Tail(s)              =  One
Odds ratio           =  1.67
Pr(Y=1|X=1) H0       =  .23
α err prob           =  0.05
Power (1-β err prob) =  0.95
R² other X           =  0
X distribution       =  Binomial
X parm π             =  0.5

# Output:
Critical z        = 1.6448536
Total sample size = 827
Actual power      = 0.9501531


It's $827$ vs $1036$, so not a huge difference, but I would like to understand.

There are two issues here. First, you computed your odds ratio backwards relative to what your situation is. That is, if you take $.23$ as the base rate, the odds ratio that moves you to $.15$ is $.6$, not $1.67$:
$$\text{odds ratio(group 1, group 2)} = \frac{\frac{.18}{1-.18}}{\frac{.23}{1-.23}} = .6$$ If you do that, you will get nearly the same answer:
Now, why isn't $1096$ exactly $1036$ instead? The answer seems to be that in this setup G*Power is assuming $X$ is randomly sampled from a binomial with equal proportions, rather than being forced to always have exactly the same $N$ per group, and that induces a slight amount of additional noise that needs to be squeezed out by a slightly higher total $N$.