Multiple Comparison

Normally, researchers are not only satisifed with testing the omnibus scientific hypothesis that \(\mu_{j}\neq\mu_{j}\), \(\forall j\neq k\), but also interested in which conditions would be effective in the behavior of our interest. To this end, we need to make comparisons for the means of conditions. There are two types of such comparisons: a priori comparisons and post hoc comparisons.

A Priori Comparison

A priori comparions are referred to as those comparisons which are chosen before the data are collected. On the contrary, the post hoc comparisons are referred to as those comparisons which are planned after the experimenter has collected the data.

However, in practice, the real distinction seems to come down to the difference between deliberately making a few comparisons that are chosen because of their theoretical or practical nature and making comparisons among all possible pairs of means.

A Numeric Example

It is known that morphine is often used to alleviate pain. Also, repeated administrations of morphine will lead to morphine tolerance, in which morphine has less and less of an effect over time. Siegel theorized that if you administered a series of pretrials in which the animal was in jected with morphine and placed on a warm surface, morphine tolerance would develop. Thus, if you again injected the subject with morphine on a subsequent test trial, the animal would be only as sensitive to pain as would a naive animal because of the tolerance that has fully developed.

Siegel further reasoned that if on the test trial, you instead injected the animal with physiological saline in the same test setting as the normal morphine injections, the conditioned hypersensitivity that results from the repeated administration of morphine would not be counterbalanced by the presence of morphine, and the animal would show very short paw-lick latency and heighten sensitivity. Siegel also reasoned that if you gave the animal repeated morphine injections in one setting but then tested it with morphine in a new setting, the new setting would not elicit the conditioned compensatory hypersensitivity to counterbalance the morphine.

The experiment involved five groups of rats. Each group received four trials, but the data for the analysis come from only the test trial. Group M-M received morphine on the first three trials in the test setting and then again on the fourth trial in the same test setting. Group M-S received morphine on the firsst three trials but then receied saline on the fourth trial. Group M (cage)-M (abbreviated as Mc-M) received morphine on the frist three trials in their home cage but then received morphine on the fourth trial in the standard test setting. Group S-M received saline on the first three trials and morphine on the fourth trial. Finally, group S-S received saline on all four trials. The fictitious data are created as follow.

morphine.dta<-data.frame(G=gl(5,8,5*8,labels=c("MS","MM","SS","SM","McM")),
                         Y=c(3,5,1,8,1,1,4,9,
                             2,12,13,6,10,7,11,19,
                             14,6,12,4,19,3,9,21,
                             29,20,36,21,25,18,26,17,
                             24,26,40,32,20,33,27,30))
summary(morphine.dta)
##    G           Y        
##  MS :8   Min.   : 1.00  
##  MM :8   1st Qu.: 6.00  
##  SS :8   Median :13.50  
##  SM :8   Mean   :15.60  
##  McM:8   3rd Qu.:24.25  
##          Max.   :40.00

Let’s check the mean duration of each condition. According to the visual inspection of this bar plot, it is expected that the omnibus F test for the experimental treatment should be significant.

library(ggplot2)
means<-with(morphine.dta,tapply(Y,G,mean))
ses<-with(morphine.dta,tapply(Y,G,sd))/table(morphine.dta$G)
ggplot(data.frame(means=means,ses=ses,cond=c("MS","MM","SS","SM","McM")),
       aes(x=cond,y=means))+
  geom_bar(stat="identity",fill="pink")+
  geom_errorbar(aes(ymin=means-ses,ymax=means+ses),width=0.1)+
  scale_x_discrete(name="Condition")+ylab("Mean Duriation")

Indeed, the omnibus F test shows that at least one comparison among all pairs of group means is significant. See the below summary of this F test. The effect size is strong, \(\omega^2=0.72\), that the experimental treatment can account for 72% of the variety of the observed data. You can find the function designed for computing \(\omega^2\) in here.

morphine.aov<-aov(Y~G,morphine.dta)
summary(morphine.aov)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## G            4   3498   874.4   27.32 2.44e-10 ***
## Residuals   35   1120    32.0                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# You have to have omega.R in the same path
source("omega.R")
omega_sq(morphine.aov)
## [1] 0.7247075

