如何在R中的双向ANOVA中排除不需要的比较

时间:2015-11-05 09:17:56

标签: r anova two-way posthoc

我已经在stats.exchange(original question)上询问了这个问题,现在我在这里重新发布了相同的内容 - 希望得到更多人的帮助。

我想知道从双向ANOVA生成的输出中排除所有不需要的对的方法,所以当从摘要(aov())显示显着结果时,事后测试赢得了给我任何我不想要的比较。详情如下:

datTable包含两个因素site下的比例数据(四个级别:A,B,C,D)和treatment(两个级别:控制和处理)。具体来说,我想在每个site下的所有treatment中进行成对测试(例如,对照-A VS.control-B,对照-A VS.control-C,处理-A VS.treated-C等),同时排除不同sites和不同treatments之间的比较(例如,对照如对照-A VS.待处理-B,对照-B VS.edated-C )。

数据如下所示:

> datTable
   site treatment proportion
     A   control  0.5000000
     A   control  0.4444444
     A   treated  0.1000000
     A   treated  0.4000000
     B   control  0.4444444
     B   control  0.4782609
     B   treated  0.0500000
     B   treated  0.3000000
     C   control  0.3214286
     C   control  0.4705882
     C   treated  0.1200000
     C   treated  0.4000000
     D   control  0.3928571
     D   control  0.4782609
     D   treated  0.4000000
     D   treated  0.4100000

我做了双向ANOVA(也不确定是否在主题site/treatment内或主题site*treatment ...之间使用),并对结果进行了总结。

  m1 <- aov(proportion~site*treatment,data=datTable) # Or should I use 'site/treatment'?

然后我的summary(m1)给了我以下内容:

> summary(m1)
               Df  Sum Sq Mean Sq F value Pr(>F)  
site            3 0.02548 0.00849   0.513 0.6845  
treatment       1 0.11395 0.11395   6.886 0.0305 *
site:treatment  3 0.03686 0.01229   0.742 0.5561  
Residuals       8 0.13239 0.01655                 

下一步是使用TukeyHSD事后测试来查看哪一对在*因素中导致了site重要性。

> TukeyHSD(m1)
  Tukey multiple comparisons of means
    95% family-wise confidence level

Fit: aov(formula = proportion ~ site * treatment, data = datTable)

$site
            diff        lwr       upr     p adj
B-A -0.042934783 -0.3342280 0.2483585 0.9631797
C-A -0.033106909 -0.3244002 0.2581863 0.9823452
D-A  0.059168392 -0.2321249 0.3504616 0.9124774
C-B  0.009827873 -0.2814654 0.3011211 0.9995090
D-B  0.102103175 -0.1891901 0.3933964 0.6869754
D-C  0.092275301 -0.1990179 0.3835685 0.7461309

$treatment
                      diff        lwr         upr     p adj
treated-control -0.1687856 -0.3171079 -0.02046328 0.0304535

$`site:treatment`
                            diff        lwr       upr     p adj
B:control-A:control -0.010869565 -0.5199109 0.4981718 1.0000000
C:control-A:control -0.076213819 -0.5852551 0.4328275 0.9979611
D:control-A:control -0.036663216 -0.5457045 0.4723781 0.9999828
A:treated-A:control -0.222222222 -0.7312635 0.2868191 0.6749021
B:treated-A:control -0.297222222 -0.8062635 0.2118191 0.3863364  # Not wanted
C:treated-A:control -0.212222222 -0.7212635 0.2968191 0.7154690  # Not wanted
D:treated-A:control -0.067222222 -0.5762635 0.4418191 0.9990671  # Not wanted
C:control-B:control -0.065344254 -0.5743856 0.4436971 0.9992203
D:control-B:control -0.025793651 -0.5348350 0.4832477 0.9999985
A:treated-B:control -0.211352657 -0.7203940 0.2976887 0.7189552  # Not wanted
B:treated-B:control -0.286352657 -0.7953940 0.2226887 0.4233804  # Not wanted
C:treated-B:control -0.201352657 -0.7103940 0.3076887 0.7583437  # Not wanted
D:treated-B:control -0.056352657 -0.5653940 0.4526887 0.9996991
D:control-C:control  0.039550603 -0.4694907 0.5485919 0.9999713
A:treated-C:control -0.146008403 -0.6550497 0.3630329 0.9304819  # Not wanted
B:treated-C:control -0.221008403 -0.7300497 0.2880329 0.6798628  # Not wanted
C:treated-C:control -0.136008403 -0.6450497 0.3730329 0.9499131 
D:treated-C:control  0.008991597 -0.5000497 0.5180329 1.0000000  # Not wanted
A:treated-D:control -0.185559006 -0.6946003 0.3234823 0.8168230  # Not wanted
B:treated-D:control -0.260559006 -0.7696003 0.2484823 0.5194129  # Not wanted
C:treated-D:control -0.175559006 -0.6846003 0.3334823 0.8505865  # Not wanted
D:treated-D:control -0.030559006 -0.5396003 0.4784823 0.9999950  
B:treated-A:treated -0.075000000 -0.5840413 0.4340413 0.9981528
C:treated-A:treated  0.010000000 -0.4990413 0.5190413 1.0000000
D:treated-A:treated  0.155000000 -0.3540413 0.6640413 0.9096378
C:treated-B:treated  0.085000000 -0.4240413 0.5940413 0.9960560
D:treated-B:treated  0.230000000 -0.2790413 0.7390413 0.6429921
D:treated-C:treated  0.145000000 -0.3640413 0.6540413 0.9326207

但是,有些对我不想被纳入我预先形成的双向ANOVA,指定为# not wanted

我有什么方法可以调整aovTukeyHSD功能来排除上面列出的那些可能性(&#39;不想要的&#39;)?我可以从*生成的长列表中轻松选择我感兴趣的重要内容(使用TukeyHSD)。但我不希望anova的结果受到那些人的偏见! (它发生在实际数据中,这些不需要的对实际上造成了重要性!)

注意:您可能已经注意到site:treatment事后测试没有显示任何重要性,这是因为我只从原始数据中选择了一个小样本。

1 个答案:

答案 0 :(得分:0)

如果您想将这些比较完全排除在计算之外,Tukey的测试通过对所有条件组合进行成对比较来进行。 &#34;排除&#34;是不合理的。任何一对。

如果您的意思是想要将不需要的比较排除在最终结果中,那么是的,这是可能的。 TukeyHSD的结果只是一个列表,site:treatment只是一个矩阵,你可以随意操作。

lst <- TukeyHSD(m1)
lst[['site:treatment']] <- lst[['site:treatment']][-c(5,6,7,10,11,12,15,16,18,19,20,21),]