查看原文
其他

如何快、准、狠使用R语言完成单因素方差分析

2017-08-28 miffery 临床科研与meta分析
> x <- c(40, 10, 35, 25, 20, 15, 35, 15, -5, 30, 25, 70, 65, 45, 50, 50, 20, 45, 55, 20, 15, 80, -10, 105, 75, 10, 60, 45, 60, 30, 60, 30, 100, 85, 20, 55, 45, 30, 77, 105,123,124,145,156,120) > group<-c(rep(1,15),rep(2,15),rep(3,15))  ##分组 > gro<-as.factor(group)  ##因子化 > d<-split(x,gro)  ##分组 > sapply(d,shapiro.test) #分组检验正态性 > bartlett.test(x,gro)   #分组检测方差齐性 Bartlett test of homogeneity of variances data: x and gro Bartlett's K-squared = 7.584, df = 2, p-value = 0.02255 #方差不齐> kruskal.test(x~gro)  #方差不齐,故选择kruskal非参数检验 Kruskal-Wallis rank sum test data: x by gro Kruskal-Wallis chi-squared = 12.485, df = 2, p-value = 0.001945


> model<-aov(x~gro)##为了演示,我们也做了单因素方差分析 > summary(model) Df Sum Sq Mean Sq F value Pr(>F) gro 2 23388 11694 10.77 0.000168 *** Residuals 42 45613 1086 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1> compr<- TukeyHSD(model) ##组间比较 > compr Tukey multiple comparisons of means 95% family-wise confidence level Fit: aov(formula = x ~ gro) $gro diff lwr upr p adj 2-1 12.33333 -16.90189 41.56856 0.5654977 3-1 53.33333 24.09811 82.56856 0.0001909 3-2 41.00000 11.76478 70.23522 0.0040805 > plot(compr)


加入临床科研讨论群,请加13738062354或者pj1989zzj为好友,注明加群,就会拉你进群了。



您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存