According to Siegel’s theory, it is anticipated that group S-M should show the longest latencies, whereas group M-S should show the shortest latency. Group Mc-M should resemble group S-M. Groups M-M and S-S should be intermediate. The pattern of anticipated results is

S-M = Mc-M > M-M ? S-S > M-S.

Let’s test Siegel’s hypothesis. Remember \(t\) test? We can run a \(t\) test for comparing two group means of our interest with \(MS_{error}\) substituting \(s^2_{pooled}\) as

\(t=\frac{\overline{X_{i}}-\overline{X_{j}}}{\sqrt{\frac{MS_{error}}{n}+\frac{MS_{error}}{n}}}\).

Thus, the comparison between M-S and S-S can be computed as below. Notice the degrees of freedom now is the one of the error term (\(MS_{error}\)) in the overall design, namely \(5\times(8-1)=35\).

t.score1<-(means[1]-means[3])/sqrt(2*32/dim(subset(morphine.dta,G=="MS"))[1])
pt(t.score1,35)*2
##         MS 
## 0.01831864

Similarly, we can test the comparison between the means of Mc-M and M-M groups.

t.score2<-(means[5]-means[2])/sqrt(2*32/dim(subset(morphine.dta,G=="MS"))[1])
(1-pt(t.score2,35))*2
##          McM 
## 8.872312e-08

There are several issues to address here. First, the variance is replaced by \(MS_{error}\). Normally, the variance of the independent-groups \(t\) test is \(s^2_{spooled}\), which is the estimate of population variance. However, the \(MS_{error}\) of the whole experimental design is made with all means taken into consideration. If we only focus on the comparison between the MS group and the SS group, then the standard error of the independent-groups \(t\) test for them should not be the same as the \(MS_{error}\) of the whole experimental design. Thus, some statisticans suggest to use the \(MS_{error}\) computed only for the data in these two conditions. We can compare these two approaches with the current example.

The following codes select the MS and SS conditions for F test. The \(MS_{error}\) is 27.57 of course different from the \(MS_{error}\) of the omnibus F test. We can run an independent-groups \(t\) test for comparing these two means. The standard error is 2.625 (see v$stderr). As here the standard error is \(s_{spooled}\sqrt{\frac{2}{n}}\), we can compute the square of v$stderr multiplied by \(n/2\) to get \(s^2_{spooled}\). As shown in the following output, this value is exactly the same as the \(MS_{error}\) in the F test for the data set including MS and SS conditions only. The \(MS_{error}\) here is smaller than the \(MS_{error}\) in the omnibus F test. Presumably, the \(t\) value here should be more extreme than the \(t\) value computed with the omnibus \(MS_{error}\). these two \(p\) values are not different. This is true. However, the difference is too small and the \(p\) values are almost the same. Thus, the conclusion is the same.

d<-subset(morphine.dta,G=="MS" | G=="SS")
summary(aov(Y~G,d))
##             Df Sum Sq Mean Sq F value Pr(>F)  
## G            1    196  196.00   7.109 0.0184 *
## Residuals   14    386   27.57                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
v<-with(d,t.test(Y~G,var.equal=T))
v$stderr
## [1] 2.625425
v$stderr^2*8/2
## [1] 27.57143
c(v$statistic,t.score1)
##         t        MS 
## -2.666235 -2.474874

However, if the variety of observed scores is quite big, then perhaps these two approaches would lead to different conclusions. Suppose we have four conditions in an experiment. The variance of population error for group 1 and group 2 is estimated by \(MS_{error_{12}}\). The variance of population error for group 3 and group 4 is estimated by \(MS_{error_{34}}\). Suppose again \(MS_{error_{12}}\) is very small and \(MS_{error_{34}}\) is very large. Thus, \(MS_{error_{12}}<<MS_{error}<<MS_{error_{34}}\), where \(MS_{error}\) is the mean of squares error in the omnibus F test. Now if we test the comparison of \(\overline{x}_1\) vs. \(\overline{x}_2\) with \(MS_{error}\) as the pooled variance, the \(t\) value will be underestimated. On the contrary, if we test the comparison of \(\overline{x}_3\) vs. \(\overline{x}_4\) with \(MS_{error}\) as the pooled variance, we will overestimate the \(t\) value. This is the reason for those statisticians suggest not to use the overall \(MS_{error}\) for individual \(t\) tests.

