Hi Michael,Can you update to the just-released update of rstanarm on CRAN (version 2.9.0-3)? We added a Note section to the documentation for posterior_predict that explains how N is handled for binomial models and changed some things internally related to this.If you don't specify newdata when calling posterior_predict the Ns are the Ns from the original data. If you do specify newdata then you should be required to specify your own Ns and get an error otherwise (the error wasn't being thrown in the first version of rstanarm). In your case, since the LHS of your formula is cbind(K, N-K) you could include in newdata a variable K=0 and a variable N that has the number of trials you want to use. If there are multiple observations in newdata N can be different for each of them. The predicted counts can then easily be divided by the number of trials if you want probabilities.Relatedly, we don't recommend trying to directly use the posterior distribution of the inverse-logit transformed linear predictor (i.e., the predicted probabilities), but rather to always sample from the posterior predictive distribution of the outcome. If you want you can then get probabilities by division, as mentioned above.
Hi Jonah,I'm bumping this thread because I have a related question.I have a *bernoulli* GLMM for which I would like to plot predicted *probabilities* (similar to e.g. the predict method for a normal R glm, type = "response"). Is the only way to approximate these by switching the model formula to *binomial* (with one trial per row in my original data) and then using posterior_predict to approximate the probabilities?
predicted_prob <- function(fit) { dat <- rstanarm:::pp_data(fit) eta <- rstanarm:::pp_eta(fit, dat)$eta plogis(eta) # inverse-logit }
Could you expand on why directly using the posterior of the inv-logit is not recommended?
predicted_prob <- function(fit, newdata = NULL) { if (is.null(newdata)) {
dat <- rstanarm:::pp_data(fit) eta <- rstanarm:::pp_eta(fit, dat)$eta plogis(eta) # inverse-logit
} else { eta <- rstanarm:::pp_eta(fit, newdata)$eta plogis(eta) # inverse-logit }}
In the example code you provided, is there a way to pass new data (i.e. a data frame to make predictions over) to those internal methods?My attempt
predicted_prob <- function(fit, newdata = NULL) {if (is.null(newdata)) {dat <- rstanarm:::pp_data(fit)eta <- rstanarm:::pp_eta(fit, dat)$etaplogis(eta) # inverse-logit} else {eta <- rstanarm:::pp_eta(fit, newdata)$etaplogis(eta) # inverse-logit}}gives a bug in pp_eta, presumably because the dataframe I'm passing doesn't correspond to some internal dataframe expected.
No, that also resulted in an error (fails on is.mer).
--
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/GS8_8djvke4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
To post to this group, send email to stan-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.