【问题标题】:Make plot with regression line for mixed model用回归线绘制混合模型的图
【发布时间】:2017-10-20 08:53:25
【问题描述】:

我有一个包含 60 棵树的数据框。我需要根据 DOY 为 EWMZ 找到一个坡度。我使用了混合模型并发现了一个负斜率,但是在制作绘图时它给了我一个正回归线。我不知道我以前用 ggplot 制作情节的方式是否正确。

DOY EWMZ    TREE
247 13,01   1
262 11,01   1
274 23,07   1
288 23,09   1
310 20,77   1
247 28,47   2
262 22,55   2
274 15  2
288 13,93   2
310 13,73   2
240 21,56   3
247 18,48   3
262 22  3
274 22,29   3
288 19,69   3
310 19,46   3
233 24,12   4
240 23,16   4
247 20,01   4
262 17,5    4
274 20,05   4
288 19,76   4
310 20,92   4
240 9,82    5
247 15,96   5
262 12,44   5
274 9,35    5
288 11,07   5
310 8,69    5


library(lme4)
library(sjPlot)
library(sjmisc)
library(ggplot2)
Model.1 <- lmer(EWMZ ~ DOY + (1 | TREE), data = Data.Grad.EWMZ)
mas <- ggplot(Data.Grad.EWMZ, aes(x = DOY, y = EWMZ)) + labs(x="Day of 
year",y="Totall number of cells")+
geom_point(shape = 16, size=1.8, col="red") +
geom_smooth(method = "lm", fill = "dodgerblue", level = .95)+
theme(panel.background = element_rect(fill = 'White', colour = 'White'))+
theme( axis.line = element_line(colour = "darkgrey", 
size = 1, linetype = "solid"))+  
theme_classic() 

【问题讨论】:

    标签: r ggplot2 lme4 mixed-models


    【解决方案1】:

    geom_smooth 不计算混合效果模型。要为固定斜率绘制一条线,我建议这样:

    Data.Grad.EWMZ <- structure(list(DOY = c(247, 262, 274, 288, 310, 247, 262, 274, 
    288, 310, 240, 247, 262, 274, 288, 310, 233, 240, 247, 262, 274, 
    288, 310, 240, 247, 262, 274, 288, 310), EWMZ = c(13.01, 11.01, 
    23.07, 23.09, 20.77, 28.47, 22.55, 15, 13.93, 13.73, 21.56, 18.48, 
    22, 22.29, 19.69, 19.46, 24.12, 23.16, 20.01, 17.5, 20.05, 19.76, 
    20.92, 9.82, 15.96, 12.44, 9.35, 11.07, 8.69), TREE = structure(c(1L, 
    1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 
    4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L), .Label = c("1", 
    "2", "3", "4", "5"), class = "factor")), .Names = c("DOY", "EWMZ", 
    "TREE"), row.names = c(NA, -29L), class = "data.frame")
    
    
    library(lme4)
    library(ggplot2)
    
    Model.1 <- lmer(EWMZ ~ DOY + (1 | TREE), data = Data.Grad.EWMZ)
    ggplot(Data.Grad.EWMZ, aes(x = DOY, y = EWMZ, colour=TREE)) +
      labs(x="Day of year",y="Totall number of cells")+
      geom_point(shape = 16, size=1.8) +
      geom_abline(aes(intercept=`(Intercept)`, slope=DOY), as.data.frame(t(fixef(Model.1))))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-13
      • 2017-10-23
      • 1970-01-01
      • 2021-03-15
      • 1970-01-01
      • 2020-07-13
      • 2020-12-16
      相关资源
      最近更新 更多