1

When adding covariates to a between-subjects ANOVA model specified using rstatix package syntax, can one specify these covariates as having no interaction with the main effects?

For example, results from running the "RUN1" code below results in both main effects for the covariates (e.g., "CV1") but also interactions with the "Date" variable (e.g., "CV1:Date) displayed. However, some covariate interactions with the time variable may make no theoretical sense (for example, an individual's gender typically wouldn't change after 6 measurements 1 week apart), therefore, I would like to try and exclude these interactions from the model. "RUN2" and "RUN3" are some attempts so far to resolve this issue, but didn't work.

Does anybody know how this could be achieved?

My data:

MyData <- structure(list(ID = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
9L, 10L, 11L, 12L, 13L, 14L, 15L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 1L, 2L, 3L, 4L, 5L, 6L, 
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L), levels = c("5f609c2408813b0009898419", 
"5f9aacf32ab79c000bb1d56e", "5f9feef22ab79c000bb264c8", "5fa48df02ab79c000bb2ec4a", 
"5fa7d6c12ab79c000bb3495d", "5fac7ad22ab79c000bb3d6af", "6003785e2ab79c000978297b", 
"6003a1132ab79c0009782c8e", "6007a18d2ab79c000978526d", "600b9db52ab79c000bcf6d2e", 
"600e2b582ab79c000bcfeebe", "6010990c2ab79c000bd0698f", "6017a8992ab79c000b55eb27", 
"601b29eb2ab79c000b57a8d1", "60ff895fadbe1d0009fd07b2"), class = "factor"), 
    Date = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L), levels = c("1", "2", "3"), class = "factor"), 
    MeanValue = c(1.57142857142857, 3, 0.857142857142857, 1.28571428571429, 
    1.42857142857143, 1, 0.714285714285714, 0.142857142857143, 
    1.71428571428571, 0.285714285714286, 1.14285714285714, 1, 
    1.42857142857143, 0.428571428571429, 1.14285714285714, 1.14285714285714, 
    2.71428571428571, 1, 1.71428571428571, 0.857142857142857, 
    1.71428571428571, 0.857142857142857, 0.571428571428571, 1.57142857142857, 
    2.14285714285714, 1, 1.28571428571429, 1.71428571428571, 
    2.57142857142857, 3, 1.14285714285714, 2.57142857142857, 
    1.14285714285714, 1.42857142857143, 1.57142857142857, 1.57142857142857, 
    0.571428571428571, 0.142857142857143, 2.14285714285714, 0.428571428571429, 
    0.714285714285714, 0.714285714285714, 1.28571428571429, 3, 
    0.714285714285714), CV1 = c(43, 56, 73, 43, 49, 52, 52, 33, 
    35, 45, 51, 60, 45, 44, 59, 43, 56, 73, 43, 49, 52, 52, 33, 
    35, 45, 51, 60, 45, 44, 59, 43, 56, 73, 43, 49, 52, 52, 33, 
    35, 45, 51, 60, 45, 44, 59), CV2 = c("1", "2", "2", "1", 
    "1", "2", "2", "2", "2", "2", "2", "1", "1", "2", "1", "1", 
    "2", "2", "1", "1", "2", "2", "2", "2", "2", "2", "1", "1", 
    "2", "1", "1", "2", "2", "1", "1", "2", "2", "2", "2", "2", 
    "2", "1", "1", "2", "1"), CV3 = c(0, 1, 1, 1, 0, 1, 0, 0, 
    0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 
    1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0), CV4 = c(5, 
    5, 1, 1, 2, 5, 5, 4, 5, 5, 3, 5, 5, 5, 5, 5, 5, 1, 1, 2, 
    5, 5, 4, 5, 5, 3, 5, 5, 5, 5, 5, 5, 1, 1, 2, 5, 5, 4, 5, 
    5, 3, 5, 5, 5, 5), CV5 = c(0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 
    1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 
    1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1), CV6 = c(0, 
    1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 
    1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 
    0, 0, 1, 0, 1, 1)), row.names = c(NA, -45L), class = c("tbl_df", 
"tbl", "data.frame")) 

And the commands I ran:

# Load packages
library(tidyverse)
library(rstatix)

# RUN1: between subjects ANOVA using rstatix
res.aov <- anova_test(data = MyData, dv = MeanValue, wid = ID, within = Date,
                      covariate=c("CV1","CV2",
                                  "CV4","CV5"))
get_anova_table(res.aov)

# RUN2: specify formula
res.aov <- anova_test(data = MyData, dv = MeanValue, wid = ID, within = Date,
                      formula = MeanValue ~ Date + Error(ID/Date),
                      covariate=c("CV1","CV2",
                                  "CV4","CV5"))
get_anova_table(res.aov)

# RUN3: specify formula adding covariates directly in
res.aov <- anova_test(data = MyData, dv = MeanValue, wid = ID, within = Date,
                      formula = MeanValue ~ Date + CV1 + CV2 + CV4 + CV5 + Error(ID/Date))
get_anova_table(res.aov)
Shawn Hemelstrand
  • 2,676
  • 4
  • 17
  • 30
JoeyyyFunk
  • 70
  • 7

0 Answers0