-
Notifications
You must be signed in to change notification settings - Fork 1
/
.Rhistory
512 lines (512 loc) · 24.2 KB
/
.Rhistory
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
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
key.list <- list(1:7)
faceKey <- make.keys(7,key.list)
# Load data and reverse code each variable individually
db <- read.csv("data/base_data/Face_Morph3_raw.csv", header=TRUE, stringsAsFactors = FALSE)
# Script for Face Morph 3 Variable Recoding and 3-way ANOVA
# 6.3.21 JMS
# Install packages and load libraries
library(psych); library(plyr)
# Create transform function to recode data
transform <- function(data, x) data[,x] <- revalue(factor(data[,x]), map, warn_missing=FALSE)
key.list <- list(1:7)
faceKey <- make.keys(7,key.list)
# Load data and reverse code each variable individually
db <- read.csv("data/base_data/Face_Morph3_raw.csv", header=TRUE, stringsAsFactors = FALSE)
View(db)
View(db)
View(db)
View(db)
library(psych); library(plyr)
# Create transform function to recode data
transform <- function(data, x) data[,x] <- revalue(factor(data[,x]), map, warn_missing=FALSE)
key.list <- list(1:7)
faceKey <- make.keys(7,key.list)
# Load data and reverse code each variable individually
d1a <- read.csv("data/base_data/Face_Morph1_raw.csv", header=TRUE, stringsAsFactors = FALSE)
View(d1a)
View(d1a)
d2a <- d1a[c(20,28:135)]
View(d2a)
View(d2a)
library(psych); library(plyr)
# Create transform function to recode data
transform <- function(data, x) data[,x] <- revalue(factor(data[,x]), map, warn_missing=FALSE)
key.list <- list(1:7)
faceKey <- make.keys(7,key.list)
# Load data and reverse code each variable individually
d3a <- read.csv("data/base_data/Face_Morph3_raw.csv", header=TRUE, stringsAsFactors = FALSE)
View(d3a)
View(d1a)
View(d1a)
d3a <- read.csv("data/base_data/Face_Morph3_raw.csv", header=TRUE, stringsAsFactors = FALSE)
d3b <- d3a[c(29,37:234)]
View(d3b)
View(d3b)
# Script for Face Morph 3 Variable Recoding and 3-way ANOVA
# 6.3.21 JMS
# Install packages and load libraries
library(psych); library(plyr)
# Create transform function to recode data
transform <- function(data, x) data[,x] <- revalue(factor(data[,x]), map, warn_missing=FALSE)
key.list <- list(1:7)
faceKey <- make.keys(7,key.list)
# Load data and reverse code each variable individually
d1 <- read.csv("data/base_data/Face_Morph3_raw.csv", header=TRUE, stringsAsFactors = FALSE)
d2 <- d1[c(29,37:234)]
map <- c('7'= '1', '6 - Moderately Negative'='2', '5 - Slightly Negative'='3','4 - Neutral'='4','3 - Slightly Positive'='5', '2 - Moderately Positive'='6', '1 - Very Positive'='7', '7'= '1', '6'='2', '5'='3','4'='4','3'='5', '2'='6', '1'='7')
for (i in 2:ncol(d2)) d2[i] <- as.numeric(as.character(transform(d2,i)))
View(d2)
View(d2)
d2 <- d2[3:nrow(d2),] # this clips off excess, including survey preview trials
View(d2)
View(d2)
View(d1)
View(d1)
View(d2)
View(d2)
# Script for Face Morph 3 Variable Recoding and 3-way ANOVA
# 6.3.21 JMS
# Install packages and load libraries
library(psych); library(plyr)
# Create transform function to recode data
transform <- function(data, x) data[,x] <- revalue(factor(data[,x]), map, warn_missing=FALSE)
key.list <- list(1:7)
faceKey <- make.keys(7,key.list)
# Load data and reverse code each variable individually
d1 <- read.csv("data/base_data/Face_Morph3_raw.csv", header=TRUE, stringsAsFactors = FALSE)
d2 <- d1[c(29,37:234)]
map <- c('7 - Very Negative'='1', '6 - Moderately Negative'='2', '5 - Slightly Negative'='3', '4 - Neutral'='4','3 - Slightly Positive'='5', '2 - Moderately Positive'='6', '1 - Very Positive'='7', '1 - Very Aroused'='7', '7 - Not At All Aroused'='1', '7'='1', '6'='2', '5'='3','4'='4','3'='5', '2'='6', '1'='7')
View(d2)
View(d2)
View(key.list)
View(key.list)
# Script for Face Morph 3 Variable Recoding and 3-way ANOVA
# 6.3.21 JMS
# Install packages and load libraries
library(psych); library(plyr)
# Create transform function to recode data
transform <- function(data, x) data[,x] <- revalue(factor(data[,x]), map, warn_missing=FALSE)
key.list <- list(1:7)
faceKey <- make.keys(7,key.list)
# Load data and reverse code each variable individually
d1 <- read.csv("data/base_data/Face_Morph3_raw.csv", header=TRUE, stringsAsFactors = FALSE)
d2 <- d1[c(29,37:234)]
map <- c('7 - Very Negative'='1', '6 - Moderately Negative'='2', '5 - Slightly Negative'='3', '4 - Neutral'='4','3 - Slightly Positive'='5', '2 - Moderately Positive'='6', '1 - Very Positive'='7', '7 - Not At All Aroused'='1', '6'='2', '5'='3','4'='4','3'='5', '2'='6', '1 - Very Aroused'='7')
View(d2)
View(d2)
# Create transform function to recode data
transform <- function(data, x) data[,x] <- revalue(factor(data[,x]), map, warn_missing=FALSE)
key.list <- list(1:7)
faceKey <- make.keys(7,key.list)
# Load data and reverse code each variable individually
d1 <- read.csv("data/base_data/Face_Morph3_raw.csv", header=TRUE, stringsAsFactors = FALSE)
d2 <- d1[c(29,37:234)]
map <- c('7 - Very Negative'='1', '6 - Moderately Negative'='2', '5 - Slightly Negative'='3', '4 - Neutral'='4','3 - Slightly Positive'='5', '2 - Moderately Positive'='6', '1 - Very Positive'='7', '7 - Not At All Aroused'='1', '6'='2', '5'='3','4'='4','3'='5', '2'='6', '1 - Very Aroused'='7')
for (i in 2:ncol(d2)) d2[i] <- as.numeric(as.character(transform(d2,i)))
View(d2)
View(d2)
View(d1)
View(d1)
d2 <- d2[3:nrow(d2),] # this clips off excess
View(d2)
View(d2)
subnum1 <- seq(1:nrow(d2))
d3 <- cbind(subnum1, d2)
View(d3)
View(d3)
subnum <- seq(1:nrow(d2))
d3 <- cbind(subnum, d2)
View(d3)
View(d3)
# Write to csv
write.csv(d3, 'data/base_data/Faces3_Numeric_Data_reverse.csv', row.names=FALSE)
# Load libraries and functions
library(reshape2); library(plyr); library(dplyr)
source('scr/SummarySE2.R')
# Load data
d1 <- read.csv('data/base_data/Faces3_Numeric_Data_reverse.csv', header=TRUE)
View(d1)
View(d1)
d2 <- melt(d1, id.vars = c('subnum', 'age'), value.name = 'rating')
d2 <- melt(d1, id.vars = c('subnum', 'age'), value.name = 'rating')
View(d3)
View(d3)
d3 <- d3 %>% rename(win_full_aro = Q21)
View(d3)
View(d3)
d3 <- d3 %>% rename(age = Q5, win_full_aro = Q21
d3 <- d3 %>% rename(age = Q5, win_full_aro = Q21)
# Script for Face Morph 3 Variable Recoding and 3-way ANOVA
# 6.3.21 JMS, adapted from 0_transform_data by KLS & SA
# Install packages and load libraries
library(psych); library(plyr)
# Create transform function to recode data
transform <- function(data, x) data[,x] <- revalue(factor(data[,x]), map, warn_missing=FALSE)
key.list <- list(1:7)
faceKey <- make.keys(7,key.list)
# Load data and reverse code each variable individually
d1 <- read.csv("data/base_data/Face_Morph3_raw.csv", header=TRUE, stringsAsFactors = FALSE)
d2 <- d1[c(29,37:234)]
map <- c('7 - Very Negative'='1', '6 - Moderately Negative'='2', '5 - Slightly Negative'='3', '4 - Neutral'='4','3 - Slightly Positive'='5', '2 - Moderately Positive'='6', '1 - Very Positive'='7', '7 - Not At All Aroused'='1', '6'='2', '5'='3','4'='4','3'='5', '2'='6', '1 - Very Aroused'='7')
for (i in 2:ncol(d2)) d2[i] <- as.numeric(as.character(transform(d2,i)))
d2 <- d2[3:nrow(d2),] # this clips off excess
# Add sub number
subnum <- seq(1:nrow(d2))
d3 <- cbind(subnum, d2)
# Rename columns
#rename all columns
d3 <- d3 %>% rename(age = Q5, win_full_aro = Q21)
View(d3)
View(d3)
# Script for Face Morph 3 Variable Recoding and 3-way ANOVA
# 6.3.21 JMS, adapted from 0_transform_data by KLS & SA
# Install packages and load libraries
library(psych); library(plyr)
# Create transform function to recode data
transform <- function(data, x) data[,x] <- revalue(factor(data[,x]), map, warn_missing=FALSE)
key.list <- list(1:7)
faceKey <- make.keys(7,key.list)
# Load data and reverse code each variable individually
d1 <- read.csv("data/base_data/Face_Morph3_raw.csv", header=TRUE, stringsAsFactors = FALSE)
d2 <- d1[c(29,37:234)]
map <- c('7 - Very Negative'='1', '6 - Moderately Negative'='2', '5 - Slightly Negative'='3', '4 - Neutral'='4','3 - Slightly Positive'='5', '2 - Moderately Positive'='6', '1 - Very Positive'='7', '7 - Not At All Aroused'='1', '6'='2', '5'='3','4'='4','3'='5', '2'='6', '1 - Very Aroused'='7')
for (i in 2:ncol(d2)) d2[i] <- as.numeric(as.character(transform(d2,i)))
d2 <- d2[3:nrow(d2),] # this clips off excess
# Add sub number
subnum <- seq(1:nrow(d2))
d3 <- cbind(subnum, d2)
# Rename columns
#rename all columns
d3 <- d3 %>% rename(age = Q5, win_full_aro = Q21, win_full_val = Q22, win_low_aro = Q26, win_low_val = Q27,
win_med_aro = Q31, win_med_val = Q32, att_1 = Q580, att_2 = Q581, lose_full_aro = Q36, lose_full_val = Q37,
lose_low_aro = Q41, lose_low_val = Q42, lose_med_aro = Q46, lose_med_val = Q47, att_3 = Q585, att_4 = Q586,
'04_a_full_aro' = Q50, '04a_full_aro' = Q51)
View(d3)
View(d3)
# Script for Face Morph 3 Variable Recoding and 3-way ANOVA
# 6.3.21 JMS, adapted from 0_transform_data by KLS & SA
# Install packages and load libraries
library(psych); library(plyr)
# Create transform function to recode data
transform <- function(data, x) data[,x] <- revalue(factor(data[,x]), map, warn_missing=FALSE)
key.list <- list(1:7)
faceKey <- make.keys(7,key.list)
# Load data and reverse code each variable individually
d1 <- read.csv("data/base_data/Face_Morph3_raw.csv", header=TRUE, stringsAsFactors = FALSE)
d2 <- d1[c(29,37:234)]
map <- c('7 - Very Negative'='1', '6 - Moderately Negative'='2', '5 - Slightly Negative'='3', '4 - Neutral'='4','3 - Slightly Positive'='5', '2 - Moderately Positive'='6', '1 - Very Positive'='7', '7 - Not At All Aroused'='1', '6'='2', '5'='3','4'='4','3'='5', '2'='6', '1 - Very Aroused'='7')
for (i in 2:ncol(d2)) d2[i] <- as.numeric(as.character(transform(d2,i)))
View(d2)
View(d2)
View(d2)
View(d2)
View(d1)
View(d1)
View(d1)
View(d1)
d1 <- read.csv("data/base_data/Face_Morph3_raw.csv", header=TRUE, stringsAsFactors = FALSE)
d2 <- d1[c(29,37:160)]
View(d2)
View(d2)
source('~/Desktop/face_morphs/facemorphs_proj/scr/4_transform_data_fm3.R')
# Load libraries and functions
library(reshape2); library(plyr); library(dplyr)
source('scr/SummarySE2.R')
# Load data
d1 <- read.csv('data/base_data/Faces3_Numeric_Data_reverse.csv', header=TRUE)
View(d1)
View(d1)
d2 <- melt(d1, id.vars = c('subnum', 'age'), value.name = 'rating')
View(d2)
View(d2)
View(d2)
View(d2)
View(d2)
View(d2)
View(d2)
View(d2)
# Pull apart variable
d2$emotion <- as.factor(t(as.data.frame(strsplit(as.character(d2$variable), '_')))[,2])
d2$level <- as.factor(t(as.data.frame(strsplit(as.character(d2$variable), '_')))[,3])
d2$domain <- as.factor(t(as.data.frame(strsplit(as.character(d2$variable), '_')))[,4])
View(d2)
View(d2)
View(d2)
View(d2)
# Summarize Table for JASP Analyses
# 6.3.21 JMS, adapted from 1_summarize_data by KLS & SA
# Load libraries and functions
library(reshape2); library(plyr); library(dplyr)
source('scr/SummarySE2.R')
# Load data
d1 <- read.csv('data/base_data/Faces3_Numeric_Data_reverse.csv', header=TRUE)
# Melt
d2 <- melt(d1, id.vars = c('subnum', 'age'), value.name = 'rating')
# Pull apart variable
d2$emotion <- as.factor(t(as.data.frame(strsplit(as.character(d2$variable), '_')))[,2])
d2$level <- as.factor(t(as.data.frame(strsplit(as.character(d2$variable), '_')))[,3])
d2$domain <- as.factor(t(as.data.frame(strsplit(as.character(d2$variable), '_')))[,4])
# Create [clean] csv of combined data
write.csv(d2,'data/all_faces_ratings_fm3.csv', row.names = FALSE)
# Melt
d2 <- melt(d1, id.vars = c('subnum', 'age'), value.name = 'rating')
# Pull apart variable
d2$emotion <- as.factor(t(as.data.frame(strsplit(as.character(d2$variable), '_')))[2])
d2$level <- as.factor(t(as.data.frame(strsplit(as.character(d2$variable), '_')))[3])
# Pull apart variable
d2$emotion <- as.factor(t(as.data.frame(strsplit(as.character(d2$variable), '_')))[,1])
d2$level <- as.factor(t(as.data.frame(strsplit(as.character(d2$variable), '_')))[,2])
d2$variable <- as.character(d2$variable)
# Pull apart variable
d2$emotion <- as.factor(t(as.data.frame(strsplit(d2$variable, '_')))[,1])
source('~/Desktop/face_morphs/facemorphs_proj/scr/4_transform_data_fm3.R')
as.data.frame(strsplit(as.character(d2$variable), '_')[,1])
# Summarize Table for JASP Analyses
# 6.3.21 JMS, adapted from 1_summarize_data by KLS & SA
# Load libraries and functions
library(reshape2); library(plyr); library(dplyr)
source('scr/SummarySE2.R')
# Load data
d1 <- read.csv('data/base_data/Faces3_Numeric_Data_reverse.csv', header=TRUE)
# Melt
d2 <- melt(d1, id.vars = c('subnum', 'age'), value.name = 'rating')
as.data.frame(strsplit(as.character(d2$variable), '_')[,1])
as.factor(t(as.data.frame(strsplit(as.character(d2$variable), '_')))[,1])
d2$emotion <- as.factor(t(as.data.frame(strsplit(as.character(d2$variable), '_')))[,1])
View(d2)
View(d2)
# Pull apart variable
d2$emotion <- as.factor(t(as.data.frame(strsplit(as.character(d2$variable), '_')))[,2])
d2$level <- as.factor(t(as.data.frame(strsplit(as.character(d2$variable), '_')))[,3])
View(d2)
View(d2)
d2$domain <- as.factor(t(as.data.frame(strsplit(as.character(d2$variable), '_')))[,4])
View(d2)
View(d2)
source('~/Desktop/face_morphs/facemorphs_proj/scr/4_transform_data_fm3.R')
source('~/Desktop/face_morphs/facemorphs_proj/scr/5_summarize_data_fm3.R')
source('~/Desktop/face_morphs/facemorphs_proj/scr/5_summarize_data_fm3.R')
d3 <- summarySE2(data = d2, measurevar = 'rating', groupvars = c('subnum', 'age', 'domain', 'emotion', 'level'), na.rm = TRUE)
# Make age groups
d3$agegrp <- ntile(d3$age, 3)
d3$agegrp <- factor(d3$agegrp, levels = c(1,2,3), labels = c('Younger', 'Middle Age', 'Older'))
View(d3)
View(d3)
View(d3)
View(d3)
d3 <- d3[c(1,11,2:5,7,8)]
View(d3)
View(d3)
d3$emo_level <- interaction(d3$emotion, d3$level) # create interaction term
d3$emo_level_dom <- interaction(d3$emotion, d3$level, d3$domain)
View(d3)
View(d3)
# Summarize Table for JASP Analyses
# 11.28.18 KLS & SA
# Updated 7.23.20 SA
# Tested 6.2.21 JMS
# Load libraries and functions
library(reshape2); library(plyr); library(dplyr)
source('scr/SummarySE2.R')
# Load data
d1a <- read.csv('data/base_data/Faces1_Numeric_Data_reverse.csv', header=TRUE)
d1b <- read.csv('data/base_data/Faces2_Numeric_Data_reverse.csv', header=TRUE)
# Delete the 'natural' columns in Faces2 (not important for this analysis)
d1b_no_nat <- d1b[, -c(1:2)]
d <- 1:ncol(d1b_no_nat)
d1b_no_nat <- d1b_no_nat[, !(d%%3==0)]
d1b_2 <- cbind(d1b[c(1:2)], d1b_no_nat)
d1b_2$subnum2 <- seq(1:nrow(d1b_2)) + 100
d1b <- d1b_2
# Remember to rename subnum1 and subnum2 to subnum for subsequent analyses
colnames(d1a)[colnames(d1a)=="subnum1"] <- "subnum"
colnames(d1b)[colnames(d1b)=="subnum2"] <- "subnum"
# Melt
d2a <- melt(d1a, id.vars = c('subnum', 'age'), value.name = 'rating')
d2b <- melt(d1b, id.vars = c('subnum', 'age'), value.name = 'rating')
# COMBINE VARIABLES!
d2 <- rbind(d2a, d2b)
# Pull apart variable
d2$emotion <- as.factor(t(as.data.frame(strsplit(as.character(d2$variable), '_')))[,2])
d2$level <- as.factor(t(as.data.frame(strsplit(as.character(d2$variable), '_')))[,3])
d2$domain <- as.factor(t(as.data.frame(strsplit(as.character(d2$variable), '_')))[,4])
# Create [clean] csv of combined data
write.csv(d2,'data/all_faces_ratings.csv', row.names = FALSE)
# -------------------------------
# Age grouping
# -------------------------------
d4a <- summarySE2(data = d2, measurevar = 'rating', groupvars = c('subnum', 'age', 'domain', 'emotion', 'level'), na.rm = TRUE)
#d4a_test <- summarySE(d2, 'rating', groupvars=c('subnum', 'age', 'domain', 'emotion', 'level'), na.rm = TRUE)
# Make age groups
d4a$agegrp <- ntile(d4a$age, 3)
d4a$agegrp <- factor(d4a$agegrp, levels = c(1,2,3), labels = c('Younger', 'Middle Age', 'Older'))
# Reorganize table and make wide
d4a <- d4a[c(1,11,2:5,7,8)]
d4a$emo_level <- interaction(d4a$emotion, d4a$level) # create interaction term
d4a$emo_level_dom <- interaction(d4a$emotion, d4a$level, d4a$domain)
View(d4a)
View(d4a)
source('~/Desktop/face_morphs/facemorphs_proj/scr/5_summarize_data_fm3.R')
source('~/Desktop/face_morphs/facemorphs_proj/scr/5_summarize_data_fm3.R')
source('~/Desktop/face_morphs/facemorphs_proj/scr/0_transform_data.R')
source('~/Desktop/face_morphs/facemorphs_proj/scr/1_summarize_data.R')
source('~/Desktop/face_morphs/facemorphs_proj/scr/2a_visualize_data_arsl.R')
source('~/Desktop/face_morphs/facemorphs_proj/scr/2b_visualize_data_vln.R')
source('~/Desktop/face_morphs/facemorphs_proj/scr/3_naturalness_analysis.R')
source('~/Desktop/face_morphs/facemorphs_proj/scr/4_transform_data_fm3.R')
source('~/Desktop/face_morphs/facemorphs_proj/scr/5_summarize_data_fm3.R')
source('~/Desktop/face_morphs/facemorphs_proj/scr/1a_summarize_data_fm3.R')
# Face Morph 3 Graphs (Arousal)
# 6.3.21 JMS, adapted from 2a_visualize_data_arsl by KLS & SA
# Load libraries and functions
library(ggplot2); library(reshape2); library(plyr); library(dplyr); library(plotly); library(wesanderson)
source('scr/SummarySE2.R')
# ===============
# Arousal
# ===============
f <- read.csv('data/ave_faces_ratings_fm3.csv')
fa <- f[which(f$domain == 'arsl'),]
View(fa)
View(fa)
# Remove age and domain variable (missing data)
fa$domain <- NULL
fa$age <- NULL
View(fa)
View(fa)
# Remove age and domain variable (missing data)
fa$domain <- NULL
fa$age <- NULL
fa$X1.att < NULL
fa$X2.att < NULL
fa$X3.att < NULL
fa$X4.att < NULL
View(fa)
View(fa)
fa$1.att < NULL
fa$2.att < NULL
fa$3.att < NULL
fa$4.att < NULL
fa$X1.att < NULL
fa$X2.att < NULL
fa$X3.att < NULL
fa$X4.att < NULL
fa$X1.att <- NULL
fa$X2.att <- NULL
fa$X3.att <- NULL
fa$X4.att <- NULL
View(fa)
# Reorder age variable
fa$agegrp <- relevel(factor(fa$agegrp), 'Younger')
View(fa)
# Remove people with incomplete data
fa <- fa[complete.cases(fa),]
View(fa)
# Change from wide to long format
fa1 <- melt(fa, id.vars=c('subnum','agegrp'), value.name = 'rating')
# Make new variable for emotion
fa1$emotion <- as.factor(t(as.data.frame(strsplit(as.character(fa1$variable), '[.]')))[,1])
fa1$emotion <- revalue(fa1$emotion, c('a'= 'Angry', 's' = 'Sad', 'h' = 'Happy'))
fa1$emotion <- relevel(fa1$emotion, 'Sad')
fa1$emotion <- relevel(fa1$emotion, 'Happy')
View(fa1)
# Make new variable for level
fa1$level <- as.factor(t(as.data.frame(strsplit(as.character(fa1$variable), '[.]')))[,2])
fa1$level <- relevel(fa1$level, 'med')
fa1$level <- relevel(fa1$level, 'low')
fa1$level <- revalue(fa1$level, c('low'= 'Low', 'med' = 'Med', 'full' = 'Full'))
# Delete variable column
fa1$variable <- NULL
View(fa1)
source('~/Desktop/face_morphs/facemorphs_proj/scr/2c_visualize_data_arsl_fm3.R')
source('~/Desktop/face_morphs/facemorphs_proj/scr/2a_visualize_data_arsl.R')
source('~/Desktop/face_morphs/facemorphs_proj/scr/2c_visualize_data_arsl_fm3.R')
# Face Morph 3 Graphs (Valence)
# 6.3.21 JMS, adapted from 2b_visualize_data_vln by KLS & SA
# Load libraries and functions
library(ggplot2); library(reshape2); library(plyr); library(wesanderson)
source('scr/SummarySE2.R')
# ===============
# Valence
# ===============
f <- read.csv('data/ave_faces_ratings_fm3.csv')
fv <- f[which(f$domain == 'vln'),]
View(fv)
# Remove age, domain and attention variables (missing data)
fv$domain <- NULL
fv$age <- NULL
fv$X1.att <- NULL
fv$X2.att <- NULL
fv$X3.att <- NULL
fv$X4.att <- NULL
View(fv)
source('~/Desktop/face_morphs/facemorphs_proj/scr/2d_visualize_data_vln_fm3.R')
source('~/Desktop/face_morphs/facemorphs_proj/scr/0a_transform_data_fm3.R')
View(d3)
View(d3)
source('~/Desktop/face_morphs/facemorphs_proj/scr/0a_transform_data_fm3.R')
source('~/Desktop/face_morphs/facemorphs_proj/scr/0a_transform_data_fm3.R')
source('~/Desktop/face_morphs/facemorphs_proj/scr/0a_transform_data_fm3.R')
View(d3)
View(d3)
source('~/Desktop/face_morphs/facemorphs_proj/scr/0a_transform_data_fm3.R')
source('~/Desktop/face_morphs/facemorphs_proj/scr/0a_transform_data_fm3.R')
source('~/Desktop/face_morphs/facemorphs_proj/scr/0a_transform_data_fm3.R')
View(d3)
source('~/Desktop/face_morphs/facemorphs_proj/scr/0a_transform_data_fm3.R')
View(d3)
source('~/Desktop/face_morphs/facemorphs_proj/scr/0a_transform_data_fm3.R')
View(d3)
# Script for Face Morph 3 Variable Recoding and 3-way ANOVA
# 6.3.21 JMS, adapted from 0_transform_data by KLS & SA
# Install packages and load libraries
library(psych); library(plyr)
# Create transform function to recode data
transform <- function(data, x) data[,x] <- revalue(factor(data[,x]), map, warn_missing=FALSE)
key.list <- list(1:7)
faceKey <- make.keys(7,key.list)
# Load data and reverse code each variable individually
d1 <- read.csv("data/base_data/Face_Morph3_raw.csv", header=TRUE, stringsAsFactors = FALSE)
d2 <- d1[c(29,37:160)]
map <- c('7 - Very Negative'='1', '6 - Moderately Negative'='2', '5 - Slightly Negative'='3', '4 - Neutral'='4','3 - Slightly Positive'='5', '2 - Moderately Positive'='6', '1 - Very Positive'='7', '7 - Not At All Aroused'='1', '6'='2', '5'='3','4'='4','3'='5', '2'='6', '1 - Very Aroused'='7')
for (i in 2:ncol(d2)) d2[i] <- as.numeric(as.character(transform(d2,i)))
d2 <- d2[3:nrow(d2),] # this clips off excess rows
# Add sub number
subnum <- seq(1:nrow(d2))
d3 <- cbind(subnum, d2)
# Rename columns
#rename all columns
d3 <- d3 %>% rename(c('age' = Q5, 'att_1' = Q580, 'att_2' = Q581, 'att_3' = Q585, 'att_4' = Q586,
'01_win_full_arsl' = Q21, '01_win_full_vln' = Q22, '01_win_low_arsl' = Q26, '01_win_low_vln' = Q27, '01_win_med_arsl' = Q31, '01_win_med_vln' = Q32,
'01_lose_full_arsl' = Q36, '01_lose_full_vln' = Q37, '01_lose_low_arsl' = Q41, '01_lose_low_vln' = Q42, '01_lose_med_arsl' = Q46, '01_lose_med_vln' = Q47,
'04_a_full_arsl' = Q50, '04_a_full_vln' = Q51, '04_a_low_arsl' = Q54, '04_a_low_vln' = Q55, '04_a_med_arsl' = Q58, '04_a_med_vln' = Q59,
'04_h_full_arsl' = Q62, '04_h_full_vln' = Q63, '04_h_low_arsl' = Q66, '04_h_low_vln' = Q67, '04_h_med_arsl' = Q70, '04_h_med_vln' = Q71,
'04_s_full_arsl' = Q74, '04_s_full_vln' = Q75, '04_s_low_arsl' = Q78, '04_s_low_vln' = Q79, '04_s_med_arsl' = Q82, '04_s_med_vln' = Q83,
'116_a_full_arsl' = Q86, '116_a_full_vln' = Q87, '116_a_low_arsl' = Q90, '116_a_low_vln' = Q91, '116_a_med_arsl' = Q94, '116_a_med_vln' = Q95,
'116_h_full_arsl' = Q98, '116_h_full_vln' = Q99, '116_h_low_arsl' = Q102, '116_h_low_vln' = Q103, '116_h_med_arsl' = Q106, '116_h_med_vln' = Q107,
'116_s_full_arsl' = Q110, '116_s_full_vln' = Q111, '116_s_low_arsl' = Q114, '116_s_low_vln' = Q115, '116_s_med_arsl' = Q118, '116_s_med_vln' = Q119,
'133_a_full_arsl' = Q122, '133_a_full_vln' = Q123, '133_a_low_arsl' = Q126, '133_a_low_vln' = Q127, '133_a_med_arsl' = Q130, '133_a_med_vln' = Q131,
'133_h_full_arsl' = Q134, '133_h_full_vln' = Q135, '133_h_low_arsl' = Q138, '133_h_low_vln' = Q139, '133_h_med_arsl' = Q142, '133_h_med_vln' = Q143,
'133_s_full_arsl' = Q146, '133_s_full_vln' = Q147, '133_s_low_arsl' = Q150, '133_s_low_vln' = Q151, '133_s_med_arsl' = Q154, '133_s_med_vln' = Q155,
'49_a_full_arsl' = Q158, '49_a_full_vln' = Q159, '49_a_low_arsl' = Q162, '49_a_low_vln' = Q163, '49_a_med_arsl' = Q166, '49_a_med_vln' = Q167,
'49_h_full_arsl' = Q170, '49_h_full_vln' = Q171, '49_h_low_arsl' = Q174, '49_h_low_vln' = Q175, '49_h_med_arsl' = Q178, '49_h_med_vln' = Q179,
'49_s_full_arsl' = Q182, '49_s_full_vln' = Q183, '49_s_low_arsl' = Q186, '49_s_low_vln' = Q187, '49_s_med_arsl' = Q190, '49_s_med_vln' = Q191,
'69_a_full_arsl' = Q194, '69_a_full_vln' = Q195, '69_a_low_arsl' = Q198, '69_a_low_vln' = Q199, '69_a_med_arsl' = Q202, '69_a_med_vln' = Q203,
'69_h_full_arsl' = Q206, '69_h_full_vln' = Q207, '69_h_low_arsl' = Q210, '69_h_low_vln' = Q211, '69_h_med_arsl' = Q214, '69_h_med_vln' = Q215,
'69_s_full_arsl' = Q218, '69_s_full_vln' = Q219, '69_s_low_arsl' = Q222, '69_s_low_vln' = Q223, '69_s_med_arsl' = Q226, '69_s_med_vln' = Q227,
'113_a_full_arsl' = Q230, '113_a_full_vln' = Q231, '113_a_low_arsl' = Q234, '113_a_low_vln' = Q235, '113_a_med_arsl' = Q238, '113_a_med_vln' = Q239,
'113_h_full_arsl' = Q242, '113_h_full_vln' = Q243, '113_h_low_arsl' = Q246, '113_h_low_vln' = Q247, '113_h_med_arsl' = Q250, '113_h_med_vln' = Q251,
'113_s_full_arsl' = Q254, '113_s_full_vln' = Q255, '113_s_low_arsl' = Q258, '113_s_low_vln' = Q259, '113_s_med_arsl' = Q262, '113_s_med_vln' = Q263))
# Write to csv
write.csv(d3, 'data/base_data/Faces3_Numeric_Data_reverse.csv', row.names=FALSE)
# Install packages and load libraries
library(psych); library(plyr); library(dplyr)
source('~/Desktop/face_morphs/facemorphs_proj/scr/0a_transform_data_fm3.R')
source('~/Desktop/face_morphs/facemorphs_proj/scr/0a_transform_data_fm3.R')
source('~/Desktop/face_morphs/facemorphs_proj/scr/0a_transform_data_fm3.R')
source('~/Desktop/face_morphs/facemorphs_proj/scr/1a_summarize_data_fm3.R')
source('~/Desktop/face_morphs/facemorphs_proj/scr/2c_visualize_data_arsl_fm3.R')
source('~/Desktop/face_morphs/facemorphs_proj/scr/2d_visualize_data_vln_fm3.R')
source('~/Desktop/face_morphs/facemorphs_proj/scr/0a_transform_data_fm3.R')
source('~/Desktop/face_morphs/facemorphs_proj/scr/1a_summarize_data_fm3.R')
source('~/Desktop/face_morphs/facemorphs_proj/scr/2c_visualize_data_arsl_fm3.R')
source('~/Desktop/face_morphs/facemorphs_proj/scr/2d_visualize_data_vln_fm3.R')