理学療法士がまとめたノート

統計学備忘録 since2016

Rを使って統計学を勉強するブログです

ANOVA君 で分散分析

ANOVA君 で分散分析

投稿日2017.8.25

 

ANOVA君はフリーの統計ソフトウェア「R」で動作する分散分析関数です。ダウンロード、使い方、リリース情報などは「井関龍太のページ」を必ずご確認ください

井関龍太のページ  http://riseki.php.xdomain.jp/index.php?FrontPage

ここではデータセットからのフレーム作りとANOVA君の使い方を勉強します.

anovakun version 4.8.1 (2017-08-01) のデフォルト

 平方和のタイプ:タイプⅢ

 球面性の仮定:Mendozaの多標本球面性検定

 多重比較:Shafferの方法

 

注)必ずANOVA君のソースを読み込んでください

 

今回はRのデータセット CO2 を使用します.Type、Treatmentで群間の分析、環境CO2濃度X1(95ml/L) vs X2(175ml/L)で群内の分析を実行します.イメージは下表をご覧ください.

 

それでは、ABsCデザイン(2水準の被験者間要因2つ,2水準の被験者内要因1つの混合要因計画)用にデータをフレームに入れ込んでみます.

「要因計画」……分析したい計画の型を入力します。「A」~「Z」を各要因を表すラベル,「s」を被験者のラベルとします。被験者間要因は「s」の左側,被験者内要因は「s」の右側に配置します。この表記法にしたがえば,例えば,2要因の被験者間計画は「ABs」,3要因の被験者内計画は「sABC」,2つの被験者間要因と1つの被験者内要因を持つ混合要因計画は「ABsC」と表せます。なお,要因計画の型は「""」で囲む形で入力する必要があります。

http://riseki.php.xdomain.jp/index.php?FrontPage


CO21<-data.frame( matrix( CO2$uptake, nrow=12, byrow=T) )
Type<-c( rep ("Quebec",6) , rep ("Mississippi",6) )
Treatment<-c(rep("nonchilled",3),rep("chilled",3),rep("nonchilled",3),rep("chilled",3))
CO22<-cbind(Type,Treatment,CO22)     #cbindフレームに列を追加

f:id:yoshida931:20170825190114p:plain

内水準を3つに限定してみます

環境CO2濃度 X1:95ml/L, X2:500ml/L, X3:1000ml/L 

X2<-CO22[,7]  # X2:500ml/L
X3<-CO22[,9]  # X3:1000ml/L
CO22[,1:3]   # X1:95ml/L
CO23<-data.frame(CO22[,1:3],X2,X3)

これで準備完了です.

f:id:yoshida931:20170825185527p:plain

ANOVA君で二元配置分散分析の実行です!

anovakun( CO23, "ABsC", 2 , 2 , 3 )      #ANOVA君のソースが使用されます

 

以下の結果が一気に出力されます.(ANOVA君、素晴らしい!!!)

Type Treatment X1
1 Quebec nonchilled 16.0
2 Quebec nonchilled 13.6
3 Quebec nonchilled 16.2
4 Quebec chilled 14.2
5 Quebec chilled 9.3
6 Quebec chilled 15.1
7 Mississippi nonchilled 10.6
8 Mississippi nonchilled 12.0
9 Mississippi nonchilled 11.3
10 Mississippi chilled 10.5
11 Mississippi chilled 7.7
12 Mississippi chilled 10.6
> CO23<-data.frame(CO22[,1:3],X2,X3)
> anovakun( CO23, "ABsC", 2, 2 , 3)

[ ABsC-Type Design ]

This output was generated by anovakun 4.8.1 under R version 3.3.3.
It was executed on Fri Aug 25 18:53:40 2017.


<< DESCRIPTIVE STATISTICS >>

-----------------------------------
A B C n Mean S.D.
-----------------------------------
a1 b1 c1 3 15.2667 1.4468
a1 b1 c2 3 39.6000 3.8974
a1 b1 c3 3 43.1667 3.0616
a1 b2 c1 3 12.8667 3.1214
a1 b2 c2 3 36.6667 3.6116
a1 b2 c3 3 40.8333 1.9140

a2 b1 c1 3 11.3000 0.7000
a2 b1 c2 3 30.6000 1.9672
a2 b1 c3 3 31.6000 3.8510
a2 b2 c1 3 9.6000 1.6462
a2 b2 c2 3 16.6333 3.6679
a2 b2 c3 3 18.7333 3.8837
-----------------------------------


<< SPHERICITY INDICES >>

== Mendoza's Multisample Sphericity Test and Epsilons ==

