SSブログ

R: 一元配置分散分析と多重比較 [統計]

ちょっとメモ。

> ##
> ## ANOVA
> ##
> 
> set.seed(12345)
> 
> group <- c("A", "B", "C")
> n.level <- 3
> g.mean <- c(5, 5, 7)
> sd <- 1
> n.rep <- 10
> g <- rep(group, each = n.rep)
> x <- c(sapply(1:n.level, function(i) rnorm(n.rep, g.mean[i], sd)))
> data <- data.frame(group = g, x = x)
> 
> plot(data, las = 1)

Rplot.png

> ## oneway.test()
> oneway.test(x ~ group, data, var.equal = TRUE)

	One-way analysis of means

data:  x and group
F = 27.0719, num df = 2, denom df = 27, p-value = 3.536e-07

> 
> ## Holm's Method
> pairwise.t.test(data$x, data$group, p.adjust.method = "holm")

	Pairwise comparisons using t tests with pooled SD 

data:  data$x and data$group 

  A       B      
B 0.52    -      
C 1.1e-06 4.0e-06

P value adjustment method: holm 
> 
> ## aov()
> x.aov <- aov(x ~ group, data)
> summary(x.aov)
            Df Sum Sq Mean Sq F value   Pr(>F)    
group        2  45.88  22.939   27.07 3.54e-07 ***
Residuals   27  22.88   0.847                     
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> 
> ## Tukey's Method
> TukeyHSD(x.aov)
  Tukey multiple comparisons of means
    95% family-wise confidence level

Fit: aov(formula = x ~ group, data = data)

$group
        diff        lwr      upr     p adj
B-A 0.267347 -0.7533505 1.288044 0.7942716
C-A 2.746764  1.7260665 3.767461 0.0000011
C-B 2.479417  1.4587195 3.500114 0.0000058


タグ:R 多重比較
nice!(1)  コメント(0)  トラックバック(0) 
共通テーマ:日記・雑感

nice! 1

コメント 0

コメントを書く

お名前:
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

Facebook コメント

トラックバック 0