-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.Rhistory
512 lines (512 loc) · 24 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
names(myData)[names(myData) == sessionID] <- "SESSION_ID"
names(myData)[names(myData) == trialLatency] <- "TRIAL_LATENCY"
myTbl <- group_by(tbl_df(myData), SESSION_ID)
myTbl$SUBEXCL <- 0
# Step 1: Include data from B3, B4, B6, B7
# Step 1 has been removed so all data is at least partially analyzed
# Step 2a: Eliminate trial latencies > 10,000ms and < 0ms
myTblNoLong <- filter(myTbl, TRIAL_LATENCY < 10000, TRIAL_LATENCY >= 0)
# Step 2b: Mark subjects for whom more than 10% of trials have latencies < 300ms with a 1
myFastTbl <- filter(myTbl, BLOCK_NAME %in% trialBlocks) %>%
summarise(FASTM = sum(TRIAL_LATENCY < 300)/length(TRIAL_LATENCY))
isTooFast <- filter(myFastTbl, FASTM > 0.10) %>%
select(SESSION_ID)
if(nrow(isTooFast) > 0){
myTbl[myTbl$SESSION_ID %in% isTooFast, ]$SUBEXCL <- 1
}
# Step 2c: Mark subjects with any missing blocks with a 2
numBlocks <- filter(myTbl, BLOCK_NAME %in% trialBlocks) %>%
summarise(total = length(unique(BLOCK_NAME)))
notComplete <- filter(numBlocks, total < 4)
if(nrow(notComplete) > 0){
myTbl[myTbl$SESSION_ID %in% notComplete, ]$SUBEXCL <- 2
}
# Step 3: Use all trials (in the conventional algorithm) the first two trials of each
# block would be dropped here
# Step 4: No extreme value treatment <or> delete trial with latencies < 400ms
if(vExtreme == 1){
myTblNotFast <- group_by(myTblNoLong, SESSION_ID, BLOCK_NAME)
} else if(vExtreme == 2){
myTblNotFast <- group_by(filter(myTblNoLong, TRIAL_LATENCY >= 400), SESSION_ID, BLOCK_NAME)
}
# Step 5: Compute mean of correct latencies for each block
# If vError = 1 then means and SDs will be calculated for the entire set of latencies
# IF vError = 2 then the algorithm will replace error trial latencies with blockmean + 600
# (where blockmean is mean of correct responses only)
# Step 5: Compute mean of correct latencies for each block
# If vError = 1 then means and SDs will be calculated for the entire set of latencies
# IF vError = 2 then the algorithm will replace error trial latencies with blockmean + 600
# (where blockmean is mean of correct responses only)
if(vError == 1){
blockMeans <- summarise(myTblNotFast, M = mean(TRIAL_LATENCY), N = length(TRIAL_LATENCY))
} else if(vError == 2){
meanReplace <- filter(myTblNotFast, TRIAL_ERROR == 0) %>%
summarise(blockMean = mean(TRIAL_LATENCY) + 600)
mergeTbl <- merge(myTblNotFast, meanReplace, by = c(sessionID, blockName), all = TRUE)
myTblNotFast$tmpLatency <- myTblNotFast$TRIAL_LATENCY
names(myTblNotFast)[c(14, 18)] <- c("oldLatency", trialLatency)
blockMeans <- summarise(myTblNotFast, M = mean(TRIAL_LATENCY), N = length(TRIAL_LATENCY))
} else stop("Please pick a value of 1 or 2 for vError.")
# Step 6: Compute pooled SD for B3 & B6, and separately for B4 & B7.
# If vStd is 1, the block SD is performed including error trials (corrected or not)
# If vStd is 2, the block SD is performed on correct responses only
myTblNotFast$blockPairs <- as.character(myTblNotFast$BLOCK_NAME)
myTblNotFast[myTblNotFast$BLOCK_NAME %in% trialBlocks[c(1,3)], ]$blockPairs <- "S1"
myTblNotFast[myTblNotFast$BLOCK_NAME %in% trialBlocks[c(2,4)], ]$blockPairs <- "S2"
myTblNotFast <- group_by(myTblNotFast, SESSION_ID, blockPairs)
allTblSDs <- merge(filter(myTblNotFast, BLOCK_NAME %in% trialBlocks) %>% summarise(A = sd(TRIAL_LATENCY)),
filter(myTblNotFast, BLOCK_NAME %in% trialBlocks & TRIAL_ERROR == 0) %>%
summarise(C = sd(TRIAL_LATENCY)),
by = c(sessionID, "blockPairs"))
blockMeansTbl <- merge(reshape(allTblSDs, v.names = c("A", "C"), idvar = "SESSION_ID", timevar = "blockPairs", direction = "wide", sep = ""),
reshape(blockMeans, v.names = c("M", "N"), idvar = "SESSION_ID", timevar = "BLOCK_NAME", direction = "wide", sep = ""),
by = "SESSION_ID")
# Step 7: Replace error latencies with block mean + 600ms
# Already done in step above
# Step 8: No transformation of latencies
# Step 9: Average latencies for each of the four blocks
# This was already done above
# Step 10: Compute the two differences B6 - B3 and B7 - B4
# Step 11: Divide each difference by associated pooled SD from step 6
if(vStd == 1){
tblResult <-
mutate(blockMeansTbl,
DIFF1 = MBLOCK5 - MBLOCK2,
DIFF2 = MBLOCK6 - MBLOCK3) %>%
mutate(IAT1 = DIFF1/AS1,
IAT2 = DIFF2/AS2) %>%
mutate(IAT = (IAT1 + IAT2)/2)
} else if(vStd == 2){
tblResult <-
mutate(blockMeansTbl,
DIFF1 = MBLOCK5 - MBLOCK2,
DIFF2 = MBLOCK6 - MBLOCK3) %>%
mutate(IAT1 = DIFF1/CS1,
IAT2 = DIFF2/CS2) %>%
mutate(IAT = (IAT1 + IAT2)/2)
} else stop("Please enter a vStd value of 1 or 2.")
##########################
# Create output dataframe
##########################
myTbl <- group_by(myTbl, SESSION_ID, BLOCK_NAME)
tblErrFast <- summarise(myTbl,
E = sum(TRIAL_ERROR)/length(TRIAL_ERROR),
F = sum(TRIAL_LATENCY < 300)/length(TRIAL_LATENCY))
tblErrFastWide <- reshape(tblErrFast, v.names = c("E", "F"), idvar = "SESSION_ID", timevar = "BLOCK_NAME", direction = "wide", sep = "")
tblExtras <- merge(tblErrFastWide, myFastTbl, by = sessionID, all = TRUE)
myTbl <- group_by(myTbl, SESSION_ID)
tblExcl <- summarise(myTbl, SUBEXCL = unique(SUBEXCL))
tblExtras$SUBEXCL <- tblExcl$SUBEXCL
tblTotal <- merge(tblResult, tblExtras, by = sessionID, all = TRUE)
}
fooFun(myData = myDataCongFirst,
blockName = "BLOCK_NAME_S",
trialBlocks = c("BLOCK2", "BLOCK3", "BLOCK5", "BLOCK6"),
sessionID = "SESSION_ID",
trialLatency = "TRIAL_LATENCY",
trialError = "TRIAL_ERROR",
vError = 1, vExtreme = 2, vStd = 1)
fooFun <- function(myData, sessionID, blockName, trialBlocks, trialLatency, trialError, vError, vExtreme, vStd){
names(myData)[names(myData) == blockName] <- "BLOCK_NAME"
names(myData)[names(myData) == sessionID] <- "SESSION_ID"
names(myData)[names(myData) == trialLatency] <- "TRIAL_LATENCY"
myTbl <- group_by(tbl_df(myData), SESSION_ID)
myTbl$SUBEXCL <- 0
# Step 1: Include data from B3, B4, B6, B7
# Step 1 has been removed so all data is at least partially analyzed
# Step 2a: Eliminate trial latencies > 10,000ms and < 0ms
myTblNoLong <- filter(myTbl, TRIAL_LATENCY < 10000, TRIAL_LATENCY >= 0)
# Step 2b: Mark subjects for whom more than 10% of trials have latencies < 300ms with a 1
myFastTbl <- filter(myTbl, BLOCK_NAME %in% trialBlocks) %>%
summarise(FASTM = sum(TRIAL_LATENCY < 300)/length(TRIAL_LATENCY))
isTooFast <- filter(myFastTbl, FASTM > 0.10) %>%
select(SESSION_ID)
if(nrow(isTooFast) > 0){
myTbl[myTbl$SESSION_ID %in% isTooFast, ]$SUBEXCL <- 1
}
# Step 2c: Mark subjects with any missing blocks with a 2
numBlocks <- filter(myTbl, BLOCK_NAME %in% trialBlocks) %>%
summarise(total = length(unique(BLOCK_NAME)))
notComplete <- filter(numBlocks, total < 4)
if(nrow(notComplete) > 0){
myTbl[myTbl$SESSION_ID %in% notComplete, ]$SUBEXCL <- 2
}
# Step 3: Use all trials (in the conventional algorithm) the first two trials of each
# block would be dropped here
# Step 4: No extreme value treatment <or> delete trial with latencies < 400ms
if(vExtreme == 1){
myTblNotFast <- group_by(myTblNoLong, SESSION_ID, BLOCK_NAME)
} else if(vExtreme == 2){
myTblNotFast <- group_by(filter(myTblNoLong, TRIAL_LATENCY >= 400), SESSION_ID, BLOCK_NAME)
}
# Step 5: Compute mean of correct latencies for each block
# If vError = 1 then means and SDs will be calculated for the entire set of latencies
# IF vError = 2 then the algorithm will replace error trial latencies with blockmean + 600
# (where blockmean is mean of correct responses only)
# Step 5: Compute mean of correct latencies for each block
# If vError = 1 then means and SDs will be calculated for the entire set of latencies
# IF vError = 2 then the algorithm will replace error trial latencies with blockmean + 600
# (where blockmean is mean of correct responses only)
if(vError == 1){
blockMeans <- summarise(myTblNotFast, M = mean(TRIAL_LATENCY), N = length(TRIAL_LATENCY))
} else if(vError == 2){
meanReplace <- filter(myTblNotFast, TRIAL_ERROR == 0) %>%
summarise(blockMean = mean(TRIAL_LATENCY) + 600)
mergeTbl <- merge(myTblNotFast, meanReplace, by = c(sessionID, blockName), all = TRUE)
myTblNotFast$tmpLatency <- myTblNotFast$TRIAL_LATENCY
names(myTblNotFast)[c(14, 18)] <- c("oldLatency", trialLatency)
blockMeans <- summarise(myTblNotFast, M = mean(TRIAL_LATENCY), N = length(TRIAL_LATENCY))
} else stop("Please pick a value of 1 or 2 for vError.")
# Step 6: Compute pooled SD for B3 & B6, and separately for B4 & B7.
# If vStd is 1, the block SD is performed including error trials (corrected or not)
# If vStd is 2, the block SD is performed on correct responses only
myTblNotFast$blockPairs <- as.character(myTblNotFast$BLOCK_NAME)
myTblNotFast[myTblNotFast$BLOCK_NAME %in% trialBlocks[c(1,3)], ]$blockPairs <- "S1"
myTblNotFast[myTblNotFast$BLOCK_NAME %in% trialBlocks[c(2,4)], ]$blockPairs <- "S2"
myTblNotFast <- group_by(myTblNotFast, SESSION_ID, blockPairs)
allTblSDs <- merge(filter(myTblNotFast, BLOCK_NAME %in% trialBlocks) %>% summarise(A = sd(TRIAL_LATENCY)),
filter(myTblNotFast, BLOCK_NAME %in% trialBlocks & TRIAL_ERROR == 0) %>%
summarise(C = sd(TRIAL_LATENCY)),
by = c(sessionID, "blockPairs"))
blockMeansTbl <- merge(reshape(allTblSDs, v.names = c("A", "C"), idvar = "SESSION_ID", timevar = "blockPairs", direction = "wide", sep = ""),
reshape(blockMeans, v.names = c("M", "N"), idvar = "SESSION_ID", timevar = "BLOCK_NAME", direction = "wide", sep = ""),
by = "SESSION_ID")
# Step 7: Replace error latencies with block mean + 600ms
# Already done in step above
# Step 8: No transformation of latencies
# Step 9: Average latencies for each of the four blocks
# This was already done above
# Step 10: Compute the two differences B6 - B3 and B7 - B4
# Step 11: Divide each difference by associated pooled SD from step 6
if(vStd == 1){
tblResult <-
mutate(blockMeansTbl,
DIFF1 = MBLOCK5 - MBLOCK2,
DIFF2 = MBLOCK6 - MBLOCK3) %>%
mutate(IAT1 = DIFF1/AS1,
IAT2 = DIFF2/AS2) %>%
mutate(IAT = (IAT1 + IAT2)/2)
} else if(vStd == 2){
tblResult <-
mutate(blockMeansTbl,
DIFF1 = MBLOCK5 - MBLOCK2,
DIFF2 = MBLOCK6 - MBLOCK3) %>%
mutate(IAT1 = DIFF1/CS1,
IAT2 = DIFF2/CS2) %>%
mutate(IAT = (IAT1 + IAT2)/2)
} else stop("Please enter a vStd value of 1 or 2.")
##########################
# Create output dataframe
##########################
myTbl <- group_by(myTbl, SESSION_ID, BLOCK_NAME)
tblErrFast <- summarise(myTbl,
E = sum(TRIAL_ERROR)/length(TRIAL_ERROR),
F = sum(TRIAL_LATENCY < 300)/length(TRIAL_LATENCY))
tblErrFastWide <- reshape(tblErrFast, v.names = c("E", "F"), idvar = "SESSION_ID", timevar = "BLOCK_NAME", direction = "wide", sep = "")
tblExtras <- merge(tblErrFastWide, myFastTbl, by = sessionID, all = TRUE)
myTbl <- group_by(myTbl, SESSION_ID)
tblExcl <- summarise(myTbl, SUBEXCL = unique(SUBEXCL))
tblExtras$SUBEXCL <- tblExcl$SUBEXCL
tblTotal <- merge(tblResult, tblExtras, by = sessionID, all = TRUE)
return(tblTotal)
}
fooFun(myData = myDataCongFirst,
blockName = "BLOCK_NAME_S",
trialBlocks = c("BLOCK2", "BLOCK3", "BLOCK5", "BLOCK6"),
sessionID = "SESSION_ID",
trialLatency = "TRIAL_LATENCY",
trialError = "TRIAL_ERROR",
vError = 1, vExtreme = 2, vStd = 1)
benchmark(gah <- fooFun(myData = myDataCongFirst,
blockName = "BLOCK_NAME_S",
trialBlocks = c("BLOCK2", "BLOCK3", "BLOCK5", "BLOCK6"),
sessionID = "SESSION_ID",
trialLatency = "TRIAL_LATENCY",
trialError = "TRIAL_ERROR",
vError = 1, vExtreme = 2, vStd = 1))
myData = myDataCongFirst;
blockName = "BLOCK_NAME_S";
trialBlocks = c("BLOCK2", "BLOCK3", "BLOCK5", "BLOCK6");
sessionID = "SESSION_ID";
trialLatency <- 'TRIAL_LATENCY';
trialError = "TRIAL_ERROR";
vError = 1; vExtreme = 2; vStd = 1
names(myData)[names(myData) == blockName] <- "BLOCK_NAME"
names(myData)[names(myData) == sessionID] <- "SESSION_ID"
names(myData)[names(myData) == trialLatency] <- "TRIAL_LATENCY"
myTbl <- group_by(tbl_df(myData), SESSION_ID)
myTbl$SUBEXCL <- 0
# Step 1: Include data from B3, B4, B6, B7
# Step 1 has been removed so all data is at least partially analyzed
# Step 2a: Eliminate trial latencies > 10,000ms and < 0ms
myTblNoLong <- filter(myTbl, TRIAL_LATENCY < 10000, TRIAL_LATENCY >= 0)
# Step 2b: Mark subjects for whom more than 10% of trials have latencies < 300ms with a 1
myFastTbl <- filter(myTbl, BLOCK_NAME %in% trialBlocks) %>%
summarise(FASTM = sum(TRIAL_LATENCY < 300)/length(TRIAL_LATENCY))
isTooFast <- filter(myFastTbl, FASTM > 0.10) %>%
select(SESSION_ID)
if(nrow(isTooFast) > 0){
myTbl[myTbl$SESSION_ID %in% isTooFast, ]$SUBEXCL <- 1
}
# Step 2c: Mark subjects with any missing blocks with a 2
numBlocks <- filter(myTbl, BLOCK_NAME %in% trialBlocks) %>%
summarise(total = length(unique(BLOCK_NAME)))
notComplete <- filter(numBlocks, total < 4)
if(nrow(notComplete) > 0){
myTbl[myTbl$SESSION_ID %in% notComplete, ]$SUBEXCL <- 2
}
# Step 3: Use all trials (in the conventional algorithm) the first two trials of each
# block would be dropped here
# Step 4: No extreme value treatment <or> delete trial with latencies < 400ms
if(vExtreme == 1){
myTblNotFast <- group_by(myTblNoLong, SESSION_ID, BLOCK_NAME)
} else if(vExtreme == 2){
myTblNotFast <- group_by(filter(myTblNoLong, TRIAL_LATENCY >= 400), SESSION_ID, BLOCK_NAME)
}
# Step 5: Compute mean of correct latencies for each block
# If vError = 1 then means and SDs will be calculated for the entire set of latencies
# IF vError = 2 then the algorithm will replace error trial latencies with blockmean + 600
# (where blockmean is mean of correct responses only)
# Step 5: Compute mean of correct latencies for each block
# If vError = 1 then means and SDs will be calculated for the entire set of latencies
# IF vError = 2 then the algorithm will replace error trial latencies with blockmean + 600
# (where blockmean is mean of correct responses only)
if(vError == 1){
blockMeans <- summarise(myTblNotFast, M = mean(TRIAL_LATENCY), N = length(TRIAL_LATENCY))
} else if(vError == 2){
meanReplace <- filter(myTblNotFast, TRIAL_ERROR == 0) %>%
summarise(blockMean = mean(TRIAL_LATENCY) + 600)
mergeTbl <- merge(myTblNotFast, meanReplace, by = c(sessionID, blockName), all = TRUE)
myTblNotFast$tmpLatency <- myTblNotFast$TRIAL_LATENCY
names(myTblNotFast)[c(14, 18)] <- c("oldLatency", trialLatency)
blockMeans <- summarise(myTblNotFast, M = mean(TRIAL_LATENCY), N = length(TRIAL_LATENCY))
} else stop("Please pick a value of 1 or 2 for vError.")
# Step 6: Compute pooled SD for B3 & B6, and separately for B4 & B7.
# If vStd is 1, the block SD is performed including error trials (corrected or not)
# If vStd is 2, the block SD is performed on correct responses only
myTblNotFast$blockPairs <- as.character(myTblNotFast$BLOCK_NAME)
myTblNotFast[myTblNotFast$BLOCK_NAME %in% trialBlocks[c(1,3)], ]$blockPairs <- "S1"
myTblNotFast[myTblNotFast$BLOCK_NAME %in% trialBlocks[c(2,4)], ]$blockPairs <- "S2"
myTblNotFast <- group_by(myTblNotFast, SESSION_ID, blockPairs)
allTblSDs <- merge(filter(myTblNotFast, BLOCK_NAME %in% trialBlocks) %>% summarise(A = sd(TRIAL_LATENCY)),
filter(myTblNotFast, BLOCK_NAME %in% trialBlocks & TRIAL_ERROR == 0) %>%
summarise(C = sd(TRIAL_LATENCY)),
by = c(sessionID, "blockPairs"))
blockMeansTbl <- merge(reshape(allTblSDs, v.names = c("A", "C"), idvar = "SESSION_ID", timevar = "blockPairs", direction = "wide", sep = ""),
reshape(blockMeans, v.names = c("M", "N"), idvar = "SESSION_ID", timevar = "BLOCK_NAME", direction = "wide", sep = ""),
by = "SESSION_ID")
# Step 7: Replace error latencies with block mean + 600ms
# Already done in step above
# Step 8: No transformation of latencies
# Step 9: Average latencies for each of the four blocks
# This was already done above
# Step 10: Compute the two differences B6 - B3 and B7 - B4
# Step 11: Divide each difference by associated pooled SD from step 6
if(vStd == 1){
tblResult <-
mutate(blockMeansTbl,
DIFF1 = MBLOCK5 - MBLOCK2,
DIFF2 = MBLOCK6 - MBLOCK3) %>%
mutate(IAT1 = DIFF1/AS1,
IAT2 = DIFF2/AS2) %>%
mutate(IAT = (IAT1 + IAT2)/2)
} else if(vStd == 2){
tblResult <-
mutate(blockMeansTbl,
DIFF1 = MBLOCK5 - MBLOCK2,
DIFF2 = MBLOCK6 - MBLOCK3) %>%
mutate(IAT1 = DIFF1/CS1,
IAT2 = DIFF2/CS2) %>%
mutate(IAT = (IAT1 + IAT2)/2)
} else stop("Please enter a vStd value of 1 or 2.")
##########################
# Create output dataframe
##########################
myTbl <- group_by(myTbl, SESSION_ID, BLOCK_NAME)
tblErrFast <- summarise(myTbl,
E = sum(TRIAL_ERROR)/length(TRIAL_ERROR),
F = sum(TRIAL_LATENCY < 300)/length(TRIAL_LATENCY))
tblErrFastWide <- reshape(tblErrFast, v.names = c("E", "F"), idvar = "SESSION_ID", timevar = "BLOCK_NAME", direction = "wide", sep = "")
tblExtras <- merge(tblErrFastWide, myFastTbl, by = sessionID, all = TRUE)
myTbl <- group_by(myTbl, SESSION_ID)
tblExcl <- summarise(myTbl, SUBEXCL = unique(SUBEXCL))
tblExtras$SUBEXCL <- tblExcl$SUBEXCL
tblTotal <- merge(tblResult, tblExtras, by = sessionID, all = TRUE)
tblTotal
names(tblTotal)
names(tblTotal)[names(myData) == "SESSION_ID"]
names(tblTotal)[names(tblTotal) == "SESSION_ID"]
sessionID
data("IATData.rdata", envir = .BaseNamespaceEnv)
library(IAT)
?last
data("IATData.rdata", envir = .BaseNamespaceEnv)
data("Data/IATData.rdata", envir = .BaseNamespaceEnv)
list.files()
data("data/IATData.rdata", envir = .BaseNamespaceEnv)
list.files("data")
load("IATData.rdata")
load("data/IATData.rdata")
ls()
myData <- IATDatals()
myData <- IATData
length(unique(myData[, sessionID])) > 100
?cleanIAT
myData = myDataCongFirst
blockName = "BLOCK_NAME_S"
trialBlocks = c("BLOCK2", "BLOCK3", "BLOCK5", "BLOCK6")
sessionID = "SESSION_ID"
trialLatency = "TRIAL_LATENCY"
trialError = "TRIAL_ERROR"
vError = 1
vExtreme = 2
vStd = 1
length(unique(myData[, sessionID])) > 100
sampleIDs <- sample(unique(myData[, sessionID]), 100)
if(length(unique(myData[, sessionID])) > 100){
sampleIDs <- sample(unique(myData[, sessionID]), 100)
myData <- myData[myData[, sessionID] %in% sampleIDs, ]
warning("Your total sample size is > 100. A random subsample was taken for plotting.")
}
myDataNew <- myData[myData[, blockName] %in% trialBlocks, ]
myDataNew <- myDataNew[myDataNew[, trialLatency] > 180 & myDataNew[, trialLatency] < 10000, ]
myDataCongFirst <- IATData[IATData$isCongruentFirst == 1, ]
myData = myDataCongFirst
blockName = "BLOCK_NAME_S"
trialBlocks = c("BLOCK2", "BLOCK3", "BLOCK5", "BLOCK6")
sessionID = "SESSION_ID"
trialLatency = "TRIAL_LATENCY"
trialError = "TRIAL_ERROR"
vError = 1
vExtreme = 2
vStd = 1
myTbl <- tbl_df(myData)
require(dplyr)
myTbl <- tbl_df(myData)
myTbl
myTbl <- group_by(tbl_df(myData), SESSION_ID)
myTbl
byPart <- filter(myTbl, TRIAL_LATENCY > 180 & TRIAL_LATENCY < 10000, TRIAL_ERROR == 0, BLOCK_NAME %in% TRIAL_BLOCKS) %>%
summarise(N = length(TRIAL_LATENCY),
meanRT = mean(TRIAL_LATENCY),
mySD = sd(TRIAL_LATENCY),
mySE = sd(TRIAL_LATENCY)/sqrt(length(TRIAL_LATENCY)))
names(myData)[names(myData) == trialLatency] <- "TRIAL_LATENCY"
names(myData)[names(myData) == trialError] <- "TRIAL_ERROR"
names(myData)[names(myData) == blockName] <- "BLOCK_NAME"
names(myData)[names(myData) == sessionID] <- "SESSION_ID"
byPart <- filter(myTbl, TRIAL_LATENCY > 180 & TRIAL_LATENCY < 10000, TRIAL_ERROR == 0, BLOCK_NAME %in% TRIAL_BLOCKS) %>%
summarise(N = length(TRIAL_LATENCY),
meanRT = mean(TRIAL_LATENCY),
mySD = sd(TRIAL_LATENCY),
mySE = sd(TRIAL_LATENCY)/sqrt(length(TRIAL_LATENCY)))
myDataCongFirst <- IATData[IATData$isCongruentFirst == 1, ]
myData = myDataCongFirst
blockName = "BLOCK_NAME_S"
trialBlocks = c("BLOCK2", "BLOCK3", "BLOCK5", "BLOCK6")
sessionID = "SESSION_ID"
trialLatency = "TRIAL_LATENCY"
trialError = "TRIAL_ERROR"
vError = 1
vExtreme = 2
vStd = 1
names(myData)[names(myData) == trialLatency] <- "TRIAL_LATENCY"
names(myData)[names(myData) == trialError] <- "TRIAL_ERROR"
names(myData)[names(myData) == blockName] <- "BLOCK_NAME"
names(myData)[names(myData) == sessionID] <- "SESSION_ID"
myTbl <- group_by(tbl_df(myData), SESSION_ID)
myTbl
byPart <- filter(myTbl, TRIAL_LATENCY > 180 & TRIAL_LATENCY < 10000, TRIAL_ERROR == 0, BLOCK_NAME %in% trialBlocks) %>%
summarise(N = length(TRIAL_LATENCY),
meanRT = mean(TRIAL_LATENCY),
mySD = sd(TRIAL_LATENCY),
mySE = sd(TRIAL_LATENCY)/sqrt(length(TRIAL_LATENCY)))
byPart
byPart$SESSION_ID <- factor(byPart$SESSION_ID, levels = byPart[order(byPart$meanRT),]$SESSION_ID)
p <- ggplot(byPart, aes(x = SESSION_ID, y = meanRT)) + geom_errorbar(aes(ymin = meanRT - 2*mySE, ymax = meanRT + 2*mySE), width = 0)
require(ggplot2)
p <- ggplot(byPart, aes(x = SESSION_ID, y = meanRT)) + geom_errorbar(aes(ymin = meanRT - 2*mySE, ymax = meanRT + 2*mySE), width = 0)
p <- p + geom_line() + geom_point() + coord_flip() + theme_bw()
suppressMessages(print(p))
p <- p + geom_line() + geom_point() + coord_flip() + theme_bw() + labs(x = "Session ID", y = "Mean Reaction Time")
suppressMessages(print(p))
names(myData)[names(myData) == trialLatency] <- "TRIAL_LATENCY"
names(myData)[names(myData) == trialError] <- "TRIAL_ERROR"
names(myData)[names(myData) == sessionID] <- "SESSION_ID"
myTbl <- group_by(tbl_df(myData), SESSION_ID)
byPart <- filter(myTbl, TRIAL_LATENCY > 180 & TRIAL_LATENCY < 10000) %>%
summarise(propErrors = sum(TRIAL_ERROR == 1)/length(TRIAL_ERROR))
byItemErr$itemName <- factor(byItemErr$itemName, levels = byItemErr[order(byItemErr$propErrors),]$itemName)
byItemErr <- filter(myTbl, TRIAL_LATENCY > 180 & TRIAL_LATENCY < 10000) %>%
summarise(propErrors = sum(TRIAL_ERROR == 1)/length(TRIAL_ERROR))
byItemErr$itemName <- factor(byItemErr$itemName, levels = byItemErr[order(byItemErr$propErrors),]$itemName)
byItemErr
myMean <- mean(byItemErr$propErrors)
myMean
p <- ggplot(byItemErr, aes(x = itemName, y = propErrors)) + geom_bar(fill = "dark gray", stat = "identity") + geom_hline(aes(yintercept = mean(propErrors)), size = 1.5)
p <- p + coord_flip() + theme_bw()
suppressMessages(suppressWarnings(print(p)))
byItemErr
byItemErr$itemName <- factor(byItemErr$itemName, levels = byItemErr[order(byItemErr$propErrors),]$itemName)
byItemErr$itemName
itemName
myData
myTbl
itemName <- "TRIAL_NAME_S"
byItemErr$itemName <- factor(byItemErr$itemName, levels = byItemErr[order(byItemErr$propErrors),]$itemName)
byItemErr$itemName
itemName
byItemErr$itemName <- factor(byItemErr[, itemName], levels = byItemErr[order(byItemErr$propErrors),][, itemName])
byItemErr[, itemName]
byItemErr <- filter(myTbl, TRIAL_LATENCY > 180 & TRIAL_LATENCY < 10000) %>%
summarise(propErrors = sum(TRIAL_ERROR == 1)/length(TRIAL_ERROR))
byItemErr
names(myData)[names(myData) == itemName] <- "ITEM"
myTbl <- group_by(tbl_df(myData), ITEM)
byItemErr <- filter(myTbl, TRIAL_LATENCY > 180 & TRIAL_LATENCY < 10000) %>%
summarise(propErrors = sum(TRIAL_ERROR == 1)/length(TRIAL_ERROR))
byItemErr$itemName <- factor(byItemErr$ITEM, levels = byItemErr[order(byItemErr$propErrors),]$ITEM)
byItemErr
names(myData)[names(myData) == trialLatency] <- "TRIAL_LATENCY"
names(myData)[names(myData) == trialError] <- "TRIAL_ERROR"
names(myData)[names(myData) == sessionID] <- "SESSION_ID"
names(myData)[names(myData) == itemName] <- "ITEM"
myTbl <- group_by(tbl_df(myData), ITEM)
byItemErr <- filter(myTbl, TRIAL_LATENCY > 180 & TRIAL_LATENCY < 10000) %>%
summarise(propErrors = sum(TRIAL_ERROR == 1)/length(TRIAL_ERROR))
byItemErr
byItemErr$ITEM <- factor(byItemErr$ITEM, levels = byItemErr[order(byItemErr$propErrors),]$ITEM)
byItemErr
myMean <- mean(byItemErr$propErrors)
p <- ggplot(byItemErr, aes(x = ITEM, y = propErrors)) + geom_bar(fill = "dark gray", stat = "identity")
p <- p + geom_hline(aes(yintercept = mean(propErrors)), size = 1.5)
p <- p + coord_flip() + theme_bw()
suppressMessages(suppressWarnings(print(p)))
myTbl <- group_by(tbl_df(myData), ITEM)
byItem <- filter(myTbl, TRIAL_LATENCY > 180 & TRIAL_LATENCY < 10000, TRIAL_ERROR == 0, BLOCK_NAME %in% trialBlocks) %>%
summarise(N = length(TRIAL_LATENCY),
meanRT = mean(TRIAL_LATENCY),
mySD = sd(TRIAL_LATENCY),
mySE = sd(TRIAL_LATENCY)/sqrt(length(TRIAL_LATENCY)))
byItem$ITEM <- factor(byItem$ITEM, levels = byItem[order(byItem$meanRT), ]$ITEM)
p <- ggplot(byItem, aes(x = ITEM, y = meanRT)) + geom_errorbar(aes(ymin = meanRT - 2*mySE, ymax = meanRT + 2*mySE), width = 0)
p <- p + geom_line() + geom_point() + coord_flip() + theme_bw()
suppressMessages(print(p))
p <- p + geom_line() + geom_point() + coord_flip() + theme_bw() + labs(x = "Item", y = "Mean Reaction Time")
suppressMessages(print(p))
library(IAT)
p <- ggplot(byPart, aes_string(x = "SESSION_ID", y = "meanRT")) + geom_errorbar(aes(ymin = meanRT - 2*mySE, ymax = meanRT + 2*mySE), width = 0)
p <- p + geom_line() + geom_point() + coord_flip() + theme_bw() + labs(x = "Session ID", y = "Mean Reaction Time")
suppressMessages(print(p))
options(repos = c(CRAN="http://cran.r-project.org"))
library(IAT)
IATData
rm(list = ls())
library(IAT)
head(IATData)
library(IAT)
data("IATData", envir = .BaseNamespaceEnv)
library(IAT)
?cleanIAT
library(IAT)
library(IAT)