post hoc for specific pairwise comparisons after welch's anova

1.4k views Asked by At

I am quite new to R and completely new to this website, so I really hope I am ably to convey my question in a clear way.

The following is a part of my data set:

A1<-c(0.308, 0.3624, 0.1861, 0.6176, 0.0506, 0.1014, 0.2245, 0.1894, 0.246, 0.1795)
A2<-c(0.0785, 0.1583, 0.1803, 0.0538, 0.0534, 0.0646, 0.0902, 0.0307, 0.2002, 0.1135, 0.0862)
B1<-c(0.293, 0.2159, 0.1919, 0.1904, 0.1274, 0.1482, 0.1579, 0.3284, 0.1948, 0.3159, 0.1764, 0.0403)
B2<-c(0.0741, 0.0601, 0.0273, 0.077, 0.1214, 0.0837, 0.0521, 0.0746, 0.0733, 0.0403, 0.0544)

the data is normally distributed but shows heteroscedasticity, so I used an ANOVA with Welch's correction after creating a dataframe:

(X <- data.frame(Y = c(A1,A2,B1,B2), Group = rep(c("A1", "A2", "B1", "B2"), times = c(length(A1), length(A2), length(B1), length(B2)))))
oneway.test(Y ~ Group, data = X)

    One-way analysis of means (not assuming equal variances)

data:  Y and Group
F = 12.346, num df = 3.000, denom df = 19.002, p-value = 0.0001037

I then used a pairwise t-test with non-pooled standard deviations (because of the heteroscedasticity) for the post-hoc comparisons

with(X, pairwise.t.test(Y, Group, pool.sd=FALSE))

    Pairwise comparisons using t tests with non-pooled SD 

data:  Y and Group 

   A1      A2      B1     
A2 0.05617 -       -      
B1 0.40115 0.01665 -      
B2 0.02360 0.17723 0.00089

P value adjustment method: holm 

My problem is that I am not really interested in all the comparisons, I really only want to compare A1 with A2, B1 with B2 and so on. My data set also includes C1&2, D1&2 and E1&2 so I am loosing quite some significance through the p-value adjustment seeing that the t-test is run for 45 pairs.

I could of course just run each t-tests I am interested seperately via the t.test() function and adjusted the p-values manually. However, I will have a similar but larger data set soon, maiking this a very tedious job. So I was wondering if there is an option in R to choose which comparisons are included in the pairwise.t.test(), or if there is another post hoc option that makes this possible.

Any advice would be greatly appreciated.

1

There are 1 answers

1
CPak On

Here's a quick way

Z <- split(X, substr(X$G, 1, 1))   # split your data frame into a list of data frames 
ans <- lapply(Z, function(A) with(A, pairwise.t.test(Y, Group, pool.sd=FALSE)))

Output

A list of your desired pairwise comparisons ($A group, $B group)

$A
        Pairwise comparisons using t tests with non-pooled SD 
data:  Y and Group 

   A1   
A2 0.019

P value adjustment method: holm 

$B
        Pairwise comparisons using t tests with non-pooled SD 
data:  Y and Group 

   B1     
B2 0.00015

P value adjustment method: holm