这是aov和lme的两个选项(我认为首选2nd):
require(MASS) ## for oats data set
require(nlme) ## for lme()
require(multcomp) ## for multiple comparison stuff
Aov.mod <- aov(Y ~ N * V + Error(B/V), data = oats)
the_residuals <- aov.out.pr[[3]][, "Residuals"]
Lme.mod <- lme(Y ~ N * V, random = ~1 | B/V, data = oats)
the_residuals <- residuals(Lme.mod)
最初的示例没有交互(Lme.mod <- lme(Y ~ N * V, random = ~1 | B/V, data = oats)
),但似乎正在使用它(并且产生了不同的结果,因此它正在执行某些操作)。
就是这样...
但为了完整性:
1-模型摘要
summary(Aov.mod)
anova(Lme.mod)
2-重复测量方差分析的Tukey测试(需要3个小时!)。
summary(Lme.mod)
summary(glht(Lme.mod, linfct=mcp(V="Tukey")))
3-正态性和均方差图
par(mfrow=c(1,2)) #add room for the rotated labels
aov.out.pr <- proj(aov.mod)
#oats$resi <- aov.out.pr[[3]][, "Residuals"]
oats$resi <- residuals(Lme.mod)
qqnorm(oats$resi, main="Normal Q-Q") # A quantile normal plot - good for checking normality
qqline(oats$resi)
boxplot(resi ~ interaction(N,V), main="Homoscedasticity",
xlab = "Code Categories", ylab = "Residuals", border = "white",
data=oats)
points(resi ~ interaction(N,V), pch = 1,
main="Homoscedasticity", data=oats)