When to exponentiate: the mean of the chain or at every step in the chain?

I am interested in when it is best to exponentiate a difference in log-odds

Here is a sample problem in the stan language, three groups of forty binary observations, group 1 with hit probability = 0.2, group 2 with hit probability of 0.5, group 3 with hit probability of 0.8. I want to calculate the odds ratio for the comparison of group 1's hit rate to group 2's, but I am not sure when to exponentiate the difference in log odds.

# create data
df <- data.frame(group = factor(rep(letters[1:3],times=40)), hit = rbinom(120, 1, prob = c(.2,.5,.8)))

# put data into list
dList <- list(N = nrow(df),
nG = nlevels(df$$group), gIndex = as.integer(df$$group),
#  0.1131707

Method 2

The other way to do it is to once again subtract the log odds estimates for group 2 from the log odds estimates from group 1, but to then exponentiate each of those difference scores and take the mean of those exponentiated scores, like so:

df <- df %>% mutate(e_diff12 = exp(a.1 - a.2))
mean(df\$e_diff12)
#  0.1372593

As you can see the odds ratios are different using the two different methods, so which is the more correct way to do it?

Odds ratio (g1 vs g2) = odds(Y=1|g1)/odds(Y=1|g2) = exp(log(odds(Y=1|g1))-log(odds(Y=1|g2))) = exp(a1-a2).

First "=" comes from the definition of odds ratio.

Second "=" comes from x/y = exp(log(a)-log(b))

Third "=" comes from the definition of logistic regression.

For any 2 subjects A and B, let $$X_A$$ and $$X_B$$ are their values on covariates, then

OR(A vs B) =exp($$X_A\beta - X_B\beta)$$ = exp($$(X_A-X_B)\beta)$$

• Thank you user158565. So method 2 was the more correct? – llewmills Aug 2 at 3:21
• Yes. Method 2 is correct (not more correct). – user158565 Aug 2 at 3:23
• I am not sure your R code is correct. I am not familiar with R. But exp(a.1 - a.2) is correct. – user158565 Aug 2 at 3:33