How can I generate the posterior probability distribution for each outcome for each predictor in an ordinal regression?
e.g. what I am looking for is this:
library(rstanarm)
fit_f <- MASS::polr(tobgp ~ agegp, data = esoph)
predict(fit_f,newdata=data.frame(agegp=factor(levels(esoph$agegp))),type = "probs")
Now with rstanarm I do:
fit <- stan_polr(tobgp ~ agegp, data = esoph, method = "logit",
prior = R2(0.2, "mean"), init_r = 0.1, seed = 12345)
But how do I obtain the distribution for the individual outcomes/predictors? I do get a distribution of probabilities using epred, but I don't understand for which outcome/predictor?
posterior_epred(fit, newdata=data.frame(agegp=factor(levels(esoph$agegp))))
The easiest way to do this in rstanarm is to use the
posterior_predictfunction to obtain posterior predictions and then calculate the proportion of predictions that fall in each outcome category by observation. In code,The matrix called
probshas rows equal to the number of observations (inesoph) and columns equal to the number of categories intobgpand each of its rows sums to 1.