Hi all, I want to obtain diagnosis plots from the following codes with R version 4.0.2 and RStudio Version 1.3.1056, error information as follows:
Error: data must be a data frame, or other object coercible by fortify(), not an S4 object with class lmerModLmerTest
The strange thing is that the following codes work well with R version 3.6.3.
By the way, I need use the package lmerTest and I want to get diagonis plots, such as qqplot, Residual vs Fitted Plot. Any suggestions? Thanks!
john <- read.table("http://stat.ethz.ch/~meier/teaching/data/john.dat", header = TRUE)
john[, "plot"] <- factor(john[, "plot"])
#https://stat.ethz.ch/~meier/teaching/anova/split-plot-designs.html
library(lme4)
library(Matrix)
library(lmerTest)
library(ggplot2)
fit <- lmer(mass ~ fertilizer * variety + (1 | plot), data = john)
p1 <-ggplot(fortify(fit), aes(.fitted, .resid))+geom_point()
# fortify(fit), Error
p1 + stat_smooth(method="loess") +
geom_hline(yintercept=0, col="red", linetype="dashed") +
xlab("Fitted values") +
ylab("Residuals") +
ggtitle("Residual vs Fitted Plot") +
theme_bw()
plot(fit)
#work, obtain Residual vs Fitted Plot