I'm running a mixed-effects logistic regression model using glmer() from the lme4 package, and I'm plotting the outcome using the ggemmeans() function. I expect the output to be a linear plot (log-odds), but the plot is non-linear.
Here’s the code I’m using. First the model:
LMM_acc = glmer(Correct ~
time_position.c +
response_side +
response_side*time_position.c +
(1|ppt_id)+
(1|Stimulus),
data = data_cleaned,
family = binomial,
nAGQ = 0)
Then the plot:
ggemmeans(LMM_acc, terms = c("time_position.c","response_side")) %>%
plot()+
geom_line (size = 2)+
aes(linetype = group_col) +
theme(legend.title = element_text(size=30),
legend.position = 'top',
legend.key.size = unit('1.5', 'cm'),
axis.title.y = element_text(size = rel(2), angle = 90),
axis.title.x = element_text(size = rel(2)),
axis.text.x = element_text(size=20),
axis.text.y = element_text(size=20))+
ylim(0.47, 1.00) +
scale_colour_manual("response_side", values = c("purple","orangered")) +
scale_fill_manual("response_side", values = c("purple","orangered"),
guide = "legend") +
scale_linetype_manual("response_side", values = c(2,1)) +
guides(fill = guide_legend(override.aes =
list(fill = c("purple","orangered"))))
And here is the output, which should be linear, but it is not:
Maybe the problem is not with the model, but with the plotting method? Because when I plot the entire model using another function (allEffects) it seems linear:
Any insights would be appreciated!
UPD:
@PBulls thank you for your reply. I changed the ggemmeans code as you suggested. However, the outcome is still not linear. The Y-scale shows percentages, not log odds. Any idea how I can solve this?
ggemmeans(LMM_acc, terms = c("time_position.c", "response_side"),
back.transform = FALSE) %>%
plot() +
geom_line(size = 2) +
aes(linetype = group_col) +
theme(legend.title = element_text(size = 30),
legend.position = 'top',
legend.key.size = unit('1.5', 'cm'),
axis.title.y = element_text(size = rel(2), angle = 90),
axis.title.x = element_text(size = rel(2)),
axis.text.x = element_text(size = 20),
axis.text.y = element_text(size = 20)) +
scale_colour_manual("response_side", values = c("purple","orangered")) +
scale_fill_manual("response_side", values = c("purple","orangered"),
guide = "legend") +
scale_linetype_manual("response_side", values = c(2,1)) +
guides(fill = guide_legend(override.aes =
list(fill = c("purple","orangered"))))