install.packages("pwrss")
library(pwrss)Power Analysis for Ordinal and Disordinal Contrasts
Instal and load the {pwrss} package in R:
1 Basic idea
In a \(2 \times 2\) factorial design, an interaction means that the effect of Factor \(A\) changes across the levels of Factor \(B\).
\[ \begin{array}{c|c|c} & B_1 & B_2 & \\ \hline A_1 & \mu_{A_1B_1} & \mu_{A_1B_2} & \\ \hline A_2 & \mu_{A_2B_1} & \mu_{A_2B_2} & \\ \hline \end{array} \]
The four cell means should be written in a specific order, which must be followed in mu.vector, sd.vector, p.vector, and contrast.matrix:
\[ [\mu_{A_1B_1},\ \mu_{A_1B_2},\ \mu_{A_2B_1},\ \mu_{A_2B_2}] \]
The simple effect of \(A\) at \(B_1\) and its contrast vector:
\[ D_{B_1} = \mu_{A_1B_1}-\mu_{A_2B_1} \]
\[ \mathbf{c}_{B_1}=[1,\ 0,\ -1,\ 0] \]
The simple effect of \(A\) at \(B_2\) and its contrast vector:
\[ D_{B_2} = \mu_{A_1B_2}-\mu_{A_2B_2} \]
\[ \mathbf{c}_{B_2}=[0,\ 1,\ 0,\ -1] \]
The interaction is the difference between these simple effects, and the interaction contrast is the difference between these two contrast vectors:
\[ \begin{aligned} \psi &=D_{B_1}-D_{B_2}\\ &=(\mu_{A_1B_1}-\mu_{A_2B_1}) -(\mu_{A_1B_2}-\mu_{A_2B_2})\\ &=\mu_{A_1B_1}-\mu_{A_1B_2} -\mu_{A_2B_1}+\mu_{A_2B_2} \end{aligned} \] \[ \begin{aligned} \mathbf{c}_{AB} &=[1,\ 0,\ -1,\ 0] - [0,\ 1,\ 0,\ -1]\\ &=[1,\ -1,\ -1,\ 1] \end{aligned} \]
| Contrast | A1B1 | A1B2 | A2B1 | A2B2 |
|---|---|---|---|---|
| Effect of A at B1 | 1 | 0 | -1 | 0 |
| Effect of A at B2 | 0 | 1 | 0 | -1 |
| Interaction | 1 | -1 | -1 | 1 |
2 Ordinal interaction
An ordinal interaction occurs when the two simple effects do not reverse direction. They usually have the same sign. The lines do not cross.
2.1 Cell means
| Factor A | B1 | B2 |
|---|---|---|
| A1 | 12 | 16 |
| A2 | 10 | 12 |
2.2 Simple effects
At \(B_1\):
\[ D_{B_1}=12-10=2 \]
At \(B_2\):
\[ D_{B_2}=16-12=4 \]
Both effects are positive, but the effect is larger at \(B_2\). Therefore, this is an ordinal interaction.
2.3 Interaction effect
\[ \begin{aligned} \psi &=D_{B_1}-D_{B_2}\\ &=2-4\\ &=-2 \end{aligned} \]
Using the interaction contrast gives the same answer:
\[ \begin{aligned} \psi &=1(12)-1(16)-1(10)+1(12)\\ &=-2 \end{aligned} \]
With a common population standard deviation of \(5\):
\[ d=\frac{\psi}{SD}=\frac{-2}{5}=-0.40 \]
2.4 Plot
2.5 Power analysis
power.f.ancova.shieh(
mu.vector = c(12, 16, 10, 12), # adjusted cell means (marginal)
sd.vector = c(5, 5, 5, 5), # unadjusted standard deviations
p.vector = c(0.25, 0.25, 0.25, 0.25), # should sum to 1
contrast.matrix = c(1, -1, -1, 1),
power = 0.80,
alpha = 0.05
)+--------------------------------------------------+
| SAMPLE SIZE CALCULATION |
+--------------------------------------------------+
One-Way Analysis of Covariance (F-Test)
----------------------------------------------------
Hypotheses
----------------------------------------------------
H0 (Null) : eta.squared = 0
H1 (Alternative) : eta.squared > 0
----------------------------------------------------
Results
----------------------------------------------------
Effect Size (eta-squared) = 0.010
Total Sample Size = 788 <<
Type 1 Error (alpha) = 0.050
Type 2 Error (beta) = 0.200
Statistical Power = 0.800
# or
power.t.contrast(
mu.vector = c(12, 16, 10, 12), # adjusted cell means (marginal)
sd.vector = c(5, 5, 5, 5), # unadjusted standard deviations
p.vector = c(0.25, 0.25, 0.25, 0.25), # should sum to 1
contrast.vector = c(1, -1, -1, 1),
power = 0.80,
alpha = 0.05,
verbose = 2
)+--------------------------------------------------+
| SAMPLE SIZE CALCULATION |
+--------------------------------------------------+
Single Contrast Analysis (T-Test)
----------------------------------------------------
Hypotheses
----------------------------------------------------
H0 (Null) : psi = 0
H1 (Alternative) : psi != 0
----------------------------------------------------
Key Parameters
----------------------------------------------------
Contrast Est. (psi) = -2
Standardized psi (d) = -0.400
Degrees of Freedom = 783
Non-centrality of Alt. = -2.805
Non-centrality of Null = 0
Critical Value = -1.963 and 1.963
----------------------------------------------------
Results
----------------------------------------------------
Effect Size (d) = -0.400
Total Sample Size = 788 <<
Type 1 Error (alpha) = 0.050
Type 2 Error (beta) = 0.200
Statistical Power = 0.800
----------------------------------------------------
Definitions
----------------------------------------------------
psi : Contrast estimate, sum(contrast[i] * mu[i])
d : Standardized contrast estimate
3 Disordinal interaction
A disordinal interaction, also called a crossover interaction, occurs when the two simple effects have opposite signs. The direction reverses, so the lines cross.
3.1 Cell means
| Factor A | B1 | B2 |
|---|---|---|
| A1 | 11 | 15 |
| A2 | 13 | 13 |
3.2 Simple effects
At \(B_1\):
\[ D_{B_1}=11-13=-2 \]
At \(B_2\):
\[ D_{B_2}=15-13=2 \]
The first simple effect is negative and the second is positive. Therefore, the direction reverses and this is a disordinal interaction.
3.3 Interaction effect
\[ \begin{aligned} \psi &=D_{B_1}-D_{B_2}\\ &=-2-2\\ &=-4 \end{aligned} \]
Using the interaction contrast gives the same answer:
\[ \begin{aligned} \psi &=1(11)-1(15)-1(13)+1(13)\\ &=-4 \end{aligned} \]
With a common population standard deviation of \(5\):
\[ d=\frac{\psi}{SD}=\frac{-4}{5}=-0.80 \]
3.4 Plot
3.5 Power analysis
power.f.ancova.shieh(
mu.vector = c(11, 15, 13, 13), # adjusted cell means (marginal)
sd.vector = c(5, 5, 5, 5), # unadjusted standard deviations
p.vector = c(0.25, 0.25, 0.25, 0.25), # should sum to 1
contrast.matrix = c(1, -1, -1, 1),
power = 0.80,
alpha = 0.05
)+--------------------------------------------------+
| SAMPLE SIZE CALCULATION |
+--------------------------------------------------+
One-Way Analysis of Covariance (F-Test)
----------------------------------------------------
Hypotheses
----------------------------------------------------
H0 (Null) : eta.squared = 0
H1 (Alternative) : eta.squared > 0
----------------------------------------------------
Results
----------------------------------------------------
Effect Size (eta-squared) = 0.038
Total Sample Size = 200 <<
Type 1 Error (alpha) = 0.050
Type 2 Error (beta) = 0.198
Statistical Power = 0.802
# or
power.t.contrast(
mu.vector = c(11, 15, 13, 13), # adjusted cell means (marginal)
sd.vector = c(5, 5, 5, 5), # unadjusted standard deviations
p.vector = c(0.25, 0.25, 0.25, 0.25), # should sum to 1
contrast.vector = c(1, -1, -1, 1),
power = 0.80,
alpha = 0.05,
verbose = 2
)+--------------------------------------------------+
| SAMPLE SIZE CALCULATION |
+--------------------------------------------------+
Single Contrast Analysis (T-Test)
----------------------------------------------------
Hypotheses
----------------------------------------------------
H0 (Null) : psi = 0
H1 (Alternative) : psi != 0
----------------------------------------------------
Key Parameters
----------------------------------------------------
Contrast Est. (psi) = -4
Standardized psi (d) = -0.800
Degrees of Freedom = 195
Non-centrality of Alt. = -2.821
Non-centrality of Null = 0
Critical Value = -1.972 and 1.972
----------------------------------------------------
Results
----------------------------------------------------
Effect Size (d) = -0.800
Total Sample Size = 200 <<
Type 1 Error (alpha) = 0.050
Type 2 Error (beta) = 0.198
Statistical Power = 0.802
----------------------------------------------------
Definitions
----------------------------------------------------
psi : Contrast estimate, sum(contrast[i] * mu[i])
d : Standardized contrast estimate
4 Challenge
Remember cell means for the ordinal contrast.
| Factor A | B1 | B2 |
|---|---|---|
| A1 | 12 | 16 |
| A2 | 10 | 12 |
How many participants are required to detect the main effect of A? Confirm with a reduced form of the code by considering factor A only (instead of factor.levels = c(2, 2), work around factor.levels = 2).
A total of at least 92 participants are required to detect the main effect of A.
Find out how: