最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ggplot2 - Why is my mixed-effects logistic regression model outputting non-linear results instead of linear log-odds? (R functio

programmeradmin3浏览0评论

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"))))

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论