方差分析
library(multcomp)
attach(cholesterol)
table(trt)
##比较均值
aggregate(response,by=list(trt),FUN=mean)
##方差分析
fit <- aov(response~trt,data =cholesterol )
fit
summary(fit)
fit.lm <- lm(response=trt,data=cholesterol)
fit.lm
summary(fit.lm)
aggregate比较均值,发现药物E的效果最好
f值越大,说明组间差异越显著
P值越小,越显著
fit.lm <- lm(response~trt,data =cholesterol )
fit.lm
summary(fit.lm)
litter
table(litter$dose)
attach(litter)
##比较均值
aggregate(weight,by=list(dose),FUN=mean)
fit <- aov(weight~gesttime+dose,data =litter)
attach(ToothGrowth)
xtabs(~ supp+dose)
aggregate(len,by=list(supp,dose),FUN=mean)
> dose<-factor(dose)
> ToothGrowth$dose<-factor(ToothGrowth$dose)
> fit<-aov(len~supp+dose,data=ToothGrowth)
> summary(fit)
install.packages("HH")
library(HH)
interaction.plot(dose, supp,len, type="b",
col=c("red","blue"),pch=c(16,18),
main = "Interaction between Dose and supplenent type")
library(MASS)
attach(UScereal)
shelf <- factor(shelf)
aggregate(cbind(calories,fat,sugars),by=list(shelf),FUN=mean)
fit<-manova(cbind(calories,fat,sugars)~shelf)