# !!!!EVAL = FALSE
##################### Read file names ##################################################################################
file_names <- dir(pattern = "\\.xls$")
## if above isn't good enough try the following:
# file_names <- list.files(wd)
# file_names <- sop_files[!file.info(sop_files)$isdir] # exclude directories
# file_names <- sop_files[grep(".xls", sop_files, fixed = TRUE)]
##################### Create folders with Condition names ###############################################################
# this part of script may be re-run if files from wd are updated
dir_names <- c("Unic_CTRL_Instr", "Unic_CTRL_Solo", "Unic_OGL_Instr", "Unic_OGL_Solo",
"Repetat_CTRL_Instr", "Repetat_CTRL_Solo", "Repetat_OGL_Instr", "Repetat_OGL_Solo")
for(dir in dir_names){
if(!dir.exists(file.path(wd, dir)))
dir.create(file.path(wd, dir), showWarnings = FALSE)
}
##################### Use file names to sort them to folders ############################################################
sort_files_to_dirs <- function(wd, pattern, dir) {
check_pattern <- outer(file_names, pattern, stringr::str_detect) # if all TRUE bye row then it has full pattern
index <- which(apply(check_pattern, 1, function(x) all(x==TRUE))) # get index of file_names where all are TRUE
sorted_files <- file_names[index] # get names of files from indexes
for(files in sorted_files) { # copy the files to corresponding folder
file.copy(from = file.path(wd, files), to = file.path(wd, dir))
}
}
sort_files_to_dirs(wd = wd, pattern = c("unic", "ecran", "instructor"), dir = "Unic_CTRL_Instr")
sort_files_to_dirs(wd = wd, pattern = c("unic", "ecran", "solo"), dir = "Unic_CTRL_Solo")
sort_files_to_dirs(wd = wd, pattern = c("unic", "oglinda", "instructor"), dir = "Unic_OGL_Instr")
sort_files_to_dirs(wd = wd, pattern = c("unic", "oglinda", "solo"), dir = "Unic_OGL_Solo")
wd <- "C:/Users/Mihai/Desktop/EEG_O.4c_1/O.4c - Poster/Date Pilot"
setwd(wd)
The working directory was changed to C:/Users/Mihai/Desktop/EEG_O.4c_1/O.4c - Poster/Date Pilot inside a notebook chunk. The working directory will be reset when the chunk is finished running. Use the knitr root.dir option in the setup chunk to change the working directory for notebook chunks.
folders <- list.files(wd)
folders <- folders[file.info(folders)$isdir] # luam doar folderele
datasetnames <- NULL
for (i in 1:length(folders)) {
datasetname <- folders[i]
datasetnames <- c(datasetnames, datasetname)
current_dir <- setwd(file.path(wd, folders[i]))
print(paste0("current_dir: ", current_dir))
paths <- dir(pattern = "\\.xls$")
names(paths) <- basename(paths)
assign( paste(datasetname), plyr::ldply(paths, rio::import) )
}
[1] "current_dir: C:/Users/Mihai/Desktop/EEG_O.4c_1/O.4c - Poster/Date Pilot"
[1] "current_dir: C:/Users/Mihai/Desktop/EEG_O.4c_1/O.4c - Poster/Date Pilot/Pilot_Unic_CTRL_Instr"
[1] "current_dir: C:/Users/Mihai/Desktop/EEG_O.4c_1/O.4c - Poster/Date Pilot/Pilot_Unic_CTRL_Solo"
[1] "current_dir: C:/Users/Mihai/Desktop/EEG_O.4c_1/O.4c - Poster/Date Pilot/Pilot_Unic_OGL_Instr"
setwd(wd)
## Function for Pilot Data processing
process_pilot_data <- function(df){
df_modif <-
df %>%
mutate(MarkerStimuli = case_when(`Stimuli order` < 36 ~ 11, # Pilot data was correcte due to stimulus ordering problems
`Stimuli order` >=36 & `Stimuli order` <= 70 ~ 21,
`Stimuli order` > 70 ~ 31,
TRUE ~ as.numeric(NA))) %>%
mutate(`Stimulus type` = case_when(MarkerStimuli %in% c(11, 12) ~ "negativ", # Left the old coding also altough we have only 11,21,31
MarkerStimuli %in% c(21, 22) ~ "neutru",
MarkerStimuli %in% c(31, 32) ~ "pozitiv",
TRUE ~ as.character(NA))) %>%
filter(`Stimulus type` != "pozitiv") # exclude positive stimuly because only 1 subject has them
df <- deparse(substitute(df))
assign(df, df_modif, envir = globalenv())
}
## Process Pilot Data
process_pilot_data(Pilot_Unic_CTRL_Instr)
process_pilot_data(Pilot_Unic_CTRL_Solo)
process_pilot_data(Pilot_Unic_OGL_Instr)
process_pilot_data(Pilot_Unic_OGL_Solo)
## Now we work only with Pilot Data
Unic_CTRL_Instr <- Pilot_Unic_CTRL_Instr
Unic_CTRL_Solo <- Pilot_Unic_CTRL_Solo
Unic_OGL_Instr <- Pilot_Unic_OGL_Instr
Unic_OGL_Solo <- Pilot_Unic_OGL_Solo
#################################### Data Cleaning #####################################################################
# Check if ids have > 1 row of data (empty .xls have only 1 row)
# Careful! This function modfies the datasets in the global envinronment
delete_empty_id <- function(df){
list_empty_id <-
df %>%
dplyr::group_by(.id) %>%
dplyr::summarise(row_count = n()) %>%
dplyr::rename("empty_id" = .id) %>%
mutate(delete_id = if_else(row_count < 3, TRUE, FALSE)) %>%
filter(delete_id == TRUE)
df_modif <-
df %>%
filter(!.id %in% list_empty_id$empty_id)
if(!identical(df, df_modif)){
df <- deparse(substitute(df))
cat("Deleting from ", print(as.name(df))); print(list_empty_id) # print out which ids are deleted from which dataset
assign(df, df_modif, envir = globalenv()) # assign modified df to original dataset from Global
}else cat("No empty datasets. Nothing to delete")
}
# Apply function to all datasets (tricky to do in for loop because of super assignment)
delete_empty_id(Unic_CTRL_Instr)
No empty datasets. Nothing to delete
delete_empty_id(Unic_CTRL_Solo)
No empty datasets. Nothing to delete
delete_empty_id(Unic_OGL_Instr)
No empty datasets. Nothing to delete
delete_empty_id(Unic_OGL_Solo)
No empty datasets. Nothing to delete
# !!!!EVAL = FALSE
############################### Exclude Outliers based on RT (by subject and stimulus type) #######################################
## DONT RUN (unless it is needed) ----> eval=FALSE
# Exclude RT outliers (=- 2SD) - instead of simple filter, makeing them NA is better for paired comparison
remove_outliers <- function(df) {
df_modif <-
df %>%
dplyr::group_by(.id, `Stimulus type`) %>% # we could have done before: dplyr::rename("Stim_type" = `Stimulus type`)
mutate(VAS_Resp = if_else(abs(VAS_RT - mean(VAS_RT, na.rm=TRUE)) > 2*sd(VAS_RT, na.rm=TRUE), as.numeric(NA), VAS_Resp))
if(!identical(df, df_modif)){
df <- deparse(substitute(df))
cat("Deleting outliers from ", print(as.name(df))); # print out datasets which have been modified
assign(df, df_modif, envir = globalenv()) # assign modified df to original dataset from Global
}else cat("No outlier")
}
remove_outliers(Unic_CTRL_Instr)
remove_outliers(Unic_CTRL_Solo)
remove_outliers(Unic_OGL_Instr)
remove_outliers(Unic_OGL_Solo)
unic_df_obj <- mget(c("Unic_CTRL_Instr", "Unic_CTRL_Solo", "Unic_OGL_Instr", "Unic_OGL_Solo"))
unic_df_obj <-lapply(unic_df_obj, colnames)
outer(unic_df_obj, unic_df_obj, Vectorize(identical)) # if all are TRUE, all df have same columns
Unic_CTRL_Instr Unic_CTRL_Solo Unic_OGL_Instr Unic_OGL_Solo
Unic_CTRL_Instr TRUE TRUE FALSE FALSE
Unic_CTRL_Solo TRUE TRUE FALSE FALSE
Unic_OGL_Instr FALSE FALSE TRUE TRUE
Unic_OGL_Solo FALSE FALSE TRUE TRUE
##########################################################################################################################
#################################### Analyses - UNICE ####################################################################
## Descriptives by condition dataset
descriptive_func <- function(df, Stim_type, By_ID = FALSE){
df_name <- deparse(substitute(df))
suppressWarnings({ # if all NAs in VAS_Resp, NaNs and Infs will be produced
df_modif <-
df %>%
dplyr::rename("ID" = .id) %>%
select_all(~gsub("\\s+|\\.", "_", .)) %>% # replaces blancks with "_" in colnames
filter(Stimulus_type == Stim_type) # filter by stimulus type
if(isTRUE(By_ID)){ # if true group by id, if not return descriptives for all ids
by_id_text <- " by subject"
df_modif %>%
dplyr::group_by(ID) %>%
tidystats::describe_data(VAS_Resp, VAS_RT, na.rm = TRUE) %>%
knitr::kable(caption = paste(as.name(df_name), " ", Stim_type, by_id_text), format = "pandoc", digits = 2)
}else{
by_id_text <- " all subjects"
df_modif %>%
ungroup() %>%
tidystats::describe_data(VAS_Resp, VAS_RT, na.rm = TRUE) %>%
knitr::kable(caption = paste(as.name(df_name), " ", Stim_type, by_id_text), format = "pandoc", digits = 2)
}
})
}
descriptive_func(df = Unic_CTRL_Instr, Stim_type = "negativ", By_ID = FALSE) # Negative - General
var | missing | n | M | SD | SE | min | max | range | median | mode | skew | kurtosis |
---|---|---|---|---|---|---|---|---|---|---|---|---|
VAS_Resp | 0 | 105 | 44.70 | 27.45 | 2.68 | 0.0 | 100.00 | 100.00 | 41.42 | 0.00 | 0.00 | 1.94 |
VAS_RT | 0 | 105 | 1.88 | 0.93 | 0.09 | 0.2 | 5.45 | 5.25 | 1.72 | 2.02 | 1.02 | 4.38 |
descriptive_func(df = Unic_CTRL_Solo, Stim_type = "negativ", By_ID = FALSE)
var | missing | n | M | SD | SE | min | max | range | median | mode | skew | kurtosis |
---|---|---|---|---|---|---|---|---|---|---|---|---|
VAS_Resp | 0 | 105 | 46.53 | 27.64 | 2.70 | 0.00 | 100.00 | 100.00 | 47.08 | 0.00 | 0.10 | 2.01 |
VAS_RT | 0 | 105 | 3.16 | 1.68 | 0.16 | 0.35 | 9.87 | 9.53 | 2.87 | 2.08 | 1.19 | 4.93 |
descriptive_func(df = Unic_OGL_Instr, Stim_type = "negativ", By_ID = FALSE)
var | missing | n | M | SD | SE | min | max | range | median | mode | skew | kurtosis |
---|---|---|---|---|---|---|---|---|---|---|---|---|
VAS_Resp | 0 | 105 | 48.10 | 33.12 | 3.23 | 0.00 | 100.00 | 100.00 | 45.99 | 0.00 | 0.00 | 1.67 |
VAS_RT | 0 | 105 | 2.73 | 1.47 | 0.14 | 0.61 | 7.92 | 7.31 | 2.35 | 2.23 | 0.97 | 3.53 |
descriptive_func(df = Unic_OGL_Solo, Stim_type = "negativ", By_ID = FALSE)
var | missing | n | M | SD | SE | min | max | range | median | mode | skew | kurtosis |
---|---|---|---|---|---|---|---|---|---|---|---|---|
VAS_Resp | 0 | 105 | 47.07 | 34.73 | 3.39 | 0.00 | 100.00 | 100.00 | 44.89 | 0.00 | 0.09 | 1.55 |
VAS_RT | 0 | 105 | 2.80 | 1.85 | 0.18 | 0.33 | 13.47 | 13.14 | 2.53 | 3.43 | 2.24 | 12.42 |
descriptive_func(df = Unic_CTRL_Instr, Stim_type = "negativ", By_ID = TRUE) # Negative - by id
var | ID | missing | n | M | SD | SE | min | max | range | median | mode | skew | kurtosis |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
VAS_Resp | Corect_EEGscalpID02o4c2ecraninst.xls | 0 | 35 | 34.70 | 21.25 | 3.59 | 0.00 | 72.26 | 72.26 | 38.14 | 0.00 | -0.14 | 1.97 |
VAS_Resp | Corect_EEGscalpID03bcontcuinstr.xls | 0 | 35 | 42.73 | 30.37 | 5.13 | 0.00 | 90.88 | 90.88 | 35.40 | 0.00 | 0.01 | 1.71 |
VAS_Resp | Corect_EEGscalpID05o4cBu2instr5ecraninst.xls | 0 | 35 | 56.66 | 26.03 | 4.40 | 10.58 | 100.00 | 89.42 | 64.42 | 66.79 | -0.27 | 1.83 |
VAS_RT | Corect_EEGscalpID02o4c2ecraninst.xls | 0 | 35 | 1.64 | 0.64 | 0.11 | 0.57 | 3.72 | 3.15 | 1.52 | 2.02 | 0.93 | 4.48 |
VAS_RT | Corect_EEGscalpID03bcontcuinstr.xls | 0 | 35 | 2.17 | 1.15 | 0.19 | 0.20 | 5.45 | 5.25 | 2.10 | 1.43 | 0.42 | 3.43 |
VAS_RT | Corect_EEGscalpID05o4cBu2instr5ecraninst.xls | 0 | 35 | 1.84 | 0.87 | 0.15 | 0.80 | 4.09 | 3.29 | 1.60 | 1.48 | 1.32 | 3.89 |
descriptive_func(df = Unic_CTRL_Solo, Stim_type = "negativ", By_ID = TRUE)
var | ID | missing | n | M | SD | SE | min | max | range | median | mode | skew | kurtosis |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
VAS_Resp | Corect_EEGscalpID02o4c2ecransolo.xls | 0 | 35 | 36.93 | 19.37 | 3.27 | 7.30 | 72.99 | 65.69 | 34.12 | 18.98 | 0.13 | 1.83 |
VAS_Resp | Corect_EEGscalpID03contsolo.xls | 0 | 35 | 46.90 | 32.63 | 5.52 | 0.00 | 100.00 | 100.00 | 43.25 | 0.00 | 0.01 | 1.77 |
VAS_Resp | Corect_EEGscalpID05o4Busolo5ecransolo.xls | 0 | 35 | 55.75 | 26.72 | 4.52 | 6.93 | 97.26 | 90.33 | 56.57 | 61.86 | -0.26 | 1.98 |
VAS_RT | Corect_EEGscalpID02o4c2ecransolo.xls | 0 | 35 | 3.27 | 1.47 | 0.25 | 1.63 | 7.34 | 5.71 | 2.70 | 2.08 | 0.98 | 3.31 |
VAS_RT | Corect_EEGscalpID03contsolo.xls | 0 | 35 | 3.50 | 2.16 | 0.36 | 0.35 | 9.87 | 9.53 | 3.08 | 6.18 | 0.90 | 3.85 |
VAS_RT | Corect_EEGscalpID05o4Busolo5ecransolo.xls | 0 | 35 | 2.71 | 1.23 | 0.21 | 1.07 | 6.22 | 5.15 | 2.58 | 1.63 | 1.07 | 3.99 |
descriptive_func(df = Unic_OGL_Instr, Stim_type = "negativ", By_ID = TRUE)
var | ID | missing | n | M | SD | SE | min | max | range | median | mode | skew | kurtosis |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
VAS_Resp | Corect_EEGscalpID02ucuinstr.xls | 0 | 35 | 45.81 | 35.23 | 5.95 | 0.00 | 97.08 | 97.08 | 46.72 | 0.00 | 0.00 | 1.55 |
VAS_Resp | Corect_EEGscalpID03u2instr.xls | 0 | 35 | 32.22 | 26.13 | 4.42 | 0.00 | 84.85 | 84.85 | 29.93 | 0.00 | 0.38 | 2.12 |
VAS_Resp | Corect_EEGscalpID05o45oglindainst.xls | 0 | 35 | 66.26 | 28.75 | 4.86 | 7.85 | 100.00 | 92.15 | 79.01 | 100.00 | -0.56 | 1.97 |
VAS_RT | Corect_EEGscalpID02ucuinstr.xls | 0 | 35 | 1.63 | 0.51 | 0.09 | 0.61 | 2.46 | 1.85 | 1.63 | 2.23 | -0.29 | 2.44 |
VAS_RT | Corect_EEGscalpID03u2instr.xls | 0 | 35 | 4.07 | 1.44 | 0.24 | 1.43 | 7.92 | 6.49 | 4.12 | 5.23 | 0.21 | 3.23 |
VAS_RT | Corect_EEGscalpID05o45oglindainst.xls | 0 | 35 | 2.48 | 1.06 | 0.18 | 0.93 | 5.28 | 4.35 | 2.45 | 2.88 | 0.81 | 3.38 |
descriptive_func(df = Unic_OGL_Solo, Stim_type = "negativ", By_ID = TRUE)
var | ID | missing | n | M | SD | SE | min | max | range | median | mode | skew | kurtosis |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
VAS_Resp | Corect_EEGscalpID02ufara.xls | 0 | 35 | 45.94 | 37.43 | 6.33 | 0.00 | 100.00 | 100.00 | 38.14 | 0.00 | 0.17 | 1.42 |
VAS_Resp | Corect_EEGscalpID03u1fara.xls | 0 | 35 | 27.98 | 26.17 | 4.42 | 0.00 | 85.04 | 85.04 | 20.26 | 0.00 | 0.66 | 2.34 |
VAS_Resp | Corect_EEGscalpID05o4c5oglindasolo.xls | 0 | 35 | 67.30 | 28.38 | 4.80 | 0.36 | 100.00 | 99.64 | 77.19 | 100.00 | -0.66 | 2.24 |
VAS_RT | Corect_EEGscalpID02ufara.xls | 0 | 35 | 2.78 | 1.51 | 0.25 | 0.38 | 7.27 | 6.89 | 2.43 | 3.43 | 1.15 | 4.39 |
VAS_RT | Corect_EEGscalpID03u1fara.xls | 0 | 35 | 3.13 | 1.78 | 0.30 | 0.33 | 7.19 | 6.86 | 2.90 | 3.55 | 0.36 | 2.57 |
VAS_RT | Corect_EEGscalpID05o4c5oglindasolo.xls | 0 | 35 | 2.50 | 2.19 | 0.37 | 0.60 | 13.47 | 12.88 | 2.01 | 2.53 | 3.74 | 19.42 |
descriptive_func(df = Unic_CTRL_Instr, Stim_type = "neutru", By_ID = FALSE) # Neutral - General
var | missing | n | M | SD | SE | min | max | range | median | mode | skew | kurtosis |
---|---|---|---|---|---|---|---|---|---|---|---|---|
VAS_Resp | 0 | 105 | 16.53 | 21.82 | 2.13 | 0.0 | 89.78 | 89.78 | 6.39 | 0.00 | 1.34 | 4.04 |
VAS_RT | 0 | 105 | 1.39 | 0.99 | 0.10 | 0.2 | 4.18 | 3.99 | 1.30 | 0.55 | 0.90 | 3.13 |
descriptive_func(df = Unic_CTRL_Solo, Stim_type = "neutru", By_ID = FALSE)
var | missing | n | M | SD | SE | min | max | range | median | mode | skew | kurtosis |
---|---|---|---|---|---|---|---|---|---|---|---|---|
VAS_Resp | 0 | 105 | 19.61 | 24.76 | 2.42 | 0.00 | 89.60 | 89.60 | 5.11 | 0.00 | 1.08 | 2.98 |
VAS_RT | 0 | 105 | 2.29 | 1.82 | 0.18 | 0.01 | 10.34 | 10.33 | 1.97 | 3.93 | 1.74 | 7.46 |
descriptive_func(df = Unic_OGL_Instr, Stim_type = "neutru", By_ID = FALSE)
var | missing | n | M | SD | SE | min | max | range | median | mode | skew | kurtosis |
---|---|---|---|---|---|---|---|---|---|---|---|---|
VAS_Resp | 0 | 105 | 27.43 | 31.58 | 3.08 | 0.00 | 97.08 | 97.08 | 12.59 | 0.00 | 0.85 | 2.33 |
VAS_RT | 0 | 105 | 2.62 | 1.78 | 0.17 | 0.48 | 11.89 | 11.41 | 2.25 | 1.58 | 1.74 | 8.58 |
descriptive_func(df = Unic_OGL_Solo, Stim_type = "neutru", By_ID = FALSE)
var | missing | n | M | SD | SE | min | max | range | median | mode | skew | kurtosis |
---|---|---|---|---|---|---|---|---|---|---|---|---|
VAS_Resp | 0 | 105 | 31.21 | 33.41 | 3.26 | 0.00 | 99.45 | 99.45 | 18.07 | 0.00 | 0.68 | 1.98 |
VAS_RT | 0 | 105 | 2.90 | 1.95 | 0.19 | 0.38 | 10.44 | 10.06 | 2.51 | 1.81 | 1.13 | 4.44 |
descriptive_func(df = Unic_CTRL_Instr, Stim_type = "neutru", By_ID = TRUE) # Neutral - by id
var | ID | missing | n | M | SD | SE | min | max | range | median | mode | skew | kurtosis |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
VAS_Resp | Corect_EEGscalpID02o4c2ecraninst.xls | 0 | 35 | 4.93 | 12.21 | 2.06 | 0.00 | 56.02 | 56.02 | 0.00 | 0.00 | 2.76 | 10.44 |
VAS_Resp | Corect_EEGscalpID03bcontcuinstr.xls | 0 | 35 | 20.08 | 25.55 | 4.32 | 0.00 | 89.78 | 89.78 | 0.00 | 0.00 | 0.96 | 2.95 |
VAS_Resp | Corect_EEGscalpID05o4cBu2instr5ecraninst.xls | 0 | 35 | 24.58 | 20.90 | 3.53 | 0.00 | 83.03 | 83.03 | 16.97 | 16.97 | 1.14 | 3.47 |
VAS_RT | Corect_EEGscalpID02o4c2ecraninst.xls | 0 | 35 | 0.78 | 0.49 | 0.08 | 0.35 | 2.65 | 2.30 | 0.58 | 0.55 | 2.02 | 7.25 |
VAS_RT | Corect_EEGscalpID03bcontcuinstr.xls | 0 | 35 | 1.44 | 1.17 | 0.20 | 0.20 | 3.93 | 3.74 | 1.43 | 2.02 | 0.65 | 2.21 |
VAS_RT | Corect_EEGscalpID05o4cBu2instr5ecraninst.xls | 0 | 35 | 1.97 | 0.80 | 0.13 | 0.86 | 4.18 | 3.32 | 1.73 | 4.18 | 1.18 | 3.91 |
descriptive_func(df = Unic_CTRL_Solo, Stim_type = "neutru", By_ID = TRUE)
var | ID | missing | n | M | SD | SE | min | max | range | median | mode | skew | kurtosis |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
VAS_Resp | Corect_EEGscalpID02o4c2ecransolo.xls | 0 | 35 | 5.57 | 14.64 | 2.47 | 0.00 | 61.31 | 61.31 | 0.00 | 0.00 | 2.95 | 10.71 |
VAS_Resp | Corect_EEGscalpID03contsolo.xls | 0 | 35 | 18.86 | 25.24 | 4.27 | 0.00 | 89.60 | 89.60 | 0.00 | 0.00 | 1.18 | 3.42 |
VAS_Resp | Corect_EEGscalpID05o4Busolo5ecransolo.xls | 0 | 35 | 34.40 | 24.39 | 4.12 | 1.09 | 84.49 | 83.39 | 27.74 | 20.44 | 0.40 | 1.96 |
VAS_RT | Corect_EEGscalpID02o4c2ecransolo.xls | 0 | 35 | 1.47 | 1.09 | 0.18 | 0.33 | 3.93 | 3.60 | 1.00 | 3.93 | 0.98 | 2.51 |
VAS_RT | Corect_EEGscalpID03contsolo.xls | 0 | 35 | 2.42 | 2.17 | 0.37 | 0.01 | 10.34 | 10.33 | 2.06 | 2.96 | 1.48 | 6.07 |
VAS_RT | Corect_EEGscalpID05o4Busolo5ecransolo.xls | 0 | 35 | 2.97 | 1.75 | 0.30 | 1.00 | 8.94 | 7.94 | 2.43 | 2.98 | 2.03 | 7.31 |
descriptive_func(df = Unic_OGL_Instr, Stim_type = "neutru", By_ID = TRUE)
var | ID | missing | n | M | SD | SE | min | max | range | median | mode | skew | kurtosis |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
VAS_Resp | Corect_EEGscalpID02ucuinstr.xls | 0 | 35 | 23.33 | 37.07 | 6.27 | 0.00 | 97.08 | 97.08 | 0.00 | 0.00 | 1.12 | 2.47 |
VAS_Resp | Corect_EEGscalpID03u2instr.xls | 0 | 35 | 27.91 | 29.69 | 5.02 | 0.00 | 85.04 | 85.04 | 14.05 | 0.00 | 0.60 | 1.85 |
VAS_Resp | Corect_EEGscalpID05o45oglindainst.xls | 0 | 35 | 31.06 | 27.65 | 4.67 | 0.00 | 94.53 | 94.53 | 27.01 | 0.00 | 0.83 | 2.71 |
VAS_RT | Corect_EEGscalpID02ucuinstr.xls | 0 | 35 | 1.26 | 0.62 | 0.10 | 0.48 | 2.60 | 2.12 | 1.03 | 1.58 | 0.56 | 1.92 |
VAS_RT | Corect_EEGscalpID03u2instr.xls | 0 | 35 | 3.61 | 1.43 | 0.24 | 1.00 | 6.17 | 5.17 | 3.60 | 4.53 | -0.11 | 1.95 |
VAS_RT | Corect_EEGscalpID05o45oglindainst.xls | 0 | 35 | 2.99 | 2.05 | 0.35 | 0.71 | 11.89 | 11.18 | 2.48 | 2.25 | 2.61 | 11.41 |
descriptive_func(df = Unic_OGL_Solo, Stim_type = "neutru", By_ID = TRUE)
var | ID | missing | n | M | SD | SE | min | max | range | median | mode | skew | kurtosis |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
VAS_Resp | Corect_EEGscalpID02ufara.xls | 0 | 35 | 24.57 | 36.92 | 6.24 | 0.00 | 99.45 | 99.45 | 0.55 | 0.00 | 1.24 | 2.81 |
VAS_Resp | Corect_EEGscalpID03u1fara.xls | 0 | 35 | 24.14 | 28.04 | 4.74 | 0.00 | 89.96 | 89.96 | 10.22 | 0.00 | 0.80 | 2.34 |
VAS_Resp | Corect_EEGscalpID05o4c5oglindasolo.xls | 0 | 35 | 44.91 | 31.21 | 5.28 | 0.36 | 93.07 | 92.70 | 49.82 | 60.40 | 0.00 | 1.52 |
VAS_RT | Corect_EEGscalpID02ufara.xls | 0 | 35 | 2.50 | 1.76 | 0.30 | 0.51 | 6.70 | 6.19 | 1.81 | 1.81 | 0.95 | 2.94 |
VAS_RT | Corect_EEGscalpID03u1fara.xls | 0 | 35 | 3.10 | 2.02 | 0.34 | 0.38 | 8.92 | 8.54 | 2.83 | 2.51 | 0.87 | 3.40 |
VAS_RT | Corect_EEGscalpID05o4c5oglindasolo.xls | 0 | 35 | 3.10 | 2.04 | 0.34 | 0.71 | 10.44 | 9.73 | 2.70 | 1.98 | 1.43 | 5.85 |
############################## Merge condition dataset ############################################################
# Must first rename .id to ID in oder to have .id for df names
ID_rename <- function(df){
if(".id" %in% colnames(df)) {
df_modif <-
df %>%
dplyr::rename("ID" = .id)
df <- deparse(substitute(df))
cat("Changed .id to ID for: ", as.name(df))
assign(df, df_modif, envir = globalenv())
}
}
ID_rename(Unic_CTRL_Instr)
Changed .id to ID for: Unic_CTRL_Instr
ID_rename(Unic_CTRL_Solo)
Changed .id to ID for: Unic_CTRL_Solo
ID_rename(Unic_OGL_Instr)
Changed .id to ID for: Unic_OGL_Instr
ID_rename(Unic_OGL_Solo)
Changed .id to ID for: Unic_OGL_Solo
# Merge into one df
list_df_merge <- list(Unic_CTRL_Instr, Unic_CTRL_Solo, Unic_OGL_Instr, Unic_OGL_Solo)
names(list_df_merge) <- c("Unic_CTRL_Instr", "Unic_CTRL_Solo", "Unic_OGL_Instr", "Unic_OGL_Solo")
Unic_merged <- plyr::ldply(list_df_merge, data.frame) # also works for this job bind_rows(list_df_merge, .id = "column_label")
############################## Analyses on Merged ################################################################
## Just a Test
# Unic_merged_spread_Neg <-
# Unic_merged %>%
# filter(!is.na(VAS_Resp)) %>% # some files had only NA on VAS_Resp and VAS_RT
# select(.id, ID, Subj_id,
# Stimuli.order, MarkerStimuli, Stimulus.type,
# VAS_Resp, VAS_RT) %>%
# filter(Stimulus.type == "negativ") %>% # dont forget to pick stymulus type
# spread(.id, VAS_Resp)
#
# t.test(Unic_merged_spread_Neg$Unic_CTRL_Instr, Unic_merged_spread_Neg$Unic_CTRL_Solo, na.rm = TRUE)
# t.test(Unic_merged_spread_Neg$Unic_OGL_Instr, Unic_merged_spread_Neg$Unic_OGL_Solo, na.rm = TRUE)
# t.test(Unic_merged_spread_Neg$Unic_OGL_Instr, Unic_merged_spread_Neg$Unic_CTRL_Instr, na.rm = TRUE)
# t.test(Unic_merged_spread_Neg$Unic_OGL_Solo, Unic_merged_spread_Neg$Unic_CTRL_Solo, na.rm = TRUE)
## Function prepair data for analyses
prepaire_merged_func <- function(Stim_type){
Unic_merged %>%
filter(!is.na(VAS_Resp)) %>% # some files had only NA on VAS_Resp and VAS_RT
select(.id, ID, Subj_id,
Stimuli.order, MarkerStimuli, Stimulus.type,
VAS_Resp, VAS_RT) %>%
dplyr::rename(Cond = .id) %>%
filter(Stimulus.type == Stim_type) %>% # dont forget to pick stymulus type
mutate(Cond = as.factor(Cond)) # tunr to factor for aov family functions
}
Unic_merged_Neg <- prepaire_merged_func("negativ")
Unic_merged_Neu <- prepaire_merged_func("neutru")
Unic_merged_Poz <- prepaire_merged_func("pozitiv")
## Anova and Post-Hoc - NEGATIV
# Stimulus type
cat("### Negativ")
# Normality
cat("#### Normality Test")
Unic_merged_Neg %>%
select(VAS_Resp) %>% # must select variables outside function
tadaatoolbox::tadaa_normtest(method = "shapiro") # , print = "markdown" for Notebook
# Levene Test (p>.05 = homogeneity of variances)
cat("#### Levene Test")
Unic_merged_Neg %>%
tadaatoolbox::tadaa_levene(data = ., VAS_Resp ~ Cond) # , print = "markdown" for Notebook
# Anova
cat("#### Anova")
Unic_merged_Neg %>%
#do(broom::glance(aov(.$VAS_Resp ~ .$Cond))) # regular anova do(broom::tidy(aov(.$VAS_Resp ~ .$Cond)))
tadaatoolbox::tadaa_aov(data = ., VAS_Resp ~ Cond, type = 1) # , print = "markdown" for Notebook
# Post-Hoc
cat("#### Post-Hoc Games Howell")
Unic_merged_Neg %>%
# Tukey for equal variance
tadaatoolbox::tadaa_pairwise_tukey(data = ., VAS_Resp, Cond) # , print = "markdown" for Notebook
# Games Howell does not assume equal variances
#tadaatoolbox::tadaa_pairwise_gh(data = ., VAS_Resp, Cond) # , print = "markdown" for Notebook
## Anova and Post-Hoc - NEUTRU
# Stimulus type
cat("### Neutru")
# Normality
cat("#### Normality Test")
Unic_merged_Neu %>%
select(VAS_Resp) %>% # must select variables outside function
tadaatoolbox::tadaa_normtest(method = "shapiro") # , print = "markdown" for Notebook
# Levene Test (p>.05 = homogeneity of variances)
cat("#### Levene Test")
Unic_merged_Neu %>%
tadaatoolbox::tadaa_levene(data = ., VAS_Resp ~ Cond) # , print = "markdown" for Notebook
# Anova
cat("#### Anova")
Unic_merged_Neu %>%
#do(broom::glance(aov(.$VAS_Resp ~ .$Cond))) # regular anova do(broom::tidy(aov(.$VAS_Resp ~ .$Cond)))
tadaatoolbox::tadaa_aov(data = ., VAS_Resp ~ Cond, type = 1) # , print = "markdown" for Notebook
# Post-Hoc
cat("#### Post-Hoc Games Howell")
Unic_merged_Neu %>%
# Tukey for equal variance
tadaatoolbox::tadaa_pairwise_tukey(data = ., VAS_Resp, Cond) # , print = "markdown" for Notebook
# Games Howell does not assume equal variances
#tadaatoolbox::tadaa_pairwise_gh(data = ., VAS_Resp, Cond) # , print = "markdown" for Notebook
# by dataset
ggplot(Unic_merged, aes(x = Stimulus.type, y = VAS_Resp)) +
geom_boxplot() +
stat_summary(fun.data = mean_se, colour = "darkred") +
xlab("") +
facet_wrap(~.id) +
ggpubr::stat_compare_means(method = "t.test",
label = "p.signif", # to avoid scientific notation of very small p-values
#paired = TRUE,
comparisons = list(c("negativ", "neutru")))
# by Stimulus type
ggplot(Unic_merged, aes(x = .id, y = VAS_Resp)) +
geom_boxplot() +
stat_summary(fun.data = mean_se, colour = "darkred") +
xlab("") +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
facet_wrap(~Stimulus.type) +
ggpubr::stat_compare_means(method = "t.test",
label = "p.format", # formated p-values
#paired = TRUE,
comparisons = list(c("Unic_CTRL_Instr", "Unic_CTRL_Solo"),
c("Unic_CTRL_Instr", "Unic_OGL_Instr"),
c("Unic_CTRL_Solo", "Unic_OGL_Instr"),
c("Unic_CTRL_Solo", "Unic_OGL_Solo"),
c("Unic_OGL_Instr", "Unic_OGL_Solo"),
c("Unic_CTRL_Instr", "Unic_OGL_Solo")))
# drop to CTRL vs OGL - by Stimulus type
Unic_merged %>%
mutate(.id = case_when(.id %in% c("Unic_CTRL_Instr", "Unic_CTRL_Solo") ~ "Unic_CTRL",
.id %in% c("Unic_OGL_Instr", "Unic_OGL_Solo") ~ "Unic_OGL",
TRUE ~ as.character(.id))) %>%
ggplot(aes(x = .id, y = VAS_Resp)) +
geom_boxplot() +
stat_summary(fun.data = mean_se, colour = "darkred") +
xlab("") +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
facet_wrap(~Stimulus.type) +
ggpubr::stat_compare_means(method = "t.test",
label = "p.format", # formated p-values
#paired = TRUE,
comparisons = list(c("Unic_CTRL", "Unic_OGL")))
# drop to Instr vs Solo - by Stimulus type
Unic_merged %>%
mutate(.id = case_when(.id %in% c("Unic_CTRL_Instr", "Unic_OGL_Instr") ~ "Unic_Instr",
.id %in% c("Unic_CTRL_Solo", "Unic_OGL_Solo") ~ "Unic_Solo",
TRUE ~ as.character(.id))) %>%
ggplot(aes(x = .id, y = VAS_Resp)) +
geom_boxplot() +
stat_summary(fun.data = mean_se, colour = "darkred") +
xlab("") +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
facet_wrap(~Stimulus.type) +
ggpubr::stat_compare_means(method = "t.test",
label = "p.format", # formated p-values
#paired = TRUE,
comparisons = list(c("Unic_Instr", "Unic_Solo")))
Unic_merged %>%
select(-c(3:10)) %>%
DT::datatable( # excel downloadable DT table
extensions = 'Buttons',
options = list(pageLength = 20,
scrollX='500px',
dom = 'Bfrtip',
buttons = c('excel', "csv")))