-------------------------------------------------------------------------
Effect Lambda approx.Chi df p LB GG HF CM
-------------------------------------------------------------------------
C 0.0000 13.9661 11 0.2349 ns 0.5000 0.6892 0.7858 0.6562
-------------------------------------------------------------------------
LB = lower.bound, GG = Greenhouse-Geisser
HF = Huynh-Feldt-Lecoutre, CM = Chi-Muller


<< ANOVA TABLE >>

-------------------------------------------------------------------
Source SS df MS F-ratio p-value
-------------------------------------------------------------------
A 1222.6678 1 1222.6678 80.8464 0.0000 ***
B 327.6100 1 327.6100 21.6626 0.0016 **
A x B 108.8544 1 108.8544 7.1978 0.0278 *
s x A x B 120.9867 8 15.1233
-------------------------------------------------------------------
C 3234.6839 2 1617.3419 300.5513 0.0000 ***
A x C 298.8572 2 149.4286 27.7684 0.0000 ***
B x C 72.4850 2 36.2425 6.7350 0.0075 **
A x B x C 66.0272 2 33.0136 6.1349 0.0105 *
s x A x B x C 86.1000 16 5.3812
-------------------------------------------------------------------
Total 5538.2722 35 158.2363
+p < .10, *p < .05, **p < .01, ***p < .001


<< POST ANALYSES >>

< SIMPLE EFFECTS for "A x B" INTERACTION >

--------------------------------
A B n Mean S.D.
--------------------------------
a1 b1 9 32.6778 13.4004
a1 b2 9 30.1222 13.3174
a2 b1 9 24.5000 10.1486
a2 b2 9 14.9889 4.9974
--------------------------------

------------------------------------------------------------
Source SS df MS F-ratio p-value
------------------------------------------------------------
A at b1 300.9422 1 300.9422 24.7984 0.0076 **
Er at b1 48.5422 4 12.1356
A at b2 1030.5800 1 1030.5800 56.9032 0.0017 **
Er at b2 72.4444 4 18.1111
B at a1 29.3889 1 29.3889 2.4694 0.1912 ns
Er at a1 47.6044 4 11.9011
B at a2 407.0756 1 407.0756 22.1893 0.0092 **
Er at a2 73.3822 4 18.3456
------------------------------------------------------------
+p < .10, *p < .05, **p < .01, ***p < .001

< MULTIPLE COMPARISON for "C" >

== Shaffer's Modified Sequentially Rejective Bonferroni Procedure ==
== The factor < C > is analysed as dependent means. ==
== Alpha level is 0.05. ==

----------------------------
C n Mean S.D.
----------------------------
c1 12 12.2583 2.7351
c2 12 30.8750 9.6711
c3 12 33.5833 10.4119
----------------------------

-----------------------------------------------------------
Pair Diff t-value df p adj.p
-----------------------------------------------------------
c1-c3 -21.3250 19.4070 8 0.0000 0.0000 c1 < c3 *
c1-c2 -18.6167 17.0768 8 0.0000 0.0000 c1 < c2 *
c2-c3 -2.7083 4.9888 8 0.0011 0.0011 c2 < c3 *
-----------------------------------------------------------


< SIMPLE EFFECTS for "A x C" INTERACTION >

-------------------------------
A C n Mean S.D.
-------------------------------
a1 c1 6 14.0667 2.5422
a1 c2 6 38.1333 3.7249
a1 c3 6 42.0000 2.6169
a2 c1 6 10.4500 1.4653
a2 c2 6 23.6167 8.0901
a2 c3 6 25.1667 7.8505
-------------------------------

--------------------------------------------------------------------------
Effect Lambda approx.Chi df p LB GG HF CM
--------------------------------------------------------------------------
C at a1 0.0153 4.8098 5 0.4395 ns 0.5000 0.5517 0.6072 0.5000
C at a2 0.0012 7.7554 5 0.1702 ns 0.5000 0.6545 0.8445 0.5000
--------------------------------------------------------------------------
LB = lower.bound, GG = Greenhouse-Geisser
HF = Huynh-Feldt-Lecoutre, CM = Chi-Muller

-----------------------------------------------------------------
Source SS df MS F-ratio p-value
-----------------------------------------------------------------
A at c1 39.2408 1 39.2408 10.4387 0.0120 *
Er at c1 30.0733 8 3.7592
-----------------------------------------------------------------
A at c2 632.2008 1 632.2008 55.5090 0.0001 ***
Er at c2 91.1133 8 11.3892
-----------------------------------------------------------------
A at c3 850.0833 1 850.0833 79.1696 0.0000 ***
Er at c3 85.9000 8 10.7375
-----------------------------------------------------------------
C at a1 2748.8533 2 1374.4267 187.6066 0.0000 ***
s x C at a1 58.6089 8 7.3261
-----------------------------------------------------------------
C at a2 784.6878 2 392.3439 114.1733 0.0000 ***
s x C at a2 27.4911 8 3.4364
-----------------------------------------------------------------
+p < .10, *p < .05, **p < .01, ***p < .001


