查看原文
其他

随机区组设计,R语言轻松实现统计分析

2017-11-14 江利冰 临床科研与meta分析
> block <- c(rep(1, 3), rep(2, 3), rep(3, 3), rep(4, 3)) ##生成区组 > treat <- c(rep(c("A", "B", "C"), 4)) ##生成组别 > alt <- c(76, 86, 115, 12, 38, 85, 40, 81, 103, 12, 33, 57) > alt <- data.frame(block= block, treat= treat, alt= alt) ##建立数据框 > alt$block <- as.factor(alt$block) ##因子化 > alt$treat <- as.factor(alt$treat) ##因子化 > model <- aov(alt ~ treat+ block, data= alt) ##随机区组方差分析 > summary(model) ##查看模型 Df Sum Sq Mean Sq F value Pr(>F) treat 2 6074 3037.0 33.54 0.000554 *** block 3 6458 2152.6 23.77 0.000992 *** Residuals 6 543 90.6 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 > TukeyHSD(model) ##两两比较 Tukey multiple comparisons of means 95% family-wise confidence level Fit: aov(formula = alt ~ treat + block, data = alt) $treat diff lwr upr p adj B-A 24.5 3.853961 45.14604 0.0251803 C-A 55.0 34.353961 75.64604 0.0004428 C-B 30.5 9.853961 51.14604 0.0094278 $block diff lwr upr p adj 2-1 -47.33333 -74.230267 -20.436399 0.0036152 3-1 -17.66667 -44.563601 9.230267 0.2062995 4-1 -58.33333 -85.230267 -31.436399 0.0011919 3-2 29.66667 2.769733 56.563601 0.0333717 4-2 -11.00000 -37.896934 15.896934 0.5343125 4-3 -40.66667 -67.563601 -13.769733 0.0077913 > res <- residuals(model) ##生成残差 > shapiro.test(res) ##评估残差正态性 Shapiro-Wilk normality test data: res W = 0.88283, p-value = 0.09529


> plot(model)


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

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