0

In this method for calculating marginal effects for a binomial logit using rstanarm, https://stackoverflow.com/a/45042387/9264004

nd <- md
nd$x1 <- 0
p0 <- posterior_linpred(glm1, newdata = nd, transform = TRUE)
nd$x1 <- 1
p1 <- posterior_linpred(glm1, newdata = nd, transform = TRUE)
ME <- p1 - p0
AME <- rowMeans(ME)

Can intervals for the marginal effects be calculated by taking quantiles, like this:

QME <- quantile(AME, c(.025,.25,.5,.75,.975))

or is there a more correct way to calculate a standard error for the effect?

1 Answers1

0

If you are interested in the posterior standard deviation of the average (over the data) "marginal" effect of changing x1 from 0 to 1, then it would be sd(ME) or possibly mad(ME). But if you want quantiles, then call quantile.

Ben Goodrich
  • 4,870
  • 1
  • 19
  • 18
  • Is this equivalent to the standard errors for average predictive comparisons in Gelman and Hill? (p. 472-473). I'm quite new to Bayesian analysis, and I thought maybe I should be using posterior_predict instead. Wanted to get the intervals right. – user34773 Jan 25 '18 at 17:09
  • If you are interested in the way that a minimal change in `x1` affects the conditional mean of the outcome, then the code you wrote with `posterior_linpred` is correct. If you were interested in the way that a minimal change in `x1` affects the predictions, then `posterior_predict` is appropriate. But `x1` has a much more precisely estimated effect on the conditional mean than on the predictions due to the latter including the stochastic component of the outcome. `posterior_predict` is under-utilized and `posterior_linpred` is over-utilized but the latter is convenient for Bernoulli models. – Ben Goodrich Jan 25 '18 at 19:18