Author

Jason S. Tsukahara

Published

May 4, 2024

Setup

# set global ggplot theme
theme_spacious <- function(font.size = 14, bold = TRUE){
  key.size <- trunc(font.size * .8)
  if (bold == TRUE) {
    face.type <- "bold"
  } else {
    face.type <- "plain"
  }

  theme(text = element_text(size = font.size),
        axis.title.x = element_text(margin = margin(t = 15, r = 0,
                                                    b = 0, l = 0),
                                    face = face.type),
        axis.title.y = element_text(margin = margin(t = 0, r = 15,
                                                    b = 0, l = 0),
                                    face = face.type),
        legend.title = element_text(face = face.type),
        legend.spacing = unit(20, "pt"),
        legend.text = element_text(size = key.size),
        plot.title = element_text(face = face.type, hjust = .5,
                                  margin = margin(b = 10)),
        plot.caption = element_text(hjust = 0, size = key.size,
                                    margin = margin(t = 20)),
        strip.background = element_rect(fill = "white", color = "white"),
        strip.text = element_text(color = "black",
                                  face = face.type))
}

output_theme <- theme_linedraw() + 
  theme_spacious(font.size = 12) + 
  theme(panel.border = element_rect(color = "gray"),
        axis.line.x = element_line(color = "gray"),
        axis.line.y = element_line(color = "gray"),
        panel.grid.minor.x = element_blank(),
        panel.grid.minor.y = element_blank())

theme_set(output_theme)
table_theme <- function(x, digits = 3, title = NULL, note = NULL) {
  kable(x, digits = digits, caption = title) |>
    kable_classic(position = "left") |>
    kable_styling(full_width = FALSE, position = "left") |>
    footnote(general = note)
}

Data

recall_import <- read_csv(here("data", "Recall_Data.csv"))
recall_data <- recall_import |>
  mutate(Memory_Strategy = factor(Memory_Strategy,
                                    levels = c("Rote Repetition", 
                                               "Visual Imagery")),
         Presentation_Rate = factor(Presentation_Rate,
                                    levels = c(1, 2, 4)))

ANOVA

anova_2way <- aov_car(Recall_Performance ~ 
                      Presentation_Rate*Memory_Strategy + 
                      Error(Subject/Presentation_Rate),
                    data = recall_data)
Contrasts set to contr.sum for the following variables: Memory_Strategy
Code
anova_tables(anova_2way, 
             contrast = c("Presentation_Rate", "Memory_Strategy"), 
             at = c("Presentation_Rate", "Memory_Strategy"))
