model <- brm(ordered_outcome ~ score + (1 + score | measure_subscale),
data = dt.long, iter=4000, cores=4, chains=4, control = list(adapt_delta = .975), family="cumulative")
predictions <- predict(model) # get predictions for the input datapredictions <- apply(model,1,which.max) # get category with the highest probability for each case
--
You received this message because you are subscribed to the Google Groups "brms-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brms-users+unsubscribe@googlegroups.com.
To post to this group, send email to brms-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brms-users/c1a5d283-af46-4cde-ab5e-93f6802b8def%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
##### simulate
set.seed(1)# the majority of outcomes are category "1"ordered_outcome <- c(rep(1,300),rep(2,150),rep(3,75))measure_subscale <- c(rep(1,100),rep(2,100),rep(3,100), rep(1,50),rep(2,50),rep(3,50), rep(1,25),rep(2,25),rep(3,25))# crude way of simulating a relationship between subscales and outcomescore <- rnorm(length(ordered_outcome), ordered_outcome * measure_subscale, .5)ordered_outcome <- as.ordered(ordered_outcome)measure_subscale <- factor(measure_subscale, levels=1:3, labels=c("A", "B", "C"))dt.lng <- data.frame(ordered_outcome, measure_subscale, score)
## Draw a histogram of the density of scores on each measure subscale by outcomedensplot <- dt.lng %>% ggplot() + aes(x = score, fill=ordered_outcome) + geom_density(show.legend = T) + xlab("score on subscales A, B, and C") + ylab("frequency")densplot + facet_wrap(~measure_subscale)
cumulative_model <- brm(ordered_outcome ~ score + (1 + score | measure_subscale), data = dt.lng, iter=500, cores=4, chains=4, family="cumulative")cumulative_predictions <- predict(cumulative_model) # get predictions for the input datacumulative_predictions <- apply(cumulative_predictions,1,which.max) # get category with the highest probability for each casedt.lng <- cbind(dt.lng, cumulative_predictions)
p <- ggplot(dt.lng) + aes(x = cumulative_predictions, y = ordered_outcome, col=score) + geom_jitter(height=.1,width=.1,alpha=.6) + scale_colour_gradient(low="blue", high="red") + ylab("Outcome; as observed") + labs(col="Observed\nscore", title="family=cumulative (this model looks appropriate)") + xlab("Outcome; as predicted")p + facet_wrap(~measure_subscale)
acat_model <- brm(ordered_outcome ~ score + (1 + score | measure_subscale), data = dt.lng, iter=500, cores=4, chains=4, family="acat")acat_predictions <- predict(acat_model) # get predictions for the input dataacat_predictions <- apply(acat_predictions,1,which.max) # get category with the highest probability for each casedt.lng <- cbind(dt.lng, acat_predictions)
p <- ggplot(dt.lng) + aes(x = acat_predictions, y = ordered_outcome, col=score) + geom_jitter(height=.1,width=.1,alpha=.6) + scale_colour_gradient(low="blue", high="red") + ylab("Outcome; as observed") + labs(col="Observed\nscore", labs="family=acat (this doesn't look right)") + xlab("Outcome; as predicted")p + facet_wrap(~measure_subscale)
# everyone gets predicted level "3"# in my 'real' dataset there is some variation in predictions (not everyone # is predicted to fall into the same category) but the predictions are about # as unreasonabletable(dt.lng$acat_predictions)
Hmm this sounds strange. Maybe there is a problem with the prediction of 'acat'. Would you mind writing a short reproducible example of your problem?
2017-12-16 22:42 GMT+01:00 Peter Phalen <peter....@gmail.com>:
I seem to be getting very different predictions when I fit a multilevel model using the "acat" family rather than the "cumulative" family.I'm trying to fit a multilevel model where the outcome is a 3-level ordinal category. I'm estimating whether higher scores on a measure of a theoretical construct predict higher levels of the outcome variable, and I'm particularly interested in variability by subscale.The code I'm using:model <- brm(ordered_outcome ~ score + (1 + score | measure_subscale),data = dt.long, iter=4000, cores=4, chains=4, control = list(adapt_delta = .975), family="cumulative")predictions <- predict(model) # get predictions for the input datapredictions <- apply(model,1,which.max) # get category with the highest probability for each case
The above code gives sensible predictions that roughly match what I get by fitting a series of unpooled proportional odds logistic regressions for each of the different subscales. However, when I run the same code with family set to "acat" (rather than "cumulative") I get very different predictions that don't really match the data. For example, the majority of predictions end up in favor of the category that has the lowest observed count...Perhaps I'm doing something wrong in processing the predictions?Thank you!
--
You received this message because you are subscribed to the Google Groups "brms-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brms-users+...@googlegroups.com.
if (!require("devtools")) { install.packages("devtools") } devtools::install_github("paul-buerkner/brms", dependencies = TRUE)
For the predicitons to work correctly, you have to refit your acat model.
To unsubscribe from this group and stop receiving emails from it, send an email to brms-users+unsubscribe@googlegroups.com.
To post to this group, send email to brms-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brms-users/d1a1169a-0fe2-470c-92e6-44b31836040f%40googlegroups.com.