I'm a PhD student in psycholinguistics and I'm having trouble in modeling some ordinal data. I have an ordinal response (completely disagree, disagree, neutral, agree, completely agree) and two categorical predictors (order: um-todo x todo-um; number: singular x plural). Initially, I tried to fit an ordered logit model (fitted with polr
function in MASS
package in R
). For this model, I could extract predicted probabilities (using the predict()
function) and plot these probabilities with ggplot2
, using the code below:
# Make new data from the original one
novo<- data.frame(
ordem = dados$Ordem,
num = dados$Num
)
# Make the predictions
novo <-cbind(novo, predict(model, type = "probs"))
# Organize everything in a new table
lnovo<-melt(novo, id.vars = c("ordem", "num"),
variable.name = "Respostas", value.name = "Probabilidade")
# Prepare some colors
paleta<-c("#D7191C", "#FDAE61", "#9C9C9C", "#ABDDA4", "#2B83BA")
# Reorder for the factor todo-um be in the base level
lnovo$ordem<-relevel(lnovo$ordem, ref = "todo-um")
# And then plot the graph
ggplot(lnovo, aes(x = num, y = Probabilidade, group=Respostas, colour = Respostas))+
geom_line()+geom_point()+
facet_grid(~ordem)+
scale_y_continuous(breaks=seq(from = 0, to = 1, by = 0.1),
labels = scales::number_format(accuracy = 0.01))+
scale_colour_manual(values=paleta,
labels=c("Discordo_Totalmente", "Discordo", "Neutro", "Concordo", "Concordo_Totalmente"))+
labs(x = "Número da anáfora", y = "Probabilidades preditas", fill="Respostas")+
ggtitle("Previsão de probabilidades estimada pelo modelo de regressão ordinal")+
theme_classic()+
guides(colour = guide_legend(reverse=T)) # Only to reorganize the legend.
Nonetheless, my data has two random factors (participants and items), so I chose to fit a mixed ordered model using the package brms
. I could fit a lot of models, with distinct structures for the random factors. So, I tried to plot a graph as the one above, using this code:
# Make new data
pred<-data.frame(ordem = rep(c("todo-um", "um-todo"), 2),
num = c("PL", "SG", "SG", "PL"))
# Convert in factors
pred$ordem<-as.factor(pred$ordem)
pred$num<-as.factor(pred$num)
# Make predictions (95%)
pred<-cbind(pred, predict(m2, probs = c(0.025, 0.975)))
colnames(pred)<-c("ordem", "num", "1", "2", "3", "4", "5")
# Put table in a vertical format
pred<-melt(pred, id.vars = c("ordem", "num"),
variable.name = "Respostas", value.name = "Probabilidade")
# Prepare colors
paleta<-c("#D7191C", "#FDAE61", "#9C9C9C", "#ABDDA4", "#2B83BA")
# Releval todo-um as base factor
pred$ordem<-relevel(pred$ordem, ref = "todo-um")
# Make the graph
ggplot(pred, aes(x = num, y = Probabilidade, group = Respostas, colour = Respostas))+
geom_line()+geom_point()+
facet_grid(~ordem)+
scale_y_continuous(breaks = seq(from = 0, to = 1.0, by = 0.1),
labels = scales::number_format(accuracy = 0.01))+
scale_colour_manual(values=paleta,
labels=c("Discordo_Totalmente", "Discordo", "Neutro", "Concordo", "Concordo_Totalmente"))+
labs(x = "Número da anáfora", y = "Probabilidades preditas", fill="Respostas")+
ggtitle("Previsão de probabilidades estimada pelo modelo de regressão ordinal")+
theme_classic()+
guides(colour = guide_legend(reverse=T)) # Apenas organizando a ordem da legenda.
But then, the result looked like this:
I've tried a lot of things, but I can't make this graph look like the other one. Even worse is the fact that I can't see any difference in the structure of the table of predicted values in both cases:
> str(lnovo)
'data.frame': 6360 obs. of 4 variables:
$ ordem : Factor w/ 2 levels "todo-um","um-todo": 1 1 2 2 2 2 1 2 2 1 ...
$ num : Factor w/ 2 levels "PL","SG": 1 2 1 2 2 1 1 1 2 1 ...
$ Respostas : Factor w/ 5 levels "1","2","3","4",..: 1 1 1 1 1 1 1 1 1 1 ...
$ Probabilidade: num 0.502 0.1098 0.1643 0.0711 0.0711 ...
> str(pred)
'data.frame': 6360 obs. of 4 variables:
$ ordem : Factor w/ 2 levels "todo-um","um-todo": 1 2 1 2 1 2 1 2 1 2 ...
$ num : Factor w/ 2 levels "PL","SG": 1 2 2 1 1 2 2 1 1 2 ...
$ Respostas : Factor w/ 5 levels "1","2","3","4",..: 1 1 1 1 1 1 1 1 1 1 ...
$ Probabilidade: num 0.3013 0.0232 0.0625 0.0275 0.0227 ...
Furthermore, here I've found a function plot_model()
which gives me the graph below (plot_model(m, type = "pred", terms = c("Ordem", "Num"))
.
This is exactly what I want, but not in this format.