多元方差分析

 

  • 单因素多元方差分析

以MASS包中的UScereal数据集为例,将研究美国谷物众的卡路里、脂肪、糖含量是否因为存储位置的不同而发生变化,1代表底层货架、2代表中层货架、3代表顶层货架。卡路里、脂肪和糖含量是因变量、货架是三水平(1\2\3)的自变量。

> library(MASS)
> attach(UScereal)
The following object is masked _by_ .GlobalEnv:

    shelf

The following objects are masked from UScereal (pos = 3):

    calories, carbo, fat, fibre, mfr, potassium, protein, shelf, sodium, sugars, vitamins


> shelf <- factor(shelf)  #货架转换成因子,后续能作为分组变量
> y <- cbind(calories, fat, sugars)   #将三个因变量(卡路里、脂肪、糖)合并成一个矩阵
> aggregate(y, by=list(shelf), FUN=mean) 
  Group.1 calories       fat    sugars
1       1 119.4774 0.6621338  6.295493
2       2 129.8162 1.3413488 12.507670
3       3 180.1466 1.9449071 10.856821

> cov(y)  #输出协方差(自己跟自己的相关性)和协方差(自己和别人的相关性)
           calories       fat     sugars
calories 3895.24210 60.674383 180.380317
fat        60.67438  2.713399   3.995474
sugars    180.38032  3.995474  34.050018


> fit <- manova(y ~ shelf)  #拟合manova()函数,对组间差异进行元检验
> summary(fit)
          Df Pillai approx F num Df den Df    Pr(>F)    
shelf      2 0.4021   5.1167      6    122 0.0001015 ***
Residuals 62                                            
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1


> summary.aov(fit)
 Response calories :
            Df Sum Sq Mean Sq F value    Pr(>F)    
shelf        2  50435 25217.6  7.8623 0.0009054 ***
Residuals   62 198860  3207.4                      
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

 Response fat :
            Df Sum Sq Mean Sq F value  Pr(>F)  
shelf        2  18.44  9.2199  3.6828 0.03081 *
Residuals   62 155.22  2.5035                  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

 Response sugars :
            Df  Sum Sq Mean Sq F value   Pr(>F)   
shelf        2  381.33 190.667  6.5752 0.002572 **
Residuals   62 1797.87  28.998                    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

 

  • 评估假设检验

单因素多元方差分析有两个前提假设,一个是多元正态性,一个是方差-协方差矩阵同质性。

a、 第一个假设即指因变量组合成的向量服从一个多元正态性。可以用 Q-Q图来检验该假设

center <- colMeans(y)
n <- nrow(y)
p <- ncol(y)
cov <- cov(y)
d <- mahalanobis(y,center,cov)
coord <- qqplot(qchisq(ppoints(n),df=p),
abline(a=0,b=1)
identify(coord$x, coord$y, labels=row.names(UScereal))  #交互性的对地图中的点进行判别

07081910_STBM.png

从图形上看,两个观测点似乎违反了多元正态性,可以删除这两点再重新分析

b、方差-协方差矩阵同质性即指各组的协方差矩阵相同

 

 

 

转载于:https://my.oschina.net/u/1785519/blog/1563536

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值