However, according to the homogeneity of variance assumption in ANOVA, the individual \(MS_{error}\) should be pretty much the same as the overall \(MS_{error}\). Thus, whether the overall \(MS_{error}\) or the individual \(MS_{error}\) should be used becomes a choice.

Second, why are the Type I errors for the two comparisons in the above example still 0.05? Every time we do a null hypothesis testing, the risk to reject a true \(H_o\) is 0.05. Then, when we do two comparisons with \(t\) test, the Type I error should inflated to 0.1. With Bonferroni correction, we should lower the Type I error in each comparison from 0.05 to 0.025. However, we didn’t do so in the above examples. There could be at least two reasons. One can be found in P. 377 in Chapter 12 that it is very unlikely to have two \(H_o\) both true at the same time. The other is that these two comparisons are actually independent of each other. When the multiple comparisons are independent of each other, there is no need to worry about the inflation of Type I error.

Third, although we did not emphasize, actually \(t^2=F\). You can see the square of the \(t\) statistic for the comparison between means of MS and SS conditions is exactly the value in the summary table of the F test for the data of these two conditions. \(F=\frac{MS_{treat}}{MS_{error}}\) and \(t=\frac{\overline{x}_1-\overline{x}_2}{\sqrt{\frac{2MS_{error}}{n}}}\). Then,

\(t^2=\frac{(\overline{x}_1-\overline{x}_2)^2}{\frac{2MS_{error}}{n}}\) \(\rightarrow\) \(t^2=\frac{n(\overline{x}_1-\overline{x}_2)^2}{2MS_{error}}\) \(\rightarrow\) \(t^2=\frac{\frac{n}{2}(\overline{x}_1-\overline{x}_2)^2}{MS_{error}}\). As, herein, \(\sum_j(\overline{x}_j-\overline{x})^2=(\overline{x}_1-\overline{x})^2+(\overline{x}_2-\overline{x})^2\). Also, \(\overline{x}=\frac{\overline{x}_1+\overline{x}_2}{2}\). Then, \((\overline{x}_1-\overline{x})^2=(\overline{x}_1-\frac{\overline{x}_1+\overline{x}_2}{2})^2=\frac{1}{4}(\overline{x}_1-\overline{x}_2)^2\). Similarly, \((\overline{x}_2-\overline{x})^2=\frac{1}{4}(\overline{x}_2-\overline{x}_1)^2=\frac{1}{4}(\overline{x}_1-\overline{x}_2)^2\).

Therefore, \((\overline{x}_1-\overline{x})^2+(\overline{x}_2-\overline{x})^2=\frac{1}{2}(\overline{x}_1-\overline{x}_2)^2\).

\(t^2=\frac{\frac{n}{2}(\overline{x}_1-\overline{x}_2)^2}{MS_{error}}=\frac{\frac{n}{2}[(\overline{x}_1-\overline{x})^2+(\overline{x}_2-\overline{x})^2]}{MS_{error}}=\frac{n\sum(\overline{x}_j-\overline{x})^2}{MS_{error}}=\frac{SS_{treat}}{MS_{error}}\). As the \(df\) for the comparison between 2 means is 2-1=1, \(SS_{treat}=MS_{treat}\). Therefore, \(t^2=\frac{MS_{treat}}{MS_{error}}=F\).

v$statistic^2
##        t 
## 7.108808

Linear Contrasts

The use of individual t test is a special case of a much more general technique involving what are known as linear contrasts. To define a linear contrast, we must first define a linear combination, which takes the form

\(L=a_{1}\overline{X}_{1}+a_{2}\overline{X}_{2}+\cdots+a_{k}\overline{X}_{k}=\sum a_{j}\overline{X}_{j}\).

