2017-10-20 125 views
2

我有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() 

回答

0

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)))) 
+0

謝謝你的工作。 – Mori22