Install the packages if they are not already installed.
rm(list = ls())
options(scipen = 999)
if (!("pacman" %in% installed.packages())) install.packages("pacman")
Load the R packages.
pacman::p_load(tidyverse, bruceR)
Load and name the dataset.
dat <- bruceR::import("E1_LocalComprehension.csv")
Check the data frame and for missings.
dim(dat)
## [1] 3200 7
colnames(dat)
## [1] "Participant" "Item" "Tracing_type" "Cueing_type"
## [5] "Score" "Prior_knowledge" "Spatial_ability"
str(dat)
## 'data.frame': 3200 obs. of 7 variables:
## $ Participant : chr "A1003" "A1003" "A1003" "A1003" ...
## $ Item : chr "local1" "local2" "local3" "local4" ...
## $ Tracing_type : chr "yes" "yes" "yes" "yes" ...
## $ Cueing_type : chr "yes" "yes" "yes" "yes" ...
## $ Score : int 1 1 1 1 1 1 1 1 1 1 ...
## $ Prior_knowledge: int 16 16 16 16 16 16 16 16 16 16 ...
## $ Spatial_ability: int 6 6 6 6 6 6 6 6 6 6 ...
summary(dat)
## Participant Item Tracing_type Cueing_type
## Length:3200 Length:3200 Length:3200 Length:3200
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
## Score Prior_knowledge Spatial_ability
## Min. :0.0000 Min. : 4.00 Min. : 0.000
## 1st Qu.:0.0000 1st Qu.: 8.00 1st Qu.: 5.000
## Median :1.0000 Median :12.00 Median : 8.000
## Mean :0.5809 Mean :10.73 Mean : 8.613
## 3rd Qu.:1.0000 3rd Qu.:14.00 3rd Qu.:12.000
## Max. :1.0000 Max. :16.00 Max. :20.000
head(dat)
## Participant Item Tracing_type Cueing_type Score Prior_knowledge
## 1 A1003 local1 yes yes 1 16
## 2 A1003 local2 yes yes 1 16
## 3 A1003 local3 yes yes 1 16
## 4 A1003 local4 yes yes 1 16
## 5 A1003 local5 yes yes 1 16
## 6 A1003 local6 yes yes 1 16
## Spatial_ability
## 1 6
## 2 6
## 3 6
## 4 6
## 5 6
## 6 6
dat_ANCOVA <- dat %>%
dplyr::filter(Cueing_type == "no") %>%
dplyr::group_by(Participant, Tracing_type) %>%
dplyr::summarise(Sum_score = sum(Score, na.rm = TRUE),
Prior_knowledge = mean(Prior_knowledge, na.rm = TRUE),
Spatial_ability = mean(Spatial_ability, na.rm = TRUE)) %>%
dplyr::ungroup() %>%
dplyr::mutate(
Spatial_ability = case_when(
Spatial_ability < mean(Spatial_ability, na.rm = TRUE) ~ "low",
Spatial_ability >= mean(Spatial_ability, na.rm = TRUE) ~ "high"
)
)
## `summarise()` has grouped output by 'Participant'. You can override using the
## `.groups` argument.
dat_ANCOVA %>%
dplyr::group_by(Tracing_type, Spatial_ability) %>%
dplyr::summarise(n = n()) %>%
bruceR::print_table(digits = 0)
## `summarise()` has grouped output by 'Tracing_type'. You can override using the
## `.groups` argument.
## ──────────────────────────────────
## Tracing_type Spatial_ability n
## ──────────────────────────────────
## 1 no high 18
## 2 no low 22
## 3 yes high 17
## 4 yes low 23
## ──────────────────────────────────
m <- bruceR::MANOVA(dat_ANCOVA, dv = "Sum_score", between = c("Tracing_type", "Spatial_ability"), covariate = "Prior_knowledge")
## Warning: Numerical variables NOT centered on 0 (matters if variable in interaction):
## Prior_knowledge
##
## ====== ANOVA (Between-Subjects Design) ======
##
## Descriptives:
## ───────────────────────────────────────────────────
## "Tracing_type" "Spatial_ability" Mean S.D. n
## ───────────────────────────────────────────────────
## no high 10.389 (4.368) 18
## no low 11.727 (3.011) 22
## yes high 14.588 (3.572) 17
## yes low 11.087 (3.825) 23
## ───────────────────────────────────────────────────
## Total sample size: N = 80
##
## ANOVA Table:
## Dependent variable(s): Sum_score
## Between-subjects factor(s): Tracing_type, Spatial_ability
## Within-subjects factor(s): –
## Covariate(s): Prior_knowledge
## ───────────────────────────────────────────────────────────────────────────────────────────────
## MS MSE df1 df2 F p η²p [90% CI of η²p] η²G
## ───────────────────────────────────────────────────────────────────────────────────────────────
## Tracing_type 63.236 13.861 1 75 4.562 .036 * .057 [.002, .161] .057
## Spatial_ability 19.663 13.861 1 75 1.419 .237 .019 [.000, .097] .019
## Prior_knowledge 1.015 13.861 1 75 0.073 .787 .001 [.000, .038] .001
## Tracing_type * Spatial_ability 113.829 13.861 1 75 8.212 .005 ** .099 [.018, .216] .099
## ───────────────────────────────────────────────────────────────────────────────────────────────
## MSE = mean square error (the residual variance of the linear model)
## η²p = partial eta-squared = SS / (SS + SSE) = F * df1 / (F * df1 + df2)
## ω²p = partial omega-squared = (F - 1) * df1 / (F * df1 + df2 + 1)
## η²G = generalized eta-squared (see Olejnik & Algina, 2003)
## Cohen’s f² = η²p / (1 - η²p)
##
## Levene’s Test for Homogeneity of Variance:
## ───────────────────────────────────────────
## Levene’s F df1 df2 p
## ───────────────────────────────────────────
## DV: Sum_score 1.222 3 76 .308
## ───────────────────────────────────────────
emmeans::emmip(m, Tracing_type ~ Spatial_ability, CIs = TRUE)
emmeans::emmip(m, Spatial_ability ~ Tracing_type, CIs = TRUE)
bruceR::EMMEANS(m, effect = "Tracing_type", by = "Spatial_ability")
## ------ EMMEANS (effect = "Tracing_type") ------
##
## Joint Tests of "Tracing_type":
## ───────────────────────────────────────────────────────────────────────────────
## Effect "Spatial_ability" df1 df2 F p η²p [90% CI of η²p]
## ───────────────────────────────────────────────────────────────────────────────
## Tracing_type high 1 75 11.164 .001 ** .130 [.034, .253]
## Tracing_type low 1 75 0.297 .588 .004 [.000, .058]
## Prior_knowledge high 1 75 0.073 .787 .001 [.000, .038]
## Prior_knowledge low 1 75 0.073 .787 .001 [.000, .038]
## ───────────────────────────────────────────────────────────────────────────────
## Note. Simple effects of repeated measures with 3 or more levels
## are different from the results obtained with SPSS MANOVA syntax.
##
## Estimated Marginal Means of "Tracing_type":
## ─────────────────────────────────────────────────────────────────
## "Tracing_type" "Spatial_ability" Mean [95% CI of Mean] S.E.
## ─────────────────────────────────────────────────────────────────
## no high 10.354 [ 8.587, 12.121] (0.887)
## yes high 14.562 [12.754, 16.371] (0.908)
## no low 11.735 [10.152, 13.317] (0.794)
## yes low 11.127 [ 9.553, 12.700] (0.790)
## ─────────────────────────────────────────────────────────────────
##
## Pairwise Comparisons of "Tracing_type":
## ────────────────────────────────────────────────────────────────────────────────────────
## Contrast "Spatial_ability" Estimate S.E. df t p Cohen’s d [95% CI of d]
## ────────────────────────────────────────────────────────────────────────────────────────
## yes - no high 4.209 (1.260) 75 3.341 .001 ** 1.130 [ 0.456, 1.804]
## yes - no low -0.608 (1.117) 75 -0.545 .588 -0.163 [-0.761, 0.434]
## ────────────────────────────────────────────────────────────────────────────────────────
## Pooled SD for computing Cohen’s d: 3.723
## No need to adjust p values.
##
## Disclaimer:
## By default, pooled SD is Root Mean Square Error (RMSE).
## There is much disagreement on how to compute Cohen’s d.
## You are completely responsible for setting `sd.pooled`.
## You might also use `effectsize::t_to_d()` to compute d.
bruceR::EMMEANS(m, effect = "Spatial_ability", by = "Tracing_type")
## ------ EMMEANS (effect = "Spatial_ability") ------
##
## Joint Tests of "Spatial_ability":
## ───────────────────────────────────────────────────────────────────────────
## Effect "Tracing_type" df1 df2 F p η²p [90% CI of η²p]
## ───────────────────────────────────────────────────────────────────────────
## Spatial_ability no 1 75 1.338 .251 .018 [.000, .095]
## Spatial_ability yes 1 75 7.996 .006 ** .096 [.017, .213]
## Prior_knowledge no 1 75 0.073 .787 .001 [.000, .038]
## Prior_knowledge yes 1 75 0.073 .787 .001 [.000, .038]
## ───────────────────────────────────────────────────────────────────────────
## Note. Simple effects of repeated measures with 3 or more levels
## are different from the results obtained with SPSS MANOVA syntax.
##
## Estimated Marginal Means of "Spatial_ability":
## ─────────────────────────────────────────────────────────────────
## "Spatial_ability" "Tracing_type" Mean [95% CI of Mean] S.E.
## ─────────────────────────────────────────────────────────────────
## high no 10.354 [ 8.587, 12.121] (0.887)
## low no 11.735 [10.152, 13.317] (0.794)
## high yes 14.562 [12.754, 16.371] (0.908)
## low yes 11.127 [ 9.553, 12.700] (0.790)
## ─────────────────────────────────────────────────────────────────
##
## Pairwise Comparisons of "Spatial_ability":
## ───────────────────────────────────────────────────────────────────────────────────────
## Contrast "Tracing_type" Estimate S.E. df t p Cohen’s d [95% CI of d]
## ───────────────────────────────────────────────────────────────────────────────────────
## low - high no 1.381 (1.194) 75 1.157 .251 0.371 [-0.268, 1.010]
## low - high yes -3.436 (1.215) 75 -2.828 .006 ** -0.923 [-1.573, -0.273]
## ───────────────────────────────────────────────────────────────────────────────────────
## Pooled SD for computing Cohen’s d: 3.723
## No need to adjust p values.
##
## Disclaimer:
## By default, pooled SD is Root Mean Square Error (RMSE).
## There is much disagreement on how to compute Cohen’s d.
## You are completely responsible for setting `sd.pooled`.
## You might also use `effectsize::t_to_d()` to compute d.