56方差分析
56方差分析
方差分析(ANOVA):也称为“变异系数分析”,用于两个及两个以上样本均数差别的显著性检验。
单因素方差分析ANOVA
双因素方差分析ANOVA
协方差分析ANCOVA
多元方差分析MANOVA:多因变量
多元协方差分析MANCOVA
install.packages ("multcomp" )
library(multcomp)
attach(cholesterol)
table(cholesterol$trt) #attach(将数据集加载到R语言,后面直接访问)

aggregate(cholesterol$response,by=list(cholesterol$trt),FUN=mean)#aggregate总计的

fit<-aov(response~trt,data=cholesterol)
summary(fit)

F:组间差异和组内差异的比值,F越大,说明组间差异越显著。
P:P值越小,说明F越可靠。
fit.lm<-lm(response~trt,data=cholesterol)
plot(fit)
协方差:litter
table(litters$dose ) #table:统计分组的情况

attach(litter)
dose weight gesttime number
aggregate(weight,by=list(dose),FUN=mean)
fit<-aov(weight~gesttime+dose,data=litter)
#weight:因变量;gesttime:协变量;dose:自变量;
summary(fit)

双因素方差分析ANOVA
:内置数据集:ToothGrowth
attach(ToothGrowth)
xtabs(~supp+dose) 二维列联表

aggregate(len,by=list(supp,dose),FUN=mean)

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 Supplement Type")

library(MASS)
UScereal

attach(UScereal)
shelf<-factor(shelf)
求平均值:aggregate(cbind(calories,fat,sugars),by=list(shelf),FUN=mean)

x<-read.csv("水培11.7.csv")

summary()函数:描述性统计分析

attach(x)
aggregate(Length,by=list(Code),FUN=mean)
y<-aggregate(cbind(Length,SurfArea,RootVolume,Number),by=list(Code),FUN=mean)
浙公网安备 33010602011771号