-
Notifications
You must be signed in to change notification settings - Fork 0
/
Study2.Rmd
executable file
·490 lines (342 loc) · 18.6 KB
/
Study2.Rmd
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
---
title: "Study2 Part 1 - Predicting emotion ratings"
author: '@H Cuve'
date: "16/07/2020"
output: html_document
---
load("D:/OneDrive - Nexus365/Face Morph Paper/Data/Study2_plots.RData"
# there is chaos and there there is my organisation method
```{r}
colnames(db_ASC_NT)
db_ASC_NT$Participant<- db_ASC_NT$ParticipantPrivateID
study2<- db_ASC_NT%>%
subset(Group == "NT")%>%
select(c(90,24,3:10,15,33,37, stim_id, Actor_ID))
saveRDS(study2, "study2.rds")
write_csv(study2, "study2.csv")
```
"remove some unnecessary duplicates
```{r eval=FALSE, include=FALSE}
rm(a_valence, a_valence1, acc_from_stimdiff, w,x,z,timebin_ADFES_avg_Anger, timebin_avg_Anger, timebin_avg_Disgust, timebin_avg_Fear, timebin_avg_Joy, timebin_avg_Sadness, timebin_avg_Surprise, timebin_JEFFE_avg_Anger, timebinout_avg_JEFFE, timebinout_avg_ADFES, timebin_shuff_Surprise, timebin_shuff_Sadness, timebin_shuff_JEFFE_Surprise, timebin_shuff_JEFFE_Joy, timebin_JEFFE_avg_Fear)
rm(timebin_random, timebin_random_ADFES, timebin_JEFFE_avg_Disgust, timebin_JEFFE_avg_Joy, timebin_JEFFE_avg_Surprise)
rm(timebin_JEFFE_avg_Sadness, timebin_random_JEFFE, timebin_shuff,timebin_shuff_Anger)
rm(timebin_shuff_ADFES, timebin_shuff_ADFES_Anger, timebin_shuff_Disgust, timebin_shuff_Fear, timebin_shuff_JEFFE, timebin_shuff_JEFFE_Anger, timebin_shuff_JEFFE_Anger)
rm(timebin_shuff_JEFFE_Disgust, timebin_shuff_JEFFE_Fear, timebin_shuff_JEFFE_Sadness, timebin_shuff_Joy)
rm(timestamp_ADFES, timestamp_ADFES_Anger, timestamp_ADFES_avg_Disgust, timestamp_ADFES_avg_Fear)
rm(whatsthisna, y, v1.1, v1, v1.2, testtemp, testpoly, test.data, test.data_avgface, test.data_avgface_96, test.data_avgface_ADFES, test.data_by_ADFES_avg_Anger)
rm(test.data1, test.data_by_ADFES_avg_Disgust, test.data_by_ADFES_avg_Fear, test.data_by_ADFES_avg_Surprise, testresults_ADFES_Fear, test.data_bySadness, test.data_byJEFFESurprise, test.data_byJEFFEJoy)
rm(test.data_avgface_jeffe)
rm(test_dcast, sum_cluster_sim, sum_cluster_sim_ADFES, sum_cluster_sim_final, sum_cluster_sim_JEFFE, sum_cluster_sim1)
rm(simularions, simulattion_vs_data, simulated_clusters_ADFES)
rm(simulattion_vs_data_ADFES, simulattion_vs_data_ADFES, simulattion_vs_data_JEFFE_test)
rm(simulattion_vs_data_JEFFE)
rm(simulated_clusters_current, simulated_clusters, simulated_clusters_ADFES_Anger, simulated_clusters_current, simulated_clusterstest_2, simulations)
rm(simulated_clusters_Anger, simulated_clusters_Disgust, simulated_clusters_Fear, simulated_clusters_JEFFE, simulated_clusterstest, simulated_clusters_JEFFE_Sadness)
rm(lmer_bin_random, lmer_bin_random_ADFES, lmer_bin_random_ADFES_Anger, lmer_bin_random_Disgust, lmer_bin_random_Disgust, lmer_bin_random_JEFFE_Anger, lmer_bin_random_summary)
rm(db_aus, db_of, db_of1, db_of4, db_of5, db_of5_new)
rm(db_of2, db_of5_coorrelations, db_of6, db_of6_new)
rm(db_of7_new_paper)
rm(db_of7_new_tomerge,db_of7_new_tomerge1, fuckup)
rm(timestamp_ADFES_avg_Anger, timestamp_ADFES_avg_Joy, timestamp_ADFES_avg_Sadness, timestamp_ADFES_avg_Surprise, timestamp_ADFES_Disgust, timestamp_ADFES_Fear, timestamp_ADFES_avg_Surprise, timestamp_ADFES_Surprise, timestamp_JEFFE_Surprise)
rm(timebinout, timebinout_avg, timestamp_ADFES_Joy, timestamp_JEFFE_Sadness, timestamp_avg_Disgust, timestamp_avg_Joy, timestamp_avg_Sadness, timestamp_JEFFE_Anger, timestamp_JEFFE_avg_Surprise)
rm(simulated_clusters_JEFFE_Anger, simulated_clusters_JEFFE_Disgust, simulated_clusters_JEFFE_Joy, simulated_clusters_JEFFE_Surprise, summarytest, summarytest_avg, summarytest_avg_ADFES, summarytest_avg_JEFFE)
rm(simulated_clusters_JEFFE_Fear, simulated_clusters_Joy, simulated_clusters_Sadness, simulated_clusters_Surprise)
rm(test.data_by_ADFES_avg_Joy, test.data_by_ADFES_avg_Sadness, test.data_by_avg_Anger, test.data_by_avg_Disgust, test.data_by_avg_Fear, test.data_by_avg_Fear, test.data_by_avg_Joy, test.data_by_avg_Sadness, test.data_by_avg_Surprise, testresults_avg_cluster_random, test.data_byADFESFear)
rm(testresults, testresults_ADFES, testresults_ADFES_Anger, testresults_ADFES_avg_Disgust, testresults_ADFES_avg_Joy)
```
Run proposed analyses
GLMMS
necessary packages
```{r}
library(afex)
library(lmerTest)
library(broom.mixed)
library(tidyverse)
library(emmeans)
library(sjmisc)
library(sjPlot)
library(sjstats)
library(psycho)
```
# Predicting emotion ratings
lmer model on valence
```{r}
unique(db_ASC_NT$Video)
unique(substr(db_ASC_NT$Video, 1,3))
db_ASC_NT$Actor_ID<- as.factor(substr(db_ASC_NT$Video, 1,3))
unique(db_ASC_NT$Actor_ID)
str(db_ASC_NT)
db_ASC_NT$ParticipantPrivateID<- as.factor(db_ASC_NT$ParticipantPrivateID)
db_ASC_NT$Emotion<- as.factor(db_ASC_NT$Emotion)
db_ASC_NT$DATASET<- as.factor(db_ASC_NT$DATASET)
db_ASC_NT$VideoType<- as.factor(db_ASC_NT$VideoType)
# paper_analyses<- list()
paper_analyses$lmer_NT_val<- lmer(AnswerRating_Valence ~ 1 + VideoType + DATASET + Emotion+
VideoType*Emotion*DATASET+(1| ParticipantPrivateID) + (1 | Video),
REML = FALSE,
data = subset(db_ASC_NT, db_ASC_NT$Group == "NT"))
paper_analyses$lmer_NT_val_analyze <- analyze (paper_analyses$lmer_NT_val, CI = 95, effsize_rules = "cohen1988")
# plot(paper_analyses$lmer_NT_val)
# qqnorm(resid(paper_analyses$lmer_NT_val))
# qqline(resid(paper_analyses$lmer_NT_val))
tab_model(paper_analyses$lmer_NT_val)
paper_analyses$lmer_NT_val_novt<- lmer(AnswerRating_Valence ~ 1 + DATASET + Emotion+
Emotion*DATASET+(1| ParticipantPrivateID) + (1 | Video),
REML = FALSE,
data = subset(db_ASC_NT, db_ASC_NT$Group == "NT"))
paper_analyses$lmer_NT_val1 <- lmer(AnswerRating_Valence ~ 1 + DATASET + Emotion+
VideoType*Emotion+
DATASET*Emotion+
# VideoType*Emotion*DATASET+ dropped insigifiant terms
(1 | ParticipantPrivateID) + (1 | Video),
REML = FALSE,
data = subset(db_ASC_NT, db_ASC_NT$Group == "NT"))
```
# control for Actor ID instead
```{r}
paper_analyses$lmer_NT_val1_actID<- lmer(AnswerRating_Valence ~ 1 + DATASET + Emotion+
VideoType*DATASET*Emotion+
# DATASET*Emotion+
# VideoType*Emotion*DATASET+ dropped insigifiant terms
(1 | ParticipantPrivateID) + (1 | Actor_ID),
REML = FALSE,
data = subset(db_ASC_NT, db_ASC_NT$Group == "NT"))
anova(paper_analyses$lmer_NT_val1_actID, paper_analyses$lmer_NT_val1)
summary(paper_analyses$lmer_NT_val)
anova(paper_analyses$lmer_NT_val)
step(paper_analyses$lmer_NT_val)
std_beta(paper_analyses$lmer_NT_val)
# check if logarithmic transformation improves residuals
paper_analyses$lmer_NT_val1_log<- lmer(log1p(AnswerRating_Valence+.1) ~ 1 + DATASET + Emotion+
VideoType*Emotion+
DATASET*Emotion+
# VideoType*Emotion*DATASET+ dropped insigifiant terms
(1 | ParticipantPrivateID) + (1 | Video),
REML = FALSE,
data = subset(db_ASC_NT, db_ASC_NT$Group == "NT"))
# the variance explained by actor ID is way less
# it doesn't
library(sjPlot)
library(sjmisc)
# sjmisc::
?plot_model
sjPlot::plot_model(paper_analyses$lmer_NT_val1, type = 'std')
summary(paper_analyses$lmer_NT_val)
anova(paper_analyses$lmer_NT_val)
plot(paper_analyses$lmer_NT_val1_log)
qqnorm(resid(paper_analyses$lmer_NT_val1_log))
qqline(resid(paper_analyses$lmer_NT_val1_log))
#
plot(paper_analyses$lmer_NT_val1)
qqnorm(resid(paper_analyses$lmer_NT_val1))
qqline(resid(paper_analyses$lmer_NT_val1))
summary(paper_analyses$lmer_NT_val1)
anova(paper_analyses$lmer_NT_val1)
emmeans(paper_analyses$lmer_NT_val1, pairwise ~ VideoType*Emotion, adjust = "none")
# Only happiness turns out significant, so the anova seems a bit anti conservative?
# EMotion main contrasts
emmeans(paper_analyses$lmer_NT_val1, pairwise ~ Emotion, adjust = "bonf")
# all pairs differ except anger disgust, fear sadness, and anger sadness
# DATASET
library(emmeans)
paper_analyses$lmer_NT_val_DS<- emmeans(paper_analyses$lmer_NT_val, pairwise~ DATASET, adjust = "none")
# <- eff_size(emmeans(paper_analyses$lmer_NT_val, pairwise ~ DATASET, adjust = "none"))
paper_analyses$lmer_NT_val_DS
paper_analyses$lmer_NT_val_em<- emmeans(paper_analyses$lmer_NT_val, pairwise ~ Emotion, adjust = "none")
paper_analyses$lmer_NT_val_em<- emmeans(paper_analyses$lmer_NT_val, pairwise~ VideoType*Emotion, adjust = "none")
summary(paper_analyses$lmer_NT_val_em)
eff_size(paper_analyses$lmer_NT_val_DS, edf = paper_analyses$lmer_NT_val@vcov_varpar)
# consistent with anova
paper_analyses$lmer_NT_val$analyze_report<- analyze(paper_analyses$lmer_NT_val)
library(sjstats)
std_beta(paper_analyses$lmer_NT_val, ci.lvl = 0.95)
library(MuMIn)
r.squaredGLMM(paper_analyses$lmer_NT_val)
r.squaredGLMM(paper_analyses$lmer_NT_val_novt) #videotype makes a very small contribution
# load poly effects
poly_ranef_df <- readRDS("~/Library/CloudStorage/[email protected]/My Drive/Papers2023/FaceDynamics/Face Morph Paper/Data/poly_ranef_df.rds")
```
```{r}
dplyr::write_rds(db_ASC_NT, "db_ASC_NT.rds")
```
LMER intensity on full data
```{r}
db_ASC_NT$VideoType<- as.factor(db_ASC_NT$VideoType)
paper_analyses$lmer_NT_int2<- lmer(AnswerRating_Intensity ~
VideoType + DATASET + Emotion+
# VideoType+Emotion+
# VideoType*Emotion*DATASET+
(1 | ParticipantPrivateID) + (1 | Video),
REML = FALSE,
data = subset(db_ASC_NT, db_ASC_NT$Group == "NT" & db_ASC_NT$outlier_intensity == FALSE))
anova(paper_analyses$lmer_NT_int2)
summary(paper_analyses$lmer_NT_int2)
step(paper_analyses$lmer_NT_int2)
paper_analyses$lmer_NT_int1<- lmer(AnswerRating_Intensity ~
DATASET + Emotion+
# VideoType+Emotion+
# VideoType*Emotion*DATASET+
(1 | ParticipantPrivateID) + (1 | Video),
REML = FALSE,
data = subset(db_ASC_NT, db_ASC_NT$Group == "NT"))
emmeans(paper_analyses$lmer_NT_int, ~VideoType)
emm_options(lmerTest.limit = 10176)
emmeans(paper_analyses$lmer_NT_int, ~DATASET )
summary(paper_analyses$lmer_NT_int)
drop1(paper_analyses$lmer_NT_int)
anova(paper_analyses$lmer_NT_int)
step(paper_analyses$lmer_NT_int)
# we find only models of main effects no interactions on intensity
# Model found:
# AnswerRating_Intensity ~ VideoType + DATASET + Emotion + (1 |
# ParticipantPrivateID) + (1 | Video) + DATASET:Emotion
plot(paper_analyses$lmer_NT_int)
qqnorm(resid(paper_analyses$lmer_NT_int))
qqline(resid(paper_analyses$lmer_NT_int)) # broadly fine
r.squaredGLMM(paper_analyses$lmer_NT_int)
r.squaredGLMM(paper_analyses$lmer_NT_int1) # small
paper_analyses$lmer_NT_int_analyze<- analyze(paper_analyses$lmer_NT_int,CI = 95, effsize_rules = "cohen1988")
paper_analyses$lmer_NT_int_analyze
```
lmer NATURALITY FUll
```{r}
db_ASC_NT$VideoType<- as.factor(db_ASC_NT$VideoType)
paper_analyses$lmer_NT_nat<- lmer(AnswerRating_Naturality ~
VideoType + DATASET + Emotion+
VideoType*Emotion+
VideoType*DATASET+
DATASET*Emotion+
# VideoType*Emotion*DATASET+
(1 | ParticipantPrivateID) + (1 | Video),
REML = FALSE,
data = subset(db_ASC_NT, db_ASC_NT$Group == "NT"))
anova(paper_analyses$lmer_NT_nat)
summary(paper_analyses$lmer_NT_nat)
paper_analyses$lmer_NT_nat1<- lmer(AnswerRating_Naturality ~
DATASET + Emotion+
DATASET*Emotion+
# VideoType*Emotion*DATASET+
(1 | ParticipantPrivateID) + (1 | Video),
REML = FALSE,
data = subset(db_ASC_NT, db_ASC_NT$Group == "NT"))
summary(paper_analyses$lmer_NT_nat)
emmeans(paper_analyses$lmer_NT_nat, pairwise~VideoType, adjust = "none")
drop1(paper_analyses$lmer_NT_nat)
anova(paper_analyses$lmer_NT_nat)
step(paper_analyses$lmer_NT_nat)
paper_analyses$lmer_NT_nat_analyze<- analyze(paper_analyses$lmer_NT_nat, CI = 95)
# consistent with anova, all main effects significant apart from Video Type and all interaction significant apart from three-way
paper_analyses$lmer_NT_nat_VT_DS <- emmeans(paper_analyses$lmer_NT_nat,pairwise~ VideoType*DATASET)
paper_analyses$lmer_NT_nat_VT_DS
# test the specific effects
# consistent with anovas, morphs are more natural for ADFES and less natural for JEFFE
# VideoType*EMotion
paper_analyses$lmer_NT_nat_VT_EM <- emmeans(paper_analyses$lmer_NT_nat,pairwise~ VideoType*Emotion, adjust = "none")
paper_analyses$lmer_NT_nat_VT_EM
# again emotion effects seem to be driven by happiness
# model found
# AnswerRating_Naturality ~ VideoType + DATASET + Emotion + (1 |
# ParticipantPrivateID) + (1 | Video) + VideoType:Emotion +
# VideoType:DATASET + DATASET:Emotion
plot(paper_analyses$lmer_NT_nat)
paper_analyses$lmer_NT_nat_DS_EM <- emmeans(paper_analyses$lmer_NT_nat,pairwise~ DATASET*Emotion, adjust = "none")
paper_analyses$lmer_NT_nat_DS_EM
EMqqnorm(resid(paper_analyses$lmer_NT_nat))
qqline(resid(paper_analyses$lmer_NT_nat)) fine
r.squaredGLMM(paper_analyses$lmer_NT_nat)
r.squaredGLMM(paper_analyses$lmer_NT_nat1)
```
Accuracy
```{r}
min(db_NT_anova$Recognacc)
max(db_NT_anova$Recognacc)
unique(db_NT_anova$Recognacc)
db_NT_anova$Recognacc
min(db_NT_anova$Recognacc_log)
max(db_NT_anova$Recognacc_log)
```
Full glmer on ACCURACY
```{r}
db_ASC_NT$VideoType<- as.factor(db_ASC_NT$VideoType)
unique(db_ASC_NT$Recognacc)
paper_analyses$glmer_NT_acc<- glmer(Recognacc ~
VideoType + DATASET + Emotion+
VideoType*Emotion+
VideoType*DATASET+
# DATASET*Emotion+
# VideoType*Emotion*DATASET+
(1 | ParticipantPrivateID) + (1 | Video),
# REML = FALSE,
family = 'binomial',
data = subset(db_ASC_NT, db_ASC_NT$Group == "NT"),
)
library(ggeffects)
# Note the use of the "all"-tag here, see help for details
ggpredict(paper_analyses$glmer_NT_acc, "VideoType") %>% plot()
emmeans::emmeans(paper_analyses$glmer_NT_acc, ~ VideoType, type = "response")
emmeans::emmeans(paper_analyses$glmer_NT_acc, ~DATASET* VideoType, type = "response")
```
```{r}
paper_analyses$glmer_NT_acc_noem<- glmer(Recognacc ~
VideoType + DATASET+
# VideoType* Emotion+
VideoType*DATASET+
# DATASET*Emotion+
# VideoType*Emotion*DATASET+
(1 | ParticipantPrivateID) + (1 | Video),
# REML = FALSE,
family = 'binomial',
data = subset(db_ASC_NT, db_ASC_NT$Group == "NT"),
)
paper_analyses$glmer_NT_acc1<- glmer(Recognacc ~
VideoType + DATASET + Emotion+
VideoType*Emotion+
VideoType*DATASET+
# DATASET*Emotion+
# VideoType*Emotion*DATASET+
(1 | ParticipantPrivateID) + (1 | Video),
# REML = FALSE,
family = 'binomial',
data = subset(db_NT_lmer, db_NT_lmer$ReactionTime_Recognition_outlier == "YES"),
)
summary(paper_analyses$glmer_NT_acc1)
anova(paper_analyses$glmer_NT_acc1)
anova(paper_analyses$glmer_NT_acc)
anova(paper_analyses$glmer_NT_acc,paper_analyses$glmer_NT_acc_noem)
acc_emm<- emmeans(paper_analyses$glmer_NT_acc1, pairwise~VideoType, adjust = "none")
?eff_size
emmeans(paper_analyses$glmer_NT_acc1, pairwise~DATASET, adjust = "none")
emmeans(paper_analyses$glmer_NT_acc1, pairwise~VideoType*DATASET, adjust = "none")
emmeans(paper_analyses$glmer_NT_acc1, pairwise~VideoType*DATASET, adjust = "none")
emmeans(paper_analyses$glmer_NT_acc1, pairwise~VideoType*Emotion, adjust = "none")
emmeans(paper_analyses$glmer_NT_acc1, pairwise~Emotion, adjust = "holm")
# <!-- p.adjust(0.0040, n = 2) -->
# eff_size(pairs(acc_emm),sigma(paper_analyses$glmer_NT_acc@dev), edf = 105 )
```
```{r}
summary(paper_analyses$glmer_NT_acc)
relgrad <- with(paper_analyses$glmer_NT_acc@optinfo$derivs,solve(Hessian,gradient))
max(abs(relgrad))
drop1(paper_analyses$glmer_NT_acc)
anova(paper_analyses$glmer_NT_acc)
step(paper_analyses$glmer_NT_acc)
# consistent with anova for the most part except no ME of videotype, all main effects significant apart from Video no interaction with video type either
paper_analyses$glmer_NT_acc_VT_DS <- emmeans(paper_analyses$glmer_NT_acc,pairwise~ VideoType*DATASET, adjust = "none")
paper_analyses$glmer_NT_acc_VT_DS # accuracy different in JEFFE
# test the specific effects
# consistent with anovas, morphs are more natural for ADFES and less natural for JEFFE
# VideoType*EMotion
paper_analyses$glmer_NT_acc_VT_EM <- emmeans(paper_analyses$glmer_NT_acc,pairwise~ VideoType*Emotion, adjust = "none")
paper_analyses$glmer_NT_acc_VT_EM
# No pairwise reaches significance
plot(paper_analyses$glmer_NT_acc)
qqnorm(resid(paper_analyses$glmer_NT_acc))
qqline(resid(paper_analyses$glmer_NT_acc))
r.squaredGLMM(paper_analyses$glmer_NT_acc)
r.squaredGLMM(paper_analyses$glmer_NT_acc1)
anova(paper_analyses$glmer_NT_acc, paper_analyses$glmer_NT_acc1)
paper_analyses$glmer_NT_acc_analyze<- analyze(paper_analyses$glmer_NT_acc)
paper_analyses$glmer_NT_acc
```
To do
- similarity and confusion analyses scripts