When we impose the restriction that \(\sum a_{j}=0\), a linear combination becomes what is called a linear contrast. As an example, consider three means. Letting \(a_{1}=1\), \(a_{2}=-1\), and \(a_{3}=0\), \(\sum a_{j}=0\).

\(\psi=(1)\overline{X}_{1}+(-1)\overline{X}_{2}+(0)\overline{X}_{3}=\overline{X}_{1}-\overline{X}_{2}\)

Similarly, with the coefficients for different groups as 1/2, 1/2, and -1, the contrast becomes

\(\psi=(1/2)\overline{X}_{1}+(1/2)\overline{X}_{2}+(-1)\overline{X}_{3}=\frac{\overline{X}_{1}+\overline{X}_{2}}{2}-\overline{X}_{3}\).

Sum of Squares for Contrasts

One of the advantages of linear contrast is that they can be converted to sums of squares very easily and can represent the sum of squared differences between the means of sets of treatments. If we write

\(\psi=a_{1}\overline{X}_{1}+a_{2}\overline{X}_{2}+\cdots+a_{k}\overline{X}_{k}=\sum a_{j}\overline{X}_{j}\)

it can be shown that

\(SS_{contrast}=\frac{n\psi^2}{\sum a_{j}^2}\)

is a component of the overall \(SS_{contrast}\) on 1 \(df\), where \(n\) represents the number of scores per treatment. For unequal sample sizes, \(SS_{contrast}=\frac{\psi^2}{\sum(a_{j}^2)/n_{j}}\).

Recall the \(SS_{treat}\) in the overall analysis of variance as

summary(morphine.aov)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## G            4   3498   874.4   27.32 2.44e-10 ***
## Residuals   35   1120    32.0                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

If we want to test the comparison between MS and SS, the coefficients for group means are [1 0 -1 0 0], namely \(\psi_{1}=(1)\overline{X}_{1}+(0)\overline{X}_{2}+(-1)\overline{X}_{3}+(0)\overline{X}_{4}+(0)\overline{X}_{5}=\overline{X}_{1}-\overline{X}_{3}\).

The sums of squares of \(\psi_{1}\) is

(8*(means[1]-means[3])^2)/2
##  MS 
## 196

Similarly, the comparison between MM and McM can be computed with the coefficients set as [0 1 0 0 -1] and the sums of squares of \(\psi_{2}\) is

coeff<-matrix(c(0,1,0,0,-1),5,1)
8*(means%*%coeff)^2/2
##      [,1]
## [1,] 1444

Again, we can test another two comparisons with the coefficients as [1/2 -1/2 1/2 0 -1/2] and [1/4 1/4 1/4 -1 1/4].

coeff<-matrix(c(0.5,-0.5,0.5,0,-0.5,
                0.25,0.25,0.25,-1,0.25),5,2)
8*(means%*%coeff)^2/(c(4*0.5^2,1+4*0.25^2))
##      [,1]  [,2]
## [1,] 1152 705.6

Now if we add up the sums of squares of all contrasts above, namely 196+1444+1152+705.6, we find the sum is equal to \(SS_{treat}\).

196+1444+1152+705.6
## [1] 3497.6
sum(8*(means-mean(means))^2)
## [1] 3497.6

Thus, we say that we have completely partitioned \(SS_{treat}\). In linear alegbra, these contrasts are orthogonal to each other, \(\psi_{i}\cdot\psi{j}=0\). If we have \(k\) groups, we can find \(k-1\) orthogonal contrasts. Also, each contrast has 1 \(df\) and the sum of these \(df\) is just the \(df\) for \(SS_{treat}\), namely 4. We can also use F test to test the significance for each contrast.

\(F=\frac{MS_{contrast}}{MS_{error}}=\frac{n\psi^2/\sum(a_{j}^2)}{MS_{error}}=\frac{n\psi^2}{\sum(a_{j}^2)MS_{error}}\)

Suppose we have four contrasts to test for the 5 group means as listed in below table. Now we can test all contrasts at once.

