Attaching package: 'car'
The following object is masked from 'package:dplyr':
recode
The following object is masked from 'package:purrr':
some
library(ggplot2)library(knitr)library(reshape2)
Attaching package: 'reshape2'
The following object is masked from 'package:tidyr':
smiths
library(dplyr)library(forcats)library(DHARMa)
This is DHARMa 0.4.7. For overview type '?DHARMa'. For recent changes, type news(package = 'DHARMa')
library(Hmisc)
Attaching package: 'Hmisc'
The following objects are masked from 'package:dplyr':
src, summarize
The following objects are masked from 'package:base':
format.pval, units
library(phia)library(lsmeans)
The 'lsmeans' package is now basically a front end for 'emmeans'.
Users are encouraged to switch the rest of the way.
See help('transition') for more information, including how to
convert old 'lsmeans' objects and scripts to work with 'emmeans'.
library(multcomp)
Loading required package: mvtnorm
Loading required package: survival
Loading required package: TH.data
Loading required package: MASS
Attaching package: 'MASS'
The following object is masked from 'package:dplyr':
select
Attaching package: 'TH.data'
The following object is masked from 'package:MASS':
geyser
library(plotly)
Attaching package: 'plotly'
The following object is masked from 'package:MASS':
select
The following object is masked from 'package:Hmisc':
subplot
The following object is masked from 'package:ggplot2':
last_plot
The following object is masked from 'package:stats':
filter
The following object is masked from 'package:graphics':
layout
Loading required package: usethis
Attaching package: 'devtools'
The following object is masked from 'package:emmeans':
test
library(brms)
Loading required package: Rcpp
Loading 'brms' package (version 2.22.0). Useful instructions
can be found by typing help('brms'). A more detailed introduction
to the package is available through vignette('brms_overview').
Attaching package: 'brms'
The following object is masked from 'package:survival':
kidney
The following object is masked from 'package:lme4':
ngrps
The following object is masked from 'package:stats':
ar
library(janitor)
Attaching package: 'janitor'
The following objects are masked from 'package:stats':
chisq.test, fisher.test
library(magrittr)
Attaching package: 'magrittr'
The following object is masked from 'package:purrr':
set_names
The following object is masked from 'package:tidyr':
extract
library(mascutils)
Attaching package: 'mascutils'
The following object is masked from 'package:car':
logit
The following object is masked from 'package:tidyr':
expand_grid
The following object is masked from 'package:base':
mode
library(ggthemes)
Warning: package 'ggthemes' was built under R version 4.2.3
library(afex)
************
Welcome to afex. For support visit: http://afex.singmann.science/
- Functions for ANOVAs: aov_car(), aov_ez(), and aov_4()
- Methods for calculating p-values with mixed(): 'S', 'KR', 'LRT', and 'PB'
- 'afex_aov' and 'mixed' objects can be passed to emmeans() for follow-up tests
- Get and set global package options with: afex_options()
- Set sum-to-zero contrasts globally: set_sum_contrasts()
- For example analyses see: browseVignettes("afex")
************
Attaching package: 'afex'
The following object is masked from 'package:lme4':
lmer
Rows: 9 Columns: 5
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (5): SubjectID, LoCog_LoMot, HiCog_LoMot, LoCog_HiMot, HiCog_HiMot
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
p3bAmps <-read_csv("Data/ERPs/p3bAmps.csv")
Rows: 9 Columns: 5
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (5): SubjectID, LoCog_LoMot, HiCog_LoMot, LoCog_HiMot, HiCog_HiMot
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
performance <- performance %>%mutate(across(c(ID, rew_cog, rew_mot, RoundNumber, BlockNumber), as.factor))# removing baselinesperformance <- performance %>%filter(RoundNumber !=0)# EEG CNV + P3b# transform into long format and duplicate rows to merge with datacolnames(cnvAmps)
# joining NASA and performance scores by round/conditionsdata <-left_join(performance, nasa, by =c("ID", "BlockNumber", "rew_cog", "rew_mot", "RoundNumber"))data <- data %>%mutate(reward_conditions =interaction(rew_cog, rew_mot, sep ="_"))# joining eeg data and dataset (NASA + Performance)data <-left_join(data, eeg, by =c("ID", "reward_conditions", "RoundNumber"))
Evaluating Questionnaires MSSQ, SSQ, NASA TLX
Motion Sickness Questionnaire MSSQ
# count number of methods of transport not used for MSSQ and SS questions (occurrences of 0)demographics <- demographics %>%mutate(MSSQ_not =rowSums(across(starts_with("MSSQ_"), ~ .x ==0)),SS_not =rowSums(across(starts_with("SS_"), ~ .x ==0)) )# transform MSSQ/SS to match scoring template (total remaining scored ones and subtract 9 to match scoring template)demographics <- demographics %>%mutate(MSSQ_scored =rowSums(across(.cols =starts_with("MSSQ_") &!any_of("MSSQ_not") ) ),SS_scored =rowSums(across(.cols =starts_with("SS_") &!any_of("SS_not") ) ) )demographics <- demographics %>%mutate(MSSQ_scored = MSSQ_scored - (9- MSSQ_not),SS_scored = SS_scored - (9- SS_not))# formula#MSSQ_child = total sickness score child * 9 / 9 * types not experienceddemographics <- demographics %>%mutate(MSSQ_child = MSSQ_scored *9/9* MSSQ_not,MSSQ_adult = SS_scored *9/9* SS_not,MSSQ_total = MSSQ_child + MSSQ_adult )
# highest motion sickness score was a 14 (bottom 60 Percentile)summary(demographics$MSSQ_total)
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.000 6.000 10.000 8.556 12.000 14.000
Rows: 4 Columns: 3002
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (2): SplitLabel, ConditionLabel
dbl (3000): MeanData_1, MeanData_2, MeanData_3, MeanData_4, MeanData_5, Mean...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 0 Columns: 1500
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (1500): -1500, -1498, -1496, -1494, -1492, -1490, -1488, -1486, -1484, -...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# Extract timepoints from colnames of the times filetimepoints <-as.numeric(colnames(cnv_times))# Reshape mean amplitudescnv_long <- cnv_means %>%pivot_longer(cols =starts_with("MeanData_"),names_to ="time_index", values_to ="mean") %>%mutate(time = timepoints[as.numeric(str_remove(time_index, "MeanData_"))]) %>%select(SplitLabel, ConditionLabel, time, mean)# Reshape SEMcnv_sem <- cnv_means %>%pivot_longer(cols =starts_with("SemData_"),names_to ="time_index", values_to ="sem") %>%mutate(time = timepoints[as.numeric(str_remove(time_index, "SemData_"))]) %>%select(SplitLabel, ConditionLabel, time, sem)# Mergecnv_long <-left_join(cnv_long, cnv_sem,by =c("SplitLabel", "ConditionLabel", "time"))# Plot CNVcnv_long <- cnv_long %>%mutate(SplitLabel =factor(SplitLabel, levels =c("loCog", "hiCog"), labels =c("Low Reward Stock Monitoring Task", "High Reward Stock Monitoring Task")),ConditionLabel =factor(ConditionLabel, levels =c("loMot", "hiMot"),labels =c("Low Reward", "High Reward")) )# if I understand it correctly we have the CNV peak at -100 (windows of 100ms: -200 to 0ms)cnv_means_plot <-ggplot(cnv_long, aes(x = time, y = mean, color = ConditionLabel)) +geom_rect(data =data.frame(xmin =-200, xmax =0, ymin =-Inf, ymax =Inf),aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax),inherit.aes =FALSE, fill ="red", alpha =0.1 ) +geom_line(size =1) +geom_ribbon(aes(ymin = mean - sem, ymax = mean + sem, fill = ConditionLabel),alpha =0.2, color =NA) +facet_wrap(~ SplitLabel, ncol =1) +labs(x ="Time in (ms)", y ="Grand Mean CNV Amplitudes in (µV)", color ="Walking Task Reward Levels", fill ="Walking Task Reward Levels") +theme_minimal()ggsave("Graphs/cnv_means_plot.jpg", cnv_means_plot, width =11, height =4, dpi =300)
Visualizing P3b grand average means
p3_means <-read_csv("Data/ERPs/p3MeansTable.csv")
Rows: 4 Columns: 3002
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (2): SplitLabel, ConditionLabel
dbl (3000): MeanData_1, MeanData_2, MeanData_3, MeanData_4, MeanData_5, Mean...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
p3_times <-read_csv("Data/ERPs/p3MeansTimes.csv")
Rows: 0 Columns: 1500
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (1500): -1500, -1498, -1496, -1494, -1492, -1490, -1488, -1486, -1484, -...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
timepoints <-as.numeric(colnames(p3_times))# Long format for plottingp3_long <- p3_means %>%pivot_longer(cols =starts_with("MeanData_"),names_to ="time_index", values_to ="mean") %>%mutate(time = timepoints[as.numeric(str_remove(time_index, "MeanData_"))]) %>%select(SplitLabel, ConditionLabel, time, mean)# Reshape Standard erorr of the meanp3_sem <- p3_means %>%pivot_longer(cols =starts_with("SemData_"),names_to ="time_index", values_to ="sem") %>%mutate(time = timepoints[as.numeric(str_remove(time_index, "SemData_"))]) %>%select(SplitLabel, ConditionLabel, time, sem)p3_long <-left_join(p3_long, p3_sem,by =c("SplitLabel", "ConditionLabel", "time"))# Change factors for order within graphsp3_long <- p3_long %>%mutate(SplitLabel =factor(SplitLabel, levels =c("loCog", "hiCog"), labels =c("Low Reward Stock Monitoring Task", "High Reward Stock Monitoring Task")),ConditionLabel =factor(ConditionLabel, levels =c("loMot", "hiMot"),labels =c("Low Reward", "High Reward")) )# P3b peak at 844 (windows of 100ms 744-944)p3_means_plot <-ggplot(p3_long, aes(x = time, y = mean, color = ConditionLabel)) +geom_rect(data =data.frame(xmin =744, xmax =944, ymin =-Inf, ymax =Inf), # typical P3b windowaes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax),inherit.aes =FALSE, fill ="red", alpha =0.1 ) +geom_line(size =1) +geom_ribbon(aes(ymin = mean - sem, ymax = mean + sem, fill = ConditionLabel),alpha =0.2, color =NA) +facet_wrap(~ SplitLabel, ncol =1) +labs(x ="Time in (ms)", y ="Grand Mean P3b Amplitudes in (µV)", color ="Walking Task Reward Levels", fill ="Walking Task Reward Levels") +theme_minimal()ggsave("Graphs/p3_means_plot.jpg", p3_means_plot, width =11, height =4, dpi =300)