Attaching package: 'rstatix'
The following object is masked from 'package:stats':
filter
library(ggpubr)library(here)
here() starts at /Users/rp3650/Library/CloudStorage/GoogleDrive-robpetrosino@gmail.com/My Drive/Academics/projects/morphology/morphological-decomposition/sub-projects/frequency-effects/frequency-effect_masked-priming
library(predictionInterval)library(lme4)
Loading required package: Matrix
Attaching package: 'Matrix'
The following objects are masked from 'package:tidyr':
expand, pack, unpack
library(car)
Loading required package: carData
Attaching package: 'car'
The following object is masked from 'package:dplyr':
recode
The following object is masked from 'package:purrr':
some
library(emmeans)
Welcome to emmeans.
Caution: You lose important information if you filter this package's results.
See '? untidy'
Data analysis
In [2]:
# load the raw data dataframeexp2_data_folder <-"data/experiment2"exp2_rawdata_filename <-"experiment_2_preprocessed_data.csv"## 02. check if the rawdata file exists. if not, download it from OSF.if (!file.exists(here(exp2_data_folder, exp2_rawdata_filename))) {osf_retrieve_file("k3gpc") |>osf_download(path =here(exp2_data_folder),conflicts ="overwrite") }## 03. read the data into R.exp2_rawdata <-here(exp2_data_folder, exp2_rawdata_filename) |>read.csv(na =c("", "NA")) %>%mutate(primeTime = primeDuration - maskDuration) %>%# calculating the actual SOArename(list ="Group_Nr")exp2_info <-list()exp2_info$intended_prime_duration <-33exp2_info$prime_dur_lb <-25exp2_info$prime_dur <-50exp2_info$prime_dur_ub <-60exp2_info$rt_lb <-200exp2_info$rt_ub <-1800exp2_info$freq_conditions <-c("high", "low", "non-word")exp2_info$n_recruited <- exp2_rawdata$Rec_Session_Id |>unique() |>length()exp2_rawdata.sub <- exp2_rawdata %>%filter(!is.na(TimeMeasure_Mean) &!is.na(primeDuration) &!is.na(responseError))exp2_subj.error <- exp2_rawdata.sub %>%group_by(Crowdsourcing_SubjId) %>%summarise(mean.error =mean(responseError))exp2_info$summary <-with(transform(exp2_rawdata.sub,RT_inrange =ifelse(RT >= exp2_info$rt_lb & RT <= exp2_info$rt_ub, 1, 0),Prime_inrange =ifelse((primeDuration - maskDuration) >= exp2_info$prime_dur_lb & (primeDuration - maskDuration) <= exp2_info$prime_dur_ub, 1, 0)), {data.frame(aggregate(Start_Time ~ Rec_Session_Id + Crowdsourcing_SubjId, data=exp2_rawdata.sub, unique),aggregate(End_Time_Local ~ Rec_Session_Id + Crowdsourcing_SubjId, data=exp2_rawdata.sub, unique),aggregate(cbind(list, SelectedGender, SelectedAge) ~ Rec_Session_Id + Crowdsourcing_SubjId, data=exp2_rawdata.sub, unique),aggregate(cbind(responseError, RT_inrange, Prime_inrange) ~ Rec_Session_Id + Crowdsourcing_SubjId, mean, data=exp2_rawdata.sub) )})exp2_info$summary <- exp2_info$summary[, -grep("Rec_Session_Id.|Crowdsourcing_SubjId.", colnames(exp2_info$summary))] # remove all extra aggregating columns (subj ID)exp2_info$summary$Duration <-interval(ymd_hms(exp2_info$summary$Start_Time), ymd_hms(exp2_info$summary$End_Time_Local)) |>lapply(function(interval_value) {interval_value/dminutes(1)}) |>unlist()
# RT outliers exp2_data_step3 <- exp2_data_step2 |>subset(RT >= exp2_info$rt_lb & RT <= exp2_info$rt_ub)exp2_step3_subj_remain <- exp2_data_step3$Rec_Session_Id |>unique() |>length()exp2_step3_trials_remain <-nrow(exp2_data_step3)# error trial removalexp2_data_step3b <- exp2_data_step3 |>subset(responseError ==0)exp2_step3b_subj_remain <- exp2_data_step3b$Rec_Session_Id |>unique() |>length()exp2_step3b_trials_remain <-nrow(exp2_data_step3b)# remove subjects with less than 7 trials in at least one condition*primetype combination (half of the total number of items per combination)rt_data_labels <-c("Rec_Session_Id", "condition_rec", "primetype_rec", "RT")exp2_subj_filter_2 <- exp2_data_step3b[, rt_data_labels] |>aggregate(RT ~ ., FUN = length, drop =FALSE) |>subset(RT <7, select = Rec_Session_Id) |>unique() |>unlist()### we also want to sure that all subjects have all conditions; in case some subject had all the trials for a given condition lost down the road, they will be removedexp2_subj_filter_conditions <- exp2_data_step3b %>%group_by(Rec_Session_Id) %>%distinct(condition_rec, primetype_rec) %>%tally() %>%filter(n !=6) %>%pull(Rec_Session_Id)exp2_data_final <- exp2_data_step3b |>subset(!(Rec_Session_Id %in% exp2_subj_filter_2) &!(Rec_Session_Id %in% exp2_subj_filter_conditions)) %>%mutate(condition_rec =as.factor(condition_rec), primetype_rec=as.factor(primetype_rec))exp2_final_subj_remain <- exp2_data_final$Rec_Session_Id |>unique() |>length()exp2_final_trials_remain <-nrow(exp2_data_final)
Results
In [6]:
# error rates averages### we also want to sure that all subjects have all conditions; in case some subject had all the trials for a given condition lost down the road, they will be removed. Crucially the trial calculations are made on the dataset *before* the trial error removal stepexp2_subj_filter_2_with.errors <- exp2_data_step3[, rt_data_labels] |>aggregate(RT ~ ., FUN = length, drop =FALSE) |>subset(RT <7, select = Rec_Session_Id) |>unique() |>unlist()# this step just makes sure that the same subjects will be removed from both datasetsexp2_subj_filter_2_with.errors <-union(exp2_subj_filter_2_with.errors, exp2_subj_filter_2)### just making sure that all subjects have all conditions; in case some subject had all the trials for a given condition lost down the road, they will be removedexp2_subj_filter_conditions_with.errors <- exp2_data_step3 %>%group_by(Rec_Session_Id) %>%distinct(condition_rec, primetype_rec) %>%tally() %>%filter(n !=6) %>%pull(Rec_Session_Id)exp2_data_final_with.errors <- exp2_data_step3 |>subset(!(Rec_Session_Id %in% exp2_subj_filter_2_with.errors) &!(Rec_Session_Id %in% exp2_subj_filter_conditions_with.errors)) exp2_error.rates <- exp2_data_final_with.errors %>%mutate(primetype_rec =factor(primetype_rec, levels=c("unrelated", "related")),condition_rec =factor(condition_rec, levels=c("high", "low", "non-word"))) %>%group_by(condition_rec, primetype_rec, Rec_Session_Id) %>%summarise(error.percent=mean(responseError)*100)
`summarise()` has grouped output by 'condition_rec', 'primetype_rec'. You can
override using the `.groups` argument.
Warning: There was 1 warning in `mutate()`.
ℹ In argument: `across(c(13), round, 2)`.
Caused by warning:
! The `...` argument of `across()` is deprecated as of dplyr 1.1.0.
Supply arguments directly to `.fns` through an anonymous function instead.
# Previously
across(a:b, mean, na.rm = TRUE)
# Now
across(a:b, \(x) mean(x, na.rm = TRUE))
Experiment 2. Summary of the word priming results based on the 2x3 GLMM model, with the same fixed and random effects as the 2x2 GLMM model, but including the non-word condition. Legend. MOP: magnitude of priming.