Groups MS MM SS SM McM
\(c_{1}\) -1/3 -1/3 -1/3 1/2 1/2
\(c_{2}\) 0 -1 0 0 1
\(c_{3}\) -1 0 1 0 0
\(c_{4}\) 0 1 -1 0 0
morphine.dta$C1<-rep(c(-1/3,-1/3,-1/3,1/2,1/2),each=8)
morphine.dta$C2<-rep(c(0,-1,0,0,1),each=8)
morphine.dta$C3<-rep(c(-1,0,1,0,0),each=8)
morphine.dta$C4<-rep(c(0,1,-1,0,0),each=8)
morphine_c.aov<-aov(Y~C1+C2+C3+C4,morphine.dta)
summary(morphine_c.aov)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## C1           1   3168    3168  99.008 9.66e-12 ***
## C2           1      5       5   0.149   0.7020    
## C3           1    196     196   6.125   0.0183 *  
## C4           1    129     129   4.018   0.0528 .  
## Residuals   35   1120      32                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

However, these results are not correct! Why? These contrasts are nonorthogonal contrasts but the model for aov() requires the independent variables are independent of each other. That is the contrasts used as the independent variables must be orthogonal to each other.

There are two solutions to this problem. One is to compute the \(\psi\) by R codes and the other is to provide the function aov() a correct error term. Notice that this is not the authentic way to deal with the nonorthogonal contrasts, yet it works. Also, notice that it doesn’t work if you write the code like “aov(Y~G+C1,data)”. As C1 is a component of G, when G is put before C1, aov() would ignore C1 as an independent variable.

morphine_c1.aov<-aov(Y~C1+G,morphine.dta)
morphine_c2.aov<-aov(Y~C2+G,morphine.dta)
morphine_c3.aov<-aov(Y~C3+G,morphine.dta)
morphine_c4.aov<-aov(Y~C4+G,morphine.dta)
summary(morphine_c1.aov)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## C1           1   3168    3168  99.008 9.66e-12 ***
## G            3    329     110   3.431   0.0274 *  
## Residuals   35   1120      32                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(morphine_c2.aov)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## C2           1   1444  1444.0   45.12 8.87e-08 ***
## G            3   2054   684.5   21.39 4.78e-08 ***
## Residuals   35   1120    32.0                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(morphine_c3.aov)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## C3           1    196     196   6.125   0.0183 *  
## G            3   3302    1100  34.392 1.54e-10 ***
## Residuals   35   1120      32                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(morphine_c4.aov)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## C4           1      4       4   0.125    0.726    
## G            3   3494    1164  36.392 7.36e-11 ***
## Residuals   35   1120      32                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Another Numeric Example

See the data listed as below. There are four conditions, in each of which 8 scores from different subjects are collected.

dta<-data.frame(G=gl(4,8,4*8,labels=1:4),
                Y=c(3,6,3,3,1,2,2,2,
                    4,5,4,3,2,3,4,3,
                    7,8,7,6,5,6,5,6,
                    7,8,9,8,10,10,9,11))
dim(dta)
## [1] 32  2

The omnibus F test first reveals a significant effect of G. The \(\eta^2=0.83\) and \(\omega^2=0.80\).

res.aov<-aov(Y~G,dta)
summary(res.aov)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## G            3  194.5   64.83   44.28 9.32e-11 ***
## Residuals   28   41.0    1.46                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(lm(Y~G,dta))
## 
## Call:
## lm(formula = Y ~ G, data = dta)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.0000 -0.7500 -0.1250  0.5625  3.2500 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   2.7500     0.4278   6.428 5.83e-07 ***
## G2            0.7500     0.6050   1.240    0.225    
## G3            3.5000     0.6050   5.785 3.27e-06 ***
## G4            6.2500     0.6050  10.330 4.68e-11 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.21 on 28 degrees of freedom
## Multiple R-squared:  0.8259, Adjusted R-squared:  0.8072 
## F-statistic: 44.28 on 3 and 28 DF,  p-value: 9.321e-11
omega_sq(res.aov)
## [1] 0.8022607

Now suppose the researcher wants to test three contrasts with the null hypotheses as follow. As these contrasts are orthogonal to each other, let’s create the coefficient variables in the data and use aov() to do the analysis of variance.

