Я пытаюсь построить график остаточных эффектов модели смешанных эффектов, используя функцию ggplot2. Однако после выполнения поиска я нашел некоторые доступные функции, но мне кажется, что для функции nlme они не работают.
Графики, которые я собираюсь построить, соответствуют приведенному ниже примеру:
Данные здесь.
Данные: https://drive.google.com/file/d/19mykz4B7jkTilbtwPQb3NUI09YZwohhs/view?usp=sharing
Вычислительные подпрограммы, которые я пробовал изначально, приведены ниже, см. ошибки, которые появляются при выполнении функции в ggplot2.
library(splines)
library(ggplot2)
library(nlme)
library(gridExtra)
setwd("C:\\Users\\Desktop")
datanew1 = read.table("dadosnew.csv", header = T, sep=";", dec = ",")
datanew1$DummyVariable = as.factor(datanew1$DummyVariable)
datanew1$Variable2 = as.factor(datanew1$Variable2)
datanew1$Variable3 = as.factor(datanew1$Variable3)
#############################################################################
############################## Model ########################################
#############################################################################
model <- lme(Response~(bs(Variable1, df=3)) + DummyVariable,
random=~1|Variable2/Variable3, datanew1, method="REML")
completemodel <- update(model, weights = varIdent(form=~1|DummyVariable))
p1 <- qplot(.fitted, .resid, data = completemodel) +
geom_hline(yintercept = 0) +
geom_smooth(se = FALSE)
Erro: `data` must be a data frame, or other object coercible by `fortify()`, not an S3 object with class lme
Run `rlang::last_error()` to see where the error occurred.
p2 <- qplot(sample =.stdresid, data = completemodel, stat = "qq") + geom_abline()
grid.arrange(p1,p2)
Erro: `data` must be a data frame, or other object coercible by `fortify()`, not an S3 object with class lme
Run `rlang::last_error()` to see where the error occurred.
Além disso: Warning message:
`stat` is deprecated
Другой способ, которым я пытался построить график, был с функцией ниже, но мне это не удалось.
ggplot(completemodel, aes(.fitted, .resid)) + geom_point()
Erro: `data` must be a data frame, or other object coercible by `fortify()`, not an S3 object with class lme
Run `rlang::last_error()` to see where the error occurred.
nmle
создает собственный объект S3 для хранения своей информации, и вам придется заглянуть в него, чтобы увидеть, где находятся данные для построения. ggplot2, кажется, изо всех сил пытается привести ваши данные к прямоугольному формату - проверьте, что такое str (completemodel). - person Dubukay   schedule 26.01.2021fortify
, но это не определено для объекта NMLE, поэтому возникает ошибка. Однако подгонка и невязки доступны с помощью completemodel$fitted и completemodel$residuals, если вы хотите рассчитать их самостоятельно. - person Dubukay   schedule 26.01.2021