ANOVA Table: Recall_Performance
Term SS SS Error df df Error MS MS Error F p ηp2 ωp2
Memory_Strategy 8957.952 7007.126 1.000  88.000 79.626  0.708 112.500 <0.001 0.561 0.553
Presentation_Rate 5953.815 9445.486 1.950 171.619 55.037  0.992  55.469 <0.001 0.387 0.260
Memory_Strategy:Presentation_Rate  272.792 9445.486 1.950 171.619 55.037 21.655   2.541     0.083 0.028 0.010
Model: aov_car(Recall_Performance ~ (Presentation_Rate) * (Memory_Strategy) + Error(Subject/(Presentation_Rate)))
df correction: Greenhouse-Geisser
N = 90
Post-hoc Comparisons: Presentation_Rate
Level 1 Level 2 Difference CI 95% SE df t p Cohen's D
1 2  −6.093  −8.091 — −4.095 1.005 88   −6.061 <0.001 −0.562
1 4 −11.496 −13.703 — −9.288 1.111 88  −10.348 <0.001 −1.060
2 4  −5.402  −7.697 — −3.108 1.155 88   −4.679 <0.001 −0.498
p-values are uncorrected.
Post-hoc Comparisons: Memory_Strategy
Level 1 Level 2 Difference CI 95% SE df t p Cohen's D
Rote Repetition Visual Imagery −11.520 −13.678 — −9.362 1.086 88  −10.607 <0.001 −1.062
p-values are uncorrected.
Post-hoc Comparisons: Presentation_Rate x Memory_Strategy
Level 1 Level 2 Memory_Strategy Difference CI 95% SE df t p Cohen's D
1 2 Rote Repetition  −8.500 −11.326 — −5.674  1.422 88  −5.978 <0.001 −0.784
1 2 Visual Imagery  −3.687  −6.512 — −0.861  1.422 88  −2.593     0.011 −0.340
1 4 Rote Repetition −13.149 −16.271 — −10.027 1.571 88  −8.369 <0.001 −1.212
1 4 Visual Imagery  −9.842 −12.964 — −6.720  1.571 88  −6.265 <0.001 −0.908
2 4 Rote Repetition  −4.649  −7.894 — −1.404  1.633 88  −2.847     0.005 −0.429
2 4 Visual Imagery  −6.156  −9.400 — −2.911  1.633 88  −3.770 <0.001 −0.568
p-values are uncorrected.
Post-hoc Comparisons: Memory_Strategy x Presentation_Rate
Level 1 Level 2 Presentation_Rate Difference CI 95% SE df t p Cohen's D
Rote Repetition Visual Imagery 1 −14.227 −17.464 — −10.989 1.629 88  −8.732 <0.001 −1.312
Rote Repetition Visual Imagery 2  −9.413 −12.687 — −6.139  1.647 88  −5.714 <0.001 −0.868
Rote Repetition Visual Imagery 4 −10.920 −14.328 — −7.512  1.715 88  −6.368 <0.001 −1.007
p-values are uncorrected.
Code
ggplot(recall_data, aes(x = Presentation_Rate, y = Recall_Performance,
                 color = Memory_Strategy, fill = Memory_Strategy)) +
  geom_flat_violin(aes(fill = Memory_Strategy),
                   position = position_nudge(x = .1, y = 0),
                   adjust = 1.5, trim = FALSE, 
                   alpha = .5, colour = NA) +
  geom_point(aes(as.numeric(Presentation_Rate) - .15), 
             position = position_jitter(width = .05), alpha = .2) +
  stat_summary(aes(group = Memory_Strategy),
               fun = mean, geom = "line", linewidth = 1) +
  stat_summary(fun = mean, geom = "point", size = 3) + 
  stat_summary(fun.data = mean_cl_normal, geom = "errorbar", 
               width = .1) +
  labs(x = "Presentation_Rate", y = "Recall Performance") +
  scale_color_brewer(palette = "Set1", name = "Memory Strategy") +
  scale_fill_brewer(palette = "Set1") +
  guides(fill = "none")

Code
summary(anova_2way)

Univariate Type III Repeated-Measures ANOVA Assuming Sphericity

                                  Sum Sq num Df Error SS den Df   F value
(Intercept)                       102348      1   7007.1     88 1285.3515
Memory_Strategy                     8958      1   7007.1     88  112.4997
Presentation_Rate                   5954      2   9445.5    176   55.4694
Memory_Strategy:Presentation_Rate    273      2   9445.5    176    2.5415
                                   Pr(>F)    
(Intercept)                       < 2e-16 ***
Memory_Strategy                   < 2e-16 ***
Presentation_Rate                 < 2e-16 ***
Memory_Strategy:Presentation_Rate 0.08164 .  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Mauchly Tests for Sphericity

                                  Test statistic p-value
Presentation_Rate                        0.97448 0.32474
Memory_Strategy:Presentation_Rate        0.97448 0.32474


Greenhouse-Geisser and Huynh-Feldt Corrections
 for Departure from Sphericity

                                   GG eps Pr(>F[GG])    
Presentation_Rate                 0.97511    < 2e-16 ***
Memory_Strategy:Presentation_Rate 0.97511    0.08311 .  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

                                     HF eps   Pr(>F[HF])
Presentation_Rate                 0.9969213 2.353114e-19
Memory_Strategy:Presentation_Rate 0.9969213 8.181690e-02