\(H_{o}: \mu_{1}-\mu_{2}=0\)

\(H_{o}: \mu_{3}-\mu_{4}=0\)

\(H_{o}: (\mu_{1}+\mu_{2})-(\mu_{3}+\mu_{4})=0\)

dta$C1<-rep(c(1,-1,0,0),each=8)
dta$C2<-rep(c(0,0,1,-1),each=8)
dta$C3<-rep(c(0.5,0.5,-0.5,-0.5),each=8)
cs.aov<-aov(Y~C1+C2+C3,dta)
summary(cs.aov)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## C1           1   2.25    2.25   1.537    0.225    
## C2           1  30.25   30.25  20.659 9.61e-05 ***
## C3           1 162.00  162.00 110.634 3.12e-11 ***
## Residuals   28  41.00    1.46                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

We can make a plot to show the pattern of these group means.

means<-with(dta,tapply(Y,G,mean))
ses<-with(dta,tapply(Y,G,sd))/sqrt(8)
ggplot(data.frame(means=means,ses=ses,cond=1:4),aes(cond,means))+
  geom_point()+geom_line()+
  geom_errorbar(aes(ymin=means-ses,ymax=means+ses),width=0.1)

One More Numeric Example

The file “stress.txt” contains the stress reduction scores with three different treatments (mental, physical, and medical). Please answer the questions that (1) whether there is an effect of treatment on reducing stress and (2)

dta<-read.table("stress.txt",header=T,sep=",")
summary(dta)
##   Treatment         StressReduction
##  Length:30          Min.   :1.000  
##  Class :character   1st Qu.:2.000  
##  Mode  :character   Median :3.000  
##                     Mean   :2.833  
##                     3rd Qu.:4.000  
##                     Max.   :5.000
means<-with(dta,tapply(StressReduction,Treatment,mean))
ses<-with(dta,tapply(StressReduction,Treatment,sd))/sqrt(table(dta$Treatment))
ggplot(data.frame(means=means,ses=ses,cond=unique(dta$Treatment)),aes(cond,means))+
  geom_bar(stat="identity",fill="gray50")+
  geom_errorbar(aes(ymin=means-ses,ymax=means+ses),width=0.2)+
  scale_x_discrete(name="Treatment")+ylab("Stress")

The omnibus F test supports that there is a significant treatment effect, \(F(2,27)=5.16\), \(MSe=1.13\), \(p<.05\). The \(\eta^2=0.28\) and \(\omega^2=0.21\).

sr.aov<-aov(StressReduction~Treatment,dta)
summary(sr.aov)
##             Df Sum Sq Mean Sq F value Pr(>F)  
## Treatment    2  11.67   5.833   5.164 0.0126 *
## Residuals   27  30.50   1.130                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(lm(StressReduction~Treatment,dta))
## 
## Call:
## lm(formula = StressReduction ~ Treatment, data = dta)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -2.000 -0.875  0.000  0.875  2.000 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)         2.0000     0.3361   5.951 2.41e-06 ***
## Treatmentmental     1.5000     0.4753   3.156  0.00391 ** 
## Treatmentphysical   1.0000     0.4753   2.104  0.04484 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.063 on 27 degrees of freedom
## Multiple R-squared:  0.2767, Adjusted R-squared:  0.2231 
## F-statistic: 5.164 on 2 and 27 DF,  p-value: 0.01262
omega_sq(sr.aov)
## [1] 0.2172797

Let’s check the contrasts of “medical” vs. “physical” and the average of “medical” and “physical” vs. “mental”. The results shows that both contrasts are significant.

dta$C1<-rep(c(0,1,-1),each=10)
dta$C2<-rep(c(-1,0.5,0.5),each=10)
summary(aov(StressReduction~C1+C2,dta))
##             Df Sum Sq Mean Sq F value Pr(>F)  
## C1           1  5.000   5.000   4.426 0.0448 *
## C2           1  6.667   6.667   5.902 0.0221 *
## Residuals   27 30.500   1.130                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1