这里有两个选项,aov 和 lme (我认为第二个是首选):
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 - 重复测量 anova 的 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)