generated from NDCLab/template-dataset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmfe_c_object_stats_v1.R
237 lines (175 loc) · 11.7 KB
/
mfe_c_object_stats_v1.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# This script will run stats on mini_mfe data.
# Author: Kianoosh Hosseini at NDCLab @FIU (https://Kianoosh.info; https://NDClab.com)
# Last Update: 2024-08-15 (YYYY-MM-DD)
library(tidyverse)
library(dplyr)
library(stringr)
library(psycho)
library(car)
library(lme4)
library(ggplot2)
library(emmeans)
library(report)
library(sjPlot)
library(effsize)
#Working directory should be the Psychopy experiment directory.
proje_wd <- "/Users/kihossei/Library/CloudStorage/[email protected]/My Drive/My Digital Life/Professional/GitHub_Repos/mfe-c-object-dataset"
setwd(proje_wd)
processed_file_input <- paste(proje_wd, "derivatives", "psychopy", "stat_output", sep ="/", collapse = NULL) # input data directory
main_df <- read.csv(file = paste(processed_file_input, "processed_data_mfe_c_object_Proj_v1.csv", sep ="/", collapse = NULL), stringsAsFactors = FALSE, na.strings=c("", "NA"))
# Check the values in every column in main_df and remove the outliers based on +- 3SD.
# Write a function that removes the outliers from an array
remove_outliers <- function(x) {
mean_x <- mean(as.numeric(x), na.rm = TRUE)
sd_x <- sd(as.numeric(x), na.rm = TRUE)
for (xx in 1:length(x)){
if (!is.na(x[xx])){
if (x[xx] < (mean_x - 3*sd_x) | x[xx] > (mean_x + 3*sd_x)){
x[xx] <- NA
}
}
}
return(x)
}
# apply this outlier removing function to all the columns in the dataframe except for participant ID column.
new_main_df <- main_df
new_main_df[-c(1, ncol(new_main_df))] <- apply(main_df[-c(1, ncol(main_df))], 2, remove_outliers)
main_df <- new_main_df
# flanker task stats
mean(main_df$epepq15_scrdTotal_s1_r1_e1, na.rm = TRUE) #
sd(main_df$epepq15_scrdTotal_s1_r1_e1, na.rm = TRUE) #
median(main_df$epepq15_scrdTotal_s1_r1_e1, na.rm = TRUE) #
# Accuracy
mean(main_df$congAcc, na.rm = TRUE)
sd(main_df$congAcc, na.rm = TRUE)
# normality test
shapiro.test(main_df$congAcc) #
mean(main_df$post_error_acc, na.rm = TRUE) #
sd(main_df$post_error_acc, na.rm = TRUE) #
mean(main_df$post_error_rt, na.rm = TRUE) #
sd(main_df$post_error_rt, na.rm = TRUE) #
mean(main_df$incongAcc, na.rm = TRUE) #
sd(main_df$incongAcc, na.rm = TRUE) #
shapiro.test(main_df$incongAcc) #
median(main_df$incongAcc, na.rm = TRUE)
IQR(main_df$incongAcc, na.rm = TRUE)
median(main_df$congAcc, na.rm = TRUE)
IQR(main_df$congAcc, na.rm = TRUE)
# as they are not normal, we perform non-parametric Wilcoxon test instead of t-test
wil_acc <- wilcox.test(main_df$congAcc, main_df$incongAcc, alternative = 'greater', paired = TRUE, na.action = na.omit) # p-value =
Z_acc <- qnorm(wil_acc$p.value/2) # z-score
r_acc <- abs(Z_acc)/sqrt(32) # r (effect size) However, I reported Cohen's d in the paper. # formulas are from https://stats.stackexchange.com/questions/330129/how-to-get-the-z-score-in-wilcox-test-in-r#:~:text=How%20can%20i%20get%20the,for%20wilcox%20test%20in%20R%3F&text=The%20R%20code%20never%20stores,to%20the%20equivalent%20z%2Dscore.
cohen.d(main_df$congAcc, main_df$incongAcc, paired=TRUE)
# RT (unit in seconds)
mean(main_df$congCorr_meanRT, na.rm = TRUE)
sd(main_df$congCorr_meanRT, na.rm = TRUE) #
shapiro.test(main_df$congCorr_meanRT) #
median(main_df$congCorr_meanRT, na.rm = TRUE)
IQR(main_df$congCorr_meanRT, na.rm = TRUE)
mean(main_df$incongCorr_meanRT, na.rm = TRUE) #
sd(main_df$incongCorr_meanRT, na.rm = TRUE) #
shapiro.test(main_df$incongCorr_meanRT) #
median(main_df$incongCorr_meanRT, na.rm = TRUE)
IQR(main_df$incongCorr_meanRT, na.rm = TRUE)
mean(main_df$congErr_meanRT, na.rm = TRUE)
sd(main_df$congErr_meanRT, na.rm = TRUE)
shapiro.test(main_df$congErr_meanRT)
mean(main_df$incongErr_meanRT, na.rm = TRUE)
sd(main_df$incongErr_meanRT, na.rm = TRUE)
shapiro.test(main_df$incongErr_meanRT)
wil_RT <- wilcox.test(main_df$congCorr_meanRT, main_df$incongCorr_meanRT, alternative = 'less', paired = TRUE, na.action = na.omit)
Z_RT <- qnorm(wil_RT$p.value/2)
r_RT <- abs(Z_RT)/sqrt(32)
cohen.d(main_df$congCorr_meanRT, main_df$incongCorr_meanRT,paired=TRUE)
report(wilcox.test(main_df$congCorr_meanRT, main_df$incongCorr_meanRT, alternative = 'less', paired = TRUE, na.action = na.omit))
##################################################
# Surprise memory task in mfe_c_face task
mean(main_df$overall_hitRate, na.rm = TRUE)
sd(main_df$overall_hitRate, na.rm = TRUE)
mean(main_df$error_hitRate, na.rm = TRUE)
sd(main_df$error_hitRate, na.rm = TRUE)
shapiro.test(main_df$error_hitRate) #normal
mean(main_df$correct_hitRate, na.rm = TRUE)
sd(main_df$correct_hitRate, na.rm = TRUE)
shapiro.test(main_df$correct_hitRate) #normal
mean(main_df$post_error_hitRate, na.rm = TRUE)
sd(main_df$post_error_hitRate, na.rm = TRUE)
shapiro.test(main_df$post_error_hitRate) #
mean(main_df$post_correct_hitRate, na.rm = TRUE) #
sd(main_df$post_correct_hitRate, na.rm = TRUE) #
shapiro.test(main_df$post_correct_hitRate) #
t.test(main_df$correct_hitRate, main_df$error_hitRate, alternative = 'less', paired = TRUE, na.action = na.omit) # p-value = 0.9939
t.test(main_df$correct_hitRate, main_df$error_hitRate, paired = TRUE, na.action = na.omit) # p-value = 0.01223, correct is larger
t.test(main_df$post_correct_hitRate, main_df$post_error_hitRate, paired = TRUE, na.action = na.omit)
report(t.test(main_df$correct_hitRate, main_df$error_hitRate, alternative = 'less', paired = TRUE, na.action = na.omit))
cohen.d(main_df$correct_hitRate, main_df$error_hitRate, paired=TRUE)
cor.test(main_df$scaared_b_scrdSoc_s1_r1_e1, main_df$overall_hitRate, method = 'pearson', na.action = na.omit)
cor.test(main_df$scaared_b_scrdSoc_s1_r1_e1, main_df$flankEff_meanACC, method = 'pearson', na.action = na.omit)
cor.test(main_df$scaared_b_scrdSoc_s1_r1_e1, main_df$incongAcc, method = 'pearson', na.action = na.omit)
##################################################
# Hit Rate correlation with SCAARED social
lm_for_cor_fit_line <- lm(hitRate_error_minus_correct ~ scaared_b_scrdSoc_s1_r1_e1, main_df)
summary(lm_for_cor_fit_line)
cor.test(main_df$scaared_b_scrdSoc_s1_r1_e1, main_df$hitRate_error_minus_correct, method = 'pearson', na.action = na.omit)
ggplot(main_df, aes(x=scaared_b_scrdSoc_s1_r1_e1, y=hitRate_error_minus_correct)) + geom_point(size = 4) + geom_smooth(method="lm") +
labs(x = "SCAARED social anxiety score", y = "Error vs. Correct Hit rate") +
theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) + theme(axis.text = element_text(size = 15)) + theme(text = element_text(size = 18))
lm_for_cor_fit_line <- lm(error_hitRate ~ scaared_b_scrdSoc_s1_r1_e1, main_df)
summary(lm_for_cor_fit_line)
ggplot(main_df, aes(x=scaared_b_scrdSoc_s1_r1_e1, y=error_hitRate)) + geom_point(size = 4) + geom_smooth(method="lm") +
labs(x = "SCAARED social anxiety score", y = "error_hitRate") +
theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) + theme(axis.text = element_text(size = 15)) + theme(text = element_text(size = 18))
lm_for_cor_fit_line <- lm(correct_hitRate ~ scaared_b_scrdSoc_s1_r1_e1, main_df)
summary(lm_for_cor_fit_line)
ggplot(main_df, aes(x=scaared_b_scrdSoc_s1_r1_e1, y=correct_hitRate)) + geom_point(size = 4) + geom_smooth(method="lm") +
labs(x = "SCAARED social anxiety score", y = "correct_hitRate") +
theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) + theme(axis.text = element_text(size = 15)) + theme(text = element_text(size = 18))
lm_for_cor_fit_line <- lm(hitRate_error_minus_correct ~ scaared_b_scrdTotal_s1_r1_e1, main_df)
summary(lm_for_cor_fit_line)
cor.test(main_df$scaared_b_scrdTotal_s1_r1_e1, main_df$hitRate_error_minus_correct, method = 'pearson', na.action = na.omit)
ggplot(main_df, aes(x=scaared_b_scrdSoc_s1_r1_e1, y=hitRate_error_minus_correct)) + geom_point(size = 4) + geom_smooth(method="lm") +
labs(x = "SCAARED total anxiety score", y = "Error vs. Correct Hit rate") +
theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) + theme(axis.text = element_text(size = 15)) + theme(text = element_text(size = 18))
ggplot(main_df, aes(x=scaared_b_scrdTotal_s1_r1_e1, y=error_hitRate)) + geom_point(size = 4) + geom_smooth(method="lm") +
labs(x = "SCAARED total anxiety score", y = "error_hitRate") +
theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) + theme(axis.text = element_text(size = 15)) + theme(text = element_text(size = 18))
ggplot(main_df, aes(x=scaared_b_scrdTotal_s1_r1_e1, y=correct_hitRate)) + geom_point(size = 4) + geom_smooth(method="lm") +
labs(x = "SCAARED total anxiety score", y = "correct_hitRate") +
theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) + theme(axis.text = element_text(size = 15)) + theme(text = element_text(size = 18))
lm_for_cor_fit_line <- lm(hitRate_post_error_minus_correct ~ scaared_b_scrdSoc_s1_r1_e1, main_df)
summary(lm_for_cor_fit_line)
cor.test(main_df$scaared_b_scrdSoc_s1_r1_e1, main_df$hitRate_post_error_minus_correct, method = 'pearson', na.action = na.omit)
ggplot(main_df, aes(x=scaared_b_scrdSoc_s1_r1_e1, y=hitRate_post_error_minus_correct)) + geom_point(size = 4) + geom_smooth(method="lm") +
labs(x = "SCAARED social anxiety score", y = "Error vs. Correct Hit rate") +
theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) + theme(axis.text = element_text(size = 15)) + theme(text = element_text(size = 18))
# Hit Rate correlation with SCAARED GA
lm_for_cor_fit_line <- lm(hitRate_error_minus_correct ~ scaared_b_scrdGA_s1_r1_e1, main_df)
summary(lm_for_cor_fit_line)
cor.test(main_df$scaared_b_scrdGA_s1_r1_e1, main_df$hitRate_error_minus_correct, method = 'pearson', na.action = na.omit)
ggplot(main_df, aes(x=scaared_b_scrdGA_s1_r1_e1, y=hitRate_error_minus_correct)) + geom_point(size = 4) + geom_smooth(method="lm") +
labs(x = "SCAARED General anxiety score", y = "Error vs. Correct Hit rate") +
theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) + theme(axis.text = element_text(size = 15)) + theme(text = element_text(size = 18))
cor.test(main_df$scaared_b_scrdGA_s1_r1_e1, main_df$hitRate_post_error_minus_correct, method = 'pearson', na.action = na.omit)
current_pep_HR_reg <- lm(hitRate_error_minus_correct ~ epepq15_scrdTotal_s1_r1_e1*scaared_b_scrdSoc_s1_r1_e1 , data = main_df)
summary(current_pep_HR_reg)
# plot
plot_model(current_pep_HR_reg, type = "eff", terms = c("epepq15_scrdTotal_s1_r1_e1","scaared_b_scrdSoc_s1_r1_e1"))
current_pep_HR_reg <- lm(hitRate_error_minus_correct ~ epepq15_scrdTotal_s1_r1_e1*scaared_b_scrdGA_s1_r1_e1 , data = main_df)
summary(current_pep_HR_reg)
# plot
########################## POST
post_pep_HR_reg <- lm(hitRate_post_error_minus_correct ~ epepq15_scrdTotal_s1_r1_e1*scaared_b_scrdSoc_s1_r1_e1 , data = main_df)
summary(post_pep_HR_reg)
# plot
plot_model(post_pep_HR_reg, type = "eff", terms = c("epepq15_scrdTotal_s1_r1_e1","scaared_b_scrdSoc_s1_r1_e1"))
post_pep_HR_reg <- lm(hitRate_post_error_minus_correct ~ epepq15_scrdTotal_s1_r1_e1*scaared_b_scrdGA_s1_r1_e1 , data = main_df)
summary(post_pep_HR_reg)
# plot