afex package で two way within ANOVA と MANOVA(2要因の被験者内計画)

Univariateな被験者内計画の二元配置分散分析をやってみる.以下の式でよいらしい.

# afex package読み込み
> library(afex)

#afexパッケージの中のデータを呼び出す.今回はサンプルデータとして活用
> data("md_12.1")

#データはこんな感じ
> head(md_12.1)
  id  noise angle  rt
1  1 absent     0 420
2  2 absent     0 420
3  3 absent     0 480
4  4 absent     0 420
5  5 absent     0 540
6  6 absent     0 360

> aov0<-aov_car(rt ~ noise * angle + Error(id/noise*angle), data = md_12.1, return = "univariate")
#ここでrtは従属変数,noiseとangleは要因,Errorで被験者内計画となるデータを定義.idは被験者.

> aov0

Univariate Type III Repeated-Measures ANOVA Assuming Sphericity

              Sum Sq num Df Error SS den Df F value    Pr(>F)    
(Intercept) 19425660      1   292140      9 598.449 1.527e-09 ***
noise         285660      1    76140      9  33.766  0.000256 ***
angle         289920      2    64080     18  40.719 2.087e-07 ***
noise:angle   105120      2    20880     18  45.310 9.424e-08 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1


Mauchly Tests for Sphericity

            Test statistic p-value
angle              0.96011 0.84972
noise:angle        0.89378 0.63814


Greenhouse-Geisser and Huynh-Feldt Corrections
 for Departure from Sphericity

             GG eps Pr(>F[GG])    
angle       0.96164  3.402e-07 ***
noise:angle 0.90398  3.454e-07 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

              HF eps   Pr(>F[HF])
angle       1.217564 2.086763e-07
noise:angle 1.117870 9.424093e-08

MANOVAもやってみる.maultvariateだけじゃなくunivariateも一括で出るけど.

> library(afex)

#afexパッケージの中のデータを呼び出す.今回はサンプルデータとして活用
> data("md_12.1")

#データはこんな感じ
> head(md_12.1)
  id  noise angle  rt
1  1 absent     0 420
2  2 absent     0 420
3  3 absent     0 480
4  4 absent     0 420
5  5 absent     0 540
6  6 absent     0 360

#ANOVAのモデルを作る.
> aov1<-aov_ez(id = "id", dv = "rt", data = md_12.1, within = c("noise", "angle"))
> summary(aov1$Anova)

Type III Repeated Measures MANOVA Tests:

------------------------------------------
 
Term: (Intercept) 

 Response transformation matrix:
           (Intercept)
absent_X0            1
absent_X4            1
absent_X8            1
present_X0           1
present_X4           1
present_X8           1

Sum of squares and products for the hypothesis:
            (Intercept)
(Intercept)   116553960

Multivariate Tests: (Intercept)
                 Df test stat approx F num Df den Df     Pr(>F)    
Pillai            1   0.98518 598.4492      1      9 1.5266e-09 ***
Wilks             1   0.01482 598.4492      1      9 1.5266e-09 ***
Hotelling-Lawley  1  66.49435 598.4492      1      9 1.5266e-09 ***
Roy               1  66.49435 598.4492      1      9 1.5266e-09 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

------------------------------------------
 
Term: noise 

 Response transformation matrix:
           noise1
absent_X0       1
absent_X4       1
absent_X8       1
present_X0     -1
present_X4     -1
present_X8     -1

Sum of squares and products for the hypothesis:
        noise1
noise1 1713960

Multivariate Tests: noise
                 Df test stat approx F num Df den Df     Pr(>F)    
Pillai            1  0.789552 33.76596      1      9 0.00025597 ***
Wilks             1  0.210448 33.76596      1      9 0.00025597 ***
Hotelling-Lawley  1  3.751773 33.76596      1      9 0.00025597 ***
Roy               1  3.751773 33.76596      1      9 0.00025597 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

------------------------------------------
 
Term: angle 

 Response transformation matrix:
           angle1 angle2
absent_X0       1      0
absent_X4       0      1
absent_X8      -1     -1
present_X0      1      0
present_X4      0      1
present_X8     -1     -1

Sum of squares and products for the hypothesis:
        angle1 angle2
angle1 1128960 403200
angle2  403200 144000

Multivariate Tests: angle
                 Df test stat approx F num Df den Df     Pr(>F)    
Pillai            1  0.887597 31.58624      2      8 0.00015963 ***
Wilks             1  0.112403 31.58624      2      8 0.00015963 ***
Hotelling-Lawley  1  7.896559 31.58624      2      8 0.00015963 ***
Roy               1  7.896559 31.58624      2      8 0.00015963 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

------------------------------------------
 
Term: noise:angle 

 Response transformation matrix:
           noise1:angle1 noise1:angle2
absent_X0              1             0
absent_X4              0             1
absent_X8             -1            -1
present_X0            -1             0
present_X4             0            -1
present_X8             1             1

Sum of squares and products for the hypothesis:
              noise1:angle1 noise1:angle2
noise1:angle1        416160        171360
noise1:angle2        171360         70560

Multivariate Tests: noise:angle
                 Df test stat approx F num Df den Df     Pr(>F)    
Pillai            1  0.918223 44.91353      2      8 4.4722e-05 ***
Wilks             1  0.081777 44.91353      2      8 4.4722e-05 ***
Hotelling-Lawley  1 11.228381 44.91353      2      8 4.4722e-05 ***
Roy               1 11.228381 44.91353      2      8 4.4722e-05 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Univariate Type III Repeated-Measures ANOVA Assuming Sphericity

              Sum Sq num Df Error SS den Df F value    Pr(>F)    
(Intercept) 19425660      1   292140      9 598.449 1.527e-09 ***
noise         285660      1    76140      9  33.766  0.000256 ***
angle         289920      2    64080     18  40.719 2.087e-07 ***
noise:angle   105120      2    20880     18  45.310 9.424e-08 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1


Mauchly Tests for Sphericity

            Test statistic p-value
angle              0.96011 0.84972
noise:angle        0.89378 0.63814


Greenhouse-Geisser and Huynh-Feldt Corrections
 for Departure from Sphericity

             GG eps Pr(>F[GG])    
angle       0.96164  3.402e-07 ***
noise:angle 0.90398  3.454e-07 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

              HF eps   Pr(>F[HF])
angle       1.217564 2.086763e-07
noise:angle 1.117870 9.424093e-08
Warning message:
In summary.Anova.mlm(aov1$Anova) : HF eps > 1 treated as 1
> 


コメント