Before I give my answer to the question, I would like to say that there are a number of problems with this waste analysis. Created graphs do not even show the same information. The graph for the model lm1
shows standardized residues versus adjusted values (which is not generally used in this specific context), while the graph for the model fm1
shows the Residues versus Position in the database (which is a graph that makes no sense, because the order of the waste should not have influence on the quality of the adjustment performed).
In addition to this specific problem, there are usually several graphs used to analyze the residues of a linear model, whether mixed or mixed. Below I show the most common four for the adjusted model and saved in the object lm1
.
library(nlme)
library(ggfortify)
#> Loading required package: ggplot2
lm1 <- lm(distance ~ age, data=Orthodont)
autoplot(lm1)
Created on 2020-11-13 by the reprex package (v0.3.0)
Note that there is more than one graph being plotted simultaneously. In particular, the graph in the upper right corner is what allows us to determine whether the residues follow an approximately normal distribution. I recommend taking a look at some reference of linear models to know what each of these graphs means (Kutner et al (2013), Applied Linear Statistical Models is a good starting point, although as I recall it does not deal with mixed models with many details).
That said, the problem here is the origin of each of the graphics. The package nlme
uses the package lattice
to make model charts lm1
, while the graph refers to the model fm1
is done with the standard graphics of R. Notice how the graphics styles are very different from each other.
library(nlme)
lm1 <- lm(distance ~ age, data=Orthodont)
fm1 <- lme(distance ~ age, Orthodont, random = ~ age | Subject)
plot(fm1)
plot(lm1$residuals)
Created on 2020-11-13 by the reprex package (v0.3.0)
Therefore, my suggestion is that both graphics be done in the same style, be the standard of R, lattice
or ggplot2
. For simplicity, I’ll do both lattice
, using the function for this xyplot
in the case of the second graph.
With the two graphics ready, just use the function grid.arrange
package gridExtra
to obtain the desired result.
library(gridExtra)
p1 <- plot(fm1)
p2 <- xyplot(residuals ~ 1:length(lm1$residuals), lm1)
grid.arrange(p1, p2, ncol = 2)
Created on 2020-11-13 by the reprex package (v0.3.0)
Thanks @Marcus Nunes!!!
– user55546