R函数测试组内均值的显着性

时间:2019-02-13 03:48:18

标签: r

我的问题是关于这个虚拟数据的。我想测试一下一起考虑的三个方法(V1,V2和V3)之间是否存在显着差异。在R And中,测试v1的平均值是否与V2显着不同。

id <- c(1,2,3,4,5,6,7,8,9,10)
V1<- c(50,  42, 58, 56, 25, 85, 12, 23, 89, 52)
V2<- c(65,  63, 52, 45, 89, 58, 74, 51, 26, 25)
V3<- c(68,  95, 62, 14, 12, 25, 48, 56, 32, 57)
sex <- c("F","F","F","F","F","M","F","F","M","M")
data<- data.frame(id,V1,V2,V3,sex) 

我尝试使用方差分析,但未成功

1 个答案:

答案 0 :(得分:0)

如果要使用anova(),则需要使用lm()包装公式。

id <- c(1,2,3,4,5,6,7,8,9,10)
V1<- c(50,  42, 58, 56, 25, 85, 12, 23, 89, 52)
V2<- c(65,  63, 52, 45, 89, 58, 74, 51, 26, 25)
V3<- c(68,  95, 62, 14, 12, 25, 48, 56, 32, 57)
sex <- c("F","F","F","F","F","M","F","F","M","M")
data<- data.frame(id,V1,V2,V3,sex) 
anova(lm(id ~ V1 + V2 + V3, data = data))
Analysis of Variance Table

Response: id
           Df Sum Sq Mean Sq  F value   Pr(>F)  
 V1         1  0.438  0.4382   0.0751  0.79330  
 V2         1 29.750 29.7497   5.0959  0.06478 .
 V3         1 17.285 17.2846   2.9607  0.13610  
 Residuals  6 35.028  5.8379                  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1