I tried to nest idiomaticity(spatial/nonspatial usages) into test (pretest/posttest/finaltest), but the output didn’t show ‘DelayIdiom’, is it being treated as the reference category? I would like know how to fix this so that I can observe the learning effect for idiomatic usages on the delayed posttest as well. Thank you so much!
as.factor will set the order of the levels in alphabetical order, which in this case means that DelayIdiom will come first and therefore will be set as the reference level. You can set a different reference level by using the factor function and specifying the order of the levels with the levels argument, or you can use forcats::fct_relevel to set a new reference level without having to specify the order of all of the levels. Also, you can simplify recoding the value of TestByIdiom using either case_when or recode instead of nested ifelse statements. For example:
library(tidyverse)
# Recode values of TestByIdiom
dat2$TestByIdiom = recode(dat2$TestByIdiom,
"1"="PreIdiom",
"2"="PostSpatial",
"3"="Postidiom",
"4"="DelaySpatial",
.default="DelayIdiom")
# Convert TestByIdiom to a factor and set PreIdiom as the reference level
dat2$TestByIdiom = fct_relevel(dat2$TestByIdiom, "PreIdiom")
Regardless of which factor level is the reference level for any particular variable, you can use the hypothesis function to look at the modeled effect of various contrasts between different factor levels. For example, see here.