一、前言
之前说过了ANOVA,包括one-way和two-way,虽然没说详细过程,但是建立了一个使用R语言进行ANOVA分析的步骤。今天来进一步说一说MANOVA,那么MANOVA是多元方差分析,注意,这个元字指的是因变量,也就是Dependent Var。所以多元方差分析,是多个因变量的方差分析,但是,two-way ANOVA是只有一个因变量,但是多个自变量,注意区别。
另外,MANOVA也分one-way与two-way。
MANOVA感觉国内讲的很少,我贴一个国外小哥讲的视频非常的清晰。MANOVA - explained with a simple example
二、分析步骤
那么,相同的首先一定是假设检验:
- 首先发现outliers,将异常值剔除,个人认为剔除一次就行
- 然后进行分组正态检验,
- 然后进行组内线性检验,
- 然后进行Levene检验,
- 然后进行Box's M test,这个用来检查协方差齐次性
之后就是MANOVA分析
分析完成后,需要进行差异检验
并做Tamhane检测或者交互图。
三、R语言程序实例
x=read.csv(file.choose(), header=TRUE)#查看数据
head(x)
names(x)boxplot(x6 ~ x1, data = x,xlab = "customer type", ylab = "product quality",main = "compare", col = c("#00AFBB", "#E7B800", "#FC4E07"), names=c("<1 year","1-5 years",">5 years") )
boxplot(x7 ~ x1, data = x,xlab = "customer type", ylab = "E-Commerce",main = "compare", col = c("#00AFBB", "#E7B800", "#FC4E07"), names=c("<1 year","1-5 years",">5 years") )
# 正态检验
shapiro.test(x$x6)
shapiro.test(x$x7)shapiro.test(x[x$x1 == 1,]$x6)
shapiro.test(x[x$x1 == 2,]$x6)
shapiro.test(x[x$x1 == 3,]$x6)hist(x$x6)
hist(x$x7)hist(x[x$x1 == 1,]$x6)
hist(x[x$x1 == 2,]$x6)
hist(x[x$x1 == 3,]$x6)qqnorm(x$x6)
qqline(x$x6)
hist(x$x6)
plot(density(x$x6))#删除outliersoutliersx6<-boxplot(x6 ~ x1, data = x,xlab = "customer type", ylab = "product quality",main = "compare", col = c("#00AFBB", "#E7B800", "#FC4E07"), names=c("<1 year","1-5 years",">5 years") )
print(outliersx6)out1<-x[x$x1==3 & x$x6==7.6,]
print(out1)
out2<-x[x$x1==1 & x$x6==9.5,]
print(out2)outliersx7<-boxplot(x7 ~ x1, data = x,xlab = "customer type", ylab = "E-Commerce",main = "compare", col = c("#00AFBB", "#E7B800", "#FC4E07"), names=c("<1 year","1-5 years",">5 years") )$out
print(outliersx7)out3<-x[x$x1==2 & (x$x7==5.1 | x$x7==5.5),]
print(out3)
out4<-x[x$x1==1 & x$x7==5.6,]
print(out4)outAll<- rbind(out1,out2, out3, out4)
print(outAll)
x<-x[-which(x$id %in% outAll$id),]#线性检验
install.packages("car")
install.packages("RColorBrewer")
library("car")
library("RColorBrewer")
scatterplotMatrix(~x6+x1+x7,transform=TRUE,data=x)#Levene
library(car)
leveneTest(x6 ~ as.factor(x1), data = x)
leveneTest(x7 ~ as.factor(x1), data = x)#Box's M test
install.packages("biotools")
library("biotools")
library("MASS")
boxM(data=x[,7:8],group=x[,2])# One Way MAnova
Y<-cbind(x$x6,x$x7)
fit <- manova(Y ~ as.factor(x1), data=x)
summary(fit)#不同的 Manova Testsummary(fit, test="Hotelling-Lawley")
summary(fit, test="Roy")
summary(fit, test="Pillai")
summary(fit, test="Wilks")#差异性
summary.aov(fit)install.packages("PMCMRplus", dependencies=TRUE, repos='http://cran.rstudio.com/')
#Tamhane
library("PMCMRplus")
summary(T2 <- tamhaneT2Test(x$x6, as.factor(x$x1)))
summary(T2 <- tamhaneT2Test(x$x7, as.factor(x$x1)))
四、结果