< MULTIPLE COMPARISON for "C at a1" >

== Shaffer's Modified Sequentially Rejective Bonferroni Procedure ==
== The factor < C at a1 > is analysed as dependent means. ==
== Alpha level is 0.05. ==

-----------------------------------------------------------
Pair Diff t-value df p adj.p
-----------------------------------------------------------
c1-c3 -27.9333 16.5237 4 0.0001 0.0002 c1 < c3 *
c1-c2 -24.0667 11.8768 4 0.0003 0.0003 c1 < c2 *
c2-c3 -3.8667 6.4246 4 0.0030 0.0030 c2 < c3 *
-----------------------------------------------------------


< MULTIPLE COMPARISON for "C at a2" >

== Shaffer's Modified Sequentially Rejective Bonferroni Procedure ==
== The factor < C at a2 > is analysed as dependent means. ==
== Alpha level is 0.05. ==

-----------------------------------------------------------
Pair Diff t-value df p adj.p
-----------------------------------------------------------
c1-c2 -13.1667 16.3592 4 0.0001 0.0002 c1 < c2 *
c1-c3 -14.7167 10.4800 4 0.0005 0.0005 c1 < c3 *
c2-c3 -1.5500 1.7152 4 0.1615 0.1615 c2 = c3
-----------------------------------------------------------

< SIMPLE EFFECTS for "B x C" INTERACTION >

--------------------------------
B C n Mean S.D.
--------------------------------
b1 c1 6 13.2833 2.3987
b1 c2 6 35.1000 5.6501
b1 c3 6 37.3833 7.0582
b2 c1 6 11.2333 2.8605
b2 c2 6 26.6500 11.4455
b2 c3 6 29.7833 12.4105
--------------------------------

--------------------------------------------------------------------------
Effect Lambda approx.Chi df p LB GG HF CM
--------------------------------------------------------------------------
C at b1 0.0212 4.4304 5 0.4892 ns 0.5000 0.7543 1.1125 0.5000
C at b2 0.0005 8.7786 5 0.1182 ns 0.5000 0.5725 0.6523 0.5000
--------------------------------------------------------------------------
LB = lower.bound, GG = Greenhouse-Geisser
HF = Huynh-Feldt-Lecoutre, CM = Chi-Muller

-----------------------------------------------------------------
Source SS df MS F-ratio p-value
-----------------------------------------------------------------
B at c1 12.6075 1 12.6075 3.3538 0.1044 ns
Er at c1 30.0733 8 3.7592
-----------------------------------------------------------------
B at c2 214.2075 1 214.2075 18.8080 0.0025 **
Er at c2 91.1133 8 11.3892
-----------------------------------------------------------------
B at c3 173.2800 1 173.2800 16.1378 0.0039 **
Er at c3 85.9000 8 10.7375
-----------------------------------------------------------------
C at b1 2123.9811 2 1061.9906 196.8877 0.0000 ***
s x C at b1 43.1511 8 5.3939
-----------------------------------------------------------------
C at b2 1183.1878 2 591.5939 110.1950 0.0000 ***
s x C at b2 42.9489 8 5.3686
-----------------------------------------------------------------
+p < .10, *p < .05, **p < .01, ***p < .001


< MULTIPLE COMPARISON for "C at b1" >

== Shaffer's Modified Sequentially Rejective Bonferroni Procedure ==
== The factor < C at b1 > is analysed as dependent means. ==
== Alpha level is 0.05. ==

-----------------------------------------------------------
Pair Diff t-value df p adj.p
-----------------------------------------------------------
c1-c2 -21.8167 15.9920 4 0.0001 0.0003 c1 < c2 *
c1-c3 -24.1000 14.7952 4 0.0001 0.0003 c1 < c3 *
c2-c3 -2.2833 2.4348 4 0.0716 0.0716 c2 = c3
-----------------------------------------------------------


< MULTIPLE COMPARISON for "C at b2" >

== Shaffer's Modified Sequentially Rejective Bonferroni Procedure ==
== The factor < C at b2 > is analysed as dependent means. ==
== Alpha level is 0.05. ==

-----------------------------------------------------------
Pair Diff t-value df p adj.p
-----------------------------------------------------------
c1-c3 -18.5500 12.5741 4 0.0002 0.0007 c1 < c3 *
c1-c2 -15.4167 9.0643 4 0.0008 0.0008 c1 < c2 *
c2-c3 -3.1333 5.7260 4 0.0046 0.0046 c2 < c3 *
-----------------------------------------------------------

< HIGHER-ORDER "A x B x C" INTERACTION >
*** Split the dataset for further analysis. ***

output is over --------------------///

R上ではもっと見やすいです