Suppose that the effect of some treatment $D = 0, 1$ on the outcome $Y = 0,1$ is confounded by sex $S = 0,1$. An unconfounded estimate of the causal effect of $D$ on$Y$ would see us estimate the within strata risks and then weight those by the prevalence of the strata prior to taking their difference. Mathematically, we would compute
$$ E[Y(D=d)] = \sum_s E[Y \mid D=d, S=s] P(S=s) $$
for each $d$ and then take the difference. If one were to simply write out the naive difference in means estimator, one would discover that the weights are incorrect, which is a cause of the counfounding
$$ E[Y\mid D=d] = \sum_s E[Y \mid D=d, S=s] P(S=s \mid D=D) $$
Note that through Bayes rule
$$ P(S=s \mid D=D) = \dfrac{P(D=D \mid S=S) P(S=s)}{P(D=d)} $$
which is a function of the propensity score and the correct weights $P(S=s)$. However, simply weighting the estimates of $E[Y \mid D=d]$ by the inverse of the propensity score leaves a factor of $1/P(D=d)$ in the expression for $E[Y \mid D=d]$.
Why does IPTW result in the correct estimate of the causal contrast then? I would appreciate an answer which appeals to weighted sums of expectations as I've written here. In particular, I'm hoping to demonstrate that IPTW leads to an expression similar to the first equation I've presented.
EDIT:
Here is my own attempt
Let the weights for each sum be
$$ w(s) = \dfrac{1}{\Pr(D=d \mid S=s)}$$
These are not guaranteed to sum to 1, so let's compute their sum and create new, normalized, weights.
$$ \sum_s w(s, d) = \dfrac{1}{\Pr(D=d \mid S=0)} + \dfrac{1}{\Pr(D=d \mid S=1)}$$
Finding a common denominator...
$$ \sum_s w(s, d) = \dfrac{\Pr(D=d \mid S=1) + \Pr(D=d \mid S=0)}{\Pr(D=d \mid S=1) \times \Pr(D=d \mid S=0)}$$
Now, here is where things get ugly. Let's first acknowledge that
$$ \Pr(D=d \mid S=s) = \dfrac{\Pr(S=s \mid D=d) \Pr(D=d)}{\Pr(S=s)}$$
If we replace the conditional probabilities of $D$ in numerator and denomintor, then the factor of $\Pr(D=d)$ pops out. We get one factor in the numerator and 2 in the denominator, so
$$ \sum_s w(s, d) = \dfrac{f(s, d)}{\Pr(D=d)} $$
where $f$ is the expression re-written using Bayes rule. The important part is that we get the factor of $\Pr(D=d)$ for doing so.
Now, define $\Omega(s, d) = \dfrac{w(s, d)}{\sum_s w(s, d)} = \dfrac{w(s) \Pr(D=d)}{f(s, d)} = \dfrac{\Pr(D=d)}{\Pr(D=d \mid S=s) f(s, d)} $
and so the weighted sum using $\Omega(s, d)$ as the weights has the factor which we need to cancel out the "wrong" weights in the naive difference in means.
My gut says $f(s, d) = 1$ but I'm not sure and have yet to prove so.