单因素方程分析
install.packages("multcomp")
library(multcomp)
attach(cholesterol)
table(trt)
aggregate(response, by=list(trt),FUN=mean)
aggregate(response, by=list(trt),FUN=sd)
fit
summary(fit)
Df Sum Sq Mean Sq F value Pr(>F)
trt 4 1351.4 337.8 32.43 9.82e-13 ***
Residuals 45 468.8 10.4
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
install.packages("gplots")
library(gplots)
plotmeans(response~trt,xlab="Treatment",ylab="Response", main="Mean Plot\nwith 95% CI")
detach(cholesterol)
#多重比较
TukeyHSD(fit)
par(las=2)
par(mar=c(5,8,4,2))
plot(TukeyHSD(fit))
library(multcomp)
par(mar=c(5,4,6,2))
tuk
plot(cld(tuk,level=.05),col="lightgrey")
#离群点检测 -
#评估检验的假设条件
library(car)
qqPlot(lm(response~trt,data=cholesterol),simulate=TRUE,main="Q-Q Plot",labels=FALSE)
#Bartlett检验
bartlett.test(response~trt,data=cholesterol)
Bartlett test of homogeneity of variances
data: response by trt
Bartlett's K-squared = 0.57975, df = 4, p-value = 0.9653
outlierTest(fit) #离群点检测
No Studentized residuals with Bonferonni p < 0.05 没发现离群点
Largest |rstudent|:
rstudent unadjusted p-value Bonferonni p<