-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.Rhistory
512 lines (512 loc) · 20.6 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
data$pathBIAS[data$BIAS == 'PATHBIAS'] = 1
data$pathBIAS[data$BIAS == 'MANNERBIAS'] = 0
if (doExtension){
data$pathEXT[data$EXT == 'PATHBIAS'] = 1
data$pathEXT[data$EXT == 'MANNERBIAS'] = 0
}
dim(data)
#Remove NA levels (really elsewhere we should document what happened to those lines!)
data <- data[!is.na(data$EXPERIMENT), ]
data <- data[!is.na(data$TRIAL), ]
if (doExtension){
data <- data[!is.na(data$EXT),]
}else{
data <- data
}
dim(data)
# #Debugging the binomial testing
# for (cond in unique(data$EXPERIMENT))
# {
# for (trial in unique(data$TRIAL))
# {
# n = length(data[data$EXPERIMENT == cond & data$TRIAL == trial,]$pathEXT)
# x = sum(data[data$EXPERIMENT == cond & data$TRIAL == trial,]$pathEXT, na.rm=TRUE)
# test = prop.test(x, n, conf.level=0.95)
# #plotData$intLower[plotData$cond == cond & plotData$verb == trial] = test$conf.int[1]
# #plotData$intUpper[plotData$cond == cond & plotData$verb == trial] = test$conf.int[2]
# print('set')
# print(x)
# print(n)
# print(test$conf.int[1])
# print(test$conf.int[2])
# }
# }
#Rename conds for prettiness
if (!doExtension) {
data$xEXPERIMENT[data$EXPERIMENT == 'MannerOfMotionCondition'] <- "Manner"
data$xEXPERIMENT[data$EXPERIMENT == 'PathCondition'] <- "Path"
data$EXPERIMENT <- data$xEXPERIMENT
}
makePlot = function(ydata, ylab, title="")
{
#aggregate data to get mean per trial per condition
plotData = aggregate(x = list(pathmean = ydata), by = list( cond = data$EXPERIMENT, verb = data$TRIAL), FUN = mean)
#get the binomial conf.intervals per condition per trial
for (cond in unique(data$EXPERIMENT))
{
for (trial in unique(data$TRIAL))
{
n = length(ydata[data$EXPERIMENT == cond & data$TRIAL == trial])
x = sum(ydata[data$EXPERIMENT == cond & data$TRIAL == trial])
test = prop.test(x, n, conf.level=0.95)
plotData$intLower[plotData$cond == cond & plotData$verb == trial] = test$conf.int[1]
plotData$intUpper[plotData$cond == cond & plotData$verb == trial] = test$conf.int[2]
#print(test$conf.int[1])
#print(test$conf.int[2])
#print(n)
#print(x)
}
}
print(plotData)
#make a plot with ggplot
pd <- position_dodge(0.1)
ggplot(plotData, aes(x=verb, y=pathmean, colour=cond, group=cond, ymax = 1)) +
geom_errorbar(aes(ymin=intLower, ymax=intUpper), colour="black", width=.1, position=pd) +
geom_line(position=pd) +
ylab(ylab) +
geom_point(position=pd, size=3) +
coord_cartesian(ylim=c(0,1)) +
ggtitle(title)
#scale_colour_manual(values = c("green","red"),
#name="",
#labels=c("Manner", "Path")) +
}
makePlot(data$pathTEST, "Proportion of Effect Responses", "Responses after training")
makePlot(data$pathBIAS, 'Proportion of EFFECT responses', 'Bias (1st presentation) responses')
if (doExtension) {
makePlot(data$pathEXT, 'Proportion of PATH responses', 'Bias responses - new domain')
}
#Now let's make some bar graphs too!
makeBar = function(ydata, ylab, title="", colors="Dark2")
{
plotData = NULL
#Aggregate mean/condition
plotData = aggregate(x = list(pathmean = ydata), by = list( cond = data$EXPERIMENT), FUN = mean)
#get the binomial conf.intervals per condition per trial
for (cond in unique(data$EXPERIMENT))
{
n = length(ydata[data$EXPERIMENT == cond])
x = sum(ydata[data$EXPERIMENT == cond])
test = prop.test(x, n, conf.level=0.95)
plotData$intLower[plotData$cond == cond] = test$conf.int[1]
plotData$intUpper[plotData$cond == cond] = test$conf.int[2]
}
ggplot(plotData, aes(x=cond, y=pathmean, fill=cond)) +
geom_bar(stat="identity") +
geom_errorbar(aes(ymin=intLower, ymax=intUpper), colour="black", width=.1) +
coord_cartesian(ylim=c(0,1))+
ylab(ylab)+
xlab('')+
theme_bw()+
theme(legend.position="none")+
scale_fill_brewer(palette=colors) +
ggtitle(title)
}
if (doExtension){
makeBar(data$pathTEST, 'Proportion of EFFECT responses', colors="Greens")
ggsave('AE_test.png', width=4, height=4)
makeBar(data$pathBIAS, 'Proportion of EFFECT responses', colors="Greens")
ggsave('AE_bias.png', width=4, height=4)
makeBar(data$pathEXT, 'Proportion of PATH responses', colors="Blues")
ggsave('AE_ext.png', width=4, height=4)
} else{
makeBar(data$pathTEST, 'Proportion of PATH responses', colors="Accent")
ggsave('MP_test.png', width=4, height=4)
makeBar(data$pathBIAS, 'Proportion of PATH responses', colors="Accent")
ggsave('MP_bias.png', width=4, height=4)
}
#set path
setwd("/Users/mekline/Dropbox/_Projects/PrimingMannerPath/MannerPathPriming/Analysis/")
#load libraries
library(ggplot2)
#CLear history!!!
rm(list=ls())
#load data
data = read.csv('all.csv', sep = ",", header = T)
doExtension = 0
#Drop participants
data <- data[!is.na(data$INCDECISION),]
data <- data[data$INCDECISION == 1,]
length(unique(data$SUBNUM))
#new variables
data$pathTEST[data$TEST == 'PATHBIAS'] = 1
data$pathTEST[data$TEST == 'MANNERBIAS'] = 0
data$pathBIAS[data$BIAS == 'PATHBIAS'] = 1
data$pathBIAS[data$BIAS == 'MANNERBIAS'] = 0
if (doExtension){
data$pathEXT[data$EXT == 'PATHBIAS'] = 1
data$pathEXT[data$EXT == 'MANNERBIAS'] = 0
}
dim(data)
#Remove NA levels (really elsewhere we should document what happened to those lines!)
data <- data[!is.na(data$EXPERIMENT), ]
data <- data[!is.na(data$TRIAL), ]
if (doExtension){
data <- data[!is.na(data$EXT),]
}else{
data <- data
}
dim(data)
# #Debugging the binomial testing
# for (cond in unique(data$EXPERIMENT))
# {
# for (trial in unique(data$TRIAL))
# {
# n = length(data[data$EXPERIMENT == cond & data$TRIAL == trial,]$pathEXT)
# x = sum(data[data$EXPERIMENT == cond & data$TRIAL == trial,]$pathEXT, na.rm=TRUE)
# test = prop.test(x, n, conf.level=0.95)
# #plotData$intLower[plotData$cond == cond & plotData$verb == trial] = test$conf.int[1]
# #plotData$intUpper[plotData$cond == cond & plotData$verb == trial] = test$conf.int[2]
# print('set')
# print(x)
# print(n)
# print(test$conf.int[1])
# print(test$conf.int[2])
# }
# }
#Rename conds for prettiness
if (!doExtension) {
data$xEXPERIMENT[data$EXPERIMENT == 'MannerOfMotionCondition'] <- "Manner"
data$xEXPERIMENT[data$EXPERIMENT == 'PathCondition'] <- "Path"
data$EXPERIMENT <- data$xEXPERIMENT
}
makePlot = function(ydata, ylab, title="")
{
#aggregate data to get mean per trial per condition
plotData = aggregate(x = list(pathmean = ydata), by = list( cond = data$EXPERIMENT, verb = data$TRIAL), FUN = mean)
#get the binomial conf.intervals per condition per trial
for (cond in unique(data$EXPERIMENT))
{
for (trial in unique(data$TRIAL))
{
n = length(ydata[data$EXPERIMENT == cond & data$TRIAL == trial])
x = sum(ydata[data$EXPERIMENT == cond & data$TRIAL == trial])
test = prop.test(x, n, conf.level=0.95)
plotData$intLower[plotData$cond == cond & plotData$verb == trial] = test$conf.int[1]
plotData$intUpper[plotData$cond == cond & plotData$verb == trial] = test$conf.int[2]
#print(test$conf.int[1])
#print(test$conf.int[2])
#print(n)
#print(x)
}
}
print(plotData)
#make a plot with ggplot
pd <- position_dodge(0.1)
ggplot(plotData, aes(x=verb, y=pathmean, colour=cond, group=cond, ymax = 1)) +
geom_errorbar(aes(ymin=intLower, ymax=intUpper), colour="black", width=.1, position=pd) +
geom_line(position=pd) +
ylab(ylab) +
geom_point(position=pd, size=3) +
coord_cartesian(ylim=c(0,1)) +
ggtitle(title)
#scale_colour_manual(values = c("green","red"),
#name="",
#labels=c("Manner", "Path")) +
}
makePlot(data$pathTEST, "Proportion of Effect Responses", "Responses after training")
makePlot(data$pathBIAS, 'Proportion of EFFECT responses', 'Bias (1st presentation) responses')
if (doExtension) {
makePlot(data$pathEXT, 'Proportion of PATH responses', 'Bias responses - new domain')
}
#Now let's make some bar graphs too!
makeBar = function(ydata, ylab, title="", colors="Dark2")
{
plotData = NULL
#Aggregate mean/condition
plotData = aggregate(x = list(pathmean = ydata), by = list( cond = data$EXPERIMENT), FUN = mean)
#get the binomial conf.intervals per condition per trial
for (cond in unique(data$EXPERIMENT))
{
n = length(ydata[data$EXPERIMENT == cond])
x = sum(ydata[data$EXPERIMENT == cond])
test = prop.test(x, n, conf.level=0.95)
plotData$intLower[plotData$cond == cond] = test$conf.int[1]
plotData$intUpper[plotData$cond == cond] = test$conf.int[2]
}
ggplot(plotData, aes(x=cond, y=pathmean, fill=cond)) +
geom_bar(stat="identity") +
geom_errorbar(aes(ymin=intLower, ymax=intUpper), colour="black", width=.1) +
coord_cartesian(ylim=c(0,1))+
ylab(ylab)+
xlab('')+
theme_bw()+
theme(legend.position="none")+
scale_fill_brewer(palette=colors) +
ggtitle(title)
}
if (doExtension){
makeBar(data$pathTEST, 'Proportion of EFFECT responses', colors="Greens")
ggsave('AE_test.png', width=4, height=4)
makeBar(data$pathBIAS, 'Proportion of EFFECT responses', colors="Greens")
ggsave('AE_bias.png', width=4, height=4)
makeBar(data$pathEXT, 'Proportion of PATH responses', colors="Blues")
ggsave('AE_ext.png', width=4, height=4)
} else{
makeBar(data$pathTEST, 'Proportion of PATH responses', colors="Blues")
ggsave('MP_test.png', width=4, height=4)
makeBar(data$pathBIAS, 'Proportion of PATH responses', colors="Blues")
ggsave('MP_bias.png', width=4, height=4)
}
setwd("~/Dropbox/_Projects/PrimingMannerPath/MannerPathPriming/Analysis/scripts")
#set directories; might need to change this on your comp!
repodir = "/Users/mekline/Dropbox/_Projects/PrimingMannerPath/MannerPathPriming/"
adir = paste(repodir, "Analysis/", sep="")
ddir = paste(repodir, "MPP Presentation Stimuli and Trial data/data/" , sep="")
#name of info file
nameMetaFile = paste(repodir,"MannerPath_data.csv",sep="")
#----------------------------------------------------------------------------------
#get all .dat files in the directory
files = list.files(ddir, pattern = ".dat$")
#create an empty error vector
error_files = c()
#counter to count at which row in the data frame we are
counter = 1
#generate an empty data frame for output
output = data.frame(EXPERIMENT = '', TRIAL = '',BIAS = '',TEST = '', SUBNUM = '', DAYSOLD = '', AGEYEARS = '', INCDECISION = '', EXT = '', stringsAsFactors=F)
#load the info data file
setwd(adir)
meta = read.csv(nameMetaFile, sep = ",", header = T)
#loop over files (participants) and the rows in the file
setwd(ddir)
for (j in 1:length(files))
{
file = files[j]
#print(file)
#read in the file
#If instead of a table we get an error message, move on!
data = try(read.table(file, sep = ",", header = T, fill=T)) #Fill adds in NAs for blank cells :)
if (length(data) == 1) {next}
#Hack for the consolidated data folder - if it's a non-extension session, skip it! (And drop kids who didn't complete any trials...)
if (dim(data)[2] < 50 || dim(data)[1] < 2) {next}
#test if there is data in that file, else place in the error vector
if (length(data[,1]) > 0)
{
#get info for current participant
info = meta[meta$Participant.. == data$SubjectNo[1],]
for (row in (length(data[,1])-7):length(data[,1]))
{
#store experiment and trialnumber
#output[counter,1] = toString(data$Experiment[row])
#whoopsy, get it from meta I guess!
print(info$Verb.Condition)
output[counter,1] = toString(info$Verb.Condition)
output[counter,2] = data$trialNo[row]
#transform variables into BIAS and TEST
if (data$mannerSideBias[row] == "L" & data$kidResponseBias[row] == "z") output[counter,3] = "MANNERBIAS"
if (data$pathSideBias[row] == "R" & data$kidResponseBias[row] == "c") output[counter,3] = "PATHBIAS"
if (data$mannerSideBias[row] == "R" & data$kidResponseBias[row] == "c") output[counter,3] = "MANNERBIAS"
if (data$pathSideBias[row] == "L" & data$kidResponseBias[row] == "z") output[counter,3] = "PATHBIAS"
if (data$mannerSideTest[row] == "L" & data$kidResponseTest[row] == "z") output[counter,4] = "MANNERBIAS"
if (data$pathSideTest[row] == "R" & data$kidResponseTest[row] == "c") output[counter,4] = "PATHBIAS"
if (data$mannerSideTest[row] == "R" & data$kidResponseTest[row] == "c") output[counter,4] = "MANNERBIAS"
if (data$pathSideTest[row] == "L" & data$kidResponseTest[row] == "z") output[counter,4] = "PATHBIAS"
# transform extension
if (data$extMannerSide[row] == "L" & data$extAnswer[row] == "z" & !is.na(data$extMannerSide[row])) output[counter,9] = "MANNERBIAS"
if (data$extPathSide[row] == "R" & data$extAnswer[row] == "c"& !is.na(data$extPathSide[row])) output[counter,9] = "PATHBIAS"
if (data$extMannerSide[row] == "R" & data$extAnswer[row] == "c"& !is.na(data$extMannerSide[row])) output[counter,9] = "MANNERBIAS"
if (data$extPathSide[row] == "L" & data$extAnswer[row] == "z" & !is.na(data$extPathSide[row])) output[counter,9] = "PATHBIAS"
#Store subject number, days old, age in years and inclusion criteria
output[counter,5] = data$SubjectNo[row]
output[counter,6] = info$Days.Old
output[counter,7] = info$Age.Years
output[counter,8] = info$Inclusion.Decision
#next row
counter = counter + 1
#if(data$SubjectNo[row] == 54) print(data)
}
}
else
{append(error_files, file)}
}
#save data frame
setwd(adir)
write.csv(output, file = paste("all_ext", ".csv", sep = ""))
#show errors
error_files
#set directories; might need to change this on your comp!
repodir = "/Users/mekline/Dropbox/_Projects/PrimingMannerPath/MannerPathPriming/"
adir = paste(repodir, "Analysis/", sep="")
ddir = paste(repodir, "MPP_Stim_and_Data/data/" , sep="")
#name of info file
nameMetaFile = paste(repodir,"MannerPath_data.csv",sep="")
#----------------------------------------------------------------------------------
#get all .dat files in the directory
files = list.files(ddir, pattern = ".dat$")
#create an empty error vector
error_files = c()
#counter to count at which row in the data frame we are
counter = 1
#generate an empty data frame for output
output = data.frame(EXPERIMENT = '', TRIAL = '',BIAS = '',TEST = '', SUBNUM = '', DAYSOLD = '', AGEYEARS = '', INCDECISION = '', EXT = '', stringsAsFactors=F)
#load the info data file
setwd(adir)
meta = read.csv(nameMetaFile, sep = ",", header = T)
#loop over files (participants) and the rows in the file
setwd(ddir)
for (j in 1:length(files))
{
file = files[j]
#print(file)
#read in the file
#If instead of a table we get an error message, move on!
data = try(read.table(file, sep = ",", header = T, fill=T)) #Fill adds in NAs for blank cells :)
if (length(data) == 1) {next}
#Hack for the consolidated data folder - if it's a non-extension session, skip it! (And drop kids who didn't complete any trials...)
if (dim(data)[2] < 50 || dim(data)[1] < 2) {next}
#test if there is data in that file, else place in the error vector
if (length(data[,1]) > 0)
{
#get info for current participant
info = meta[meta$Participant.. == data$SubjectNo[1],]
for (row in (length(data[,1])-7):length(data[,1]))
{
#store experiment and trialnumber
#output[counter,1] = toString(data$Experiment[row])
#whoopsy, get it from meta I guess!
print(info$Verb.Condition)
output[counter,1] = toString(info$Verb.Condition)
output[counter,2] = data$trialNo[row]
#transform variables into BIAS and TEST
if (data$mannerSideBias[row] == "L" & data$kidResponseBias[row] == "z") output[counter,3] = "MANNERBIAS"
if (data$pathSideBias[row] == "R" & data$kidResponseBias[row] == "c") output[counter,3] = "PATHBIAS"
if (data$mannerSideBias[row] == "R" & data$kidResponseBias[row] == "c") output[counter,3] = "MANNERBIAS"
if (data$pathSideBias[row] == "L" & data$kidResponseBias[row] == "z") output[counter,3] = "PATHBIAS"
if (data$mannerSideTest[row] == "L" & data$kidResponseTest[row] == "z") output[counter,4] = "MANNERBIAS"
if (data$pathSideTest[row] == "R" & data$kidResponseTest[row] == "c") output[counter,4] = "PATHBIAS"
if (data$mannerSideTest[row] == "R" & data$kidResponseTest[row] == "c") output[counter,4] = "MANNERBIAS"
if (data$pathSideTest[row] == "L" & data$kidResponseTest[row] == "z") output[counter,4] = "PATHBIAS"
# transform extension
if (data$extMannerSide[row] == "L" & data$extAnswer[row] == "z" & !is.na(data$extMannerSide[row])) output[counter,9] = "MANNERBIAS"
if (data$extPathSide[row] == "R" & data$extAnswer[row] == "c"& !is.na(data$extPathSide[row])) output[counter,9] = "PATHBIAS"
if (data$extMannerSide[row] == "R" & data$extAnswer[row] == "c"& !is.na(data$extMannerSide[row])) output[counter,9] = "MANNERBIAS"
if (data$extPathSide[row] == "L" & data$extAnswer[row] == "z" & !is.na(data$extPathSide[row])) output[counter,9] = "PATHBIAS"
#Store subject number, days old, age in years and inclusion criteria
output[counter,5] = data$SubjectNo[row]
output[counter,6] = info$Days.Old
output[counter,7] = info$Age.Years
output[counter,8] = info$Inclusion.Decision
#next row
counter = counter + 1
#if(data$SubjectNo[row] == 54) print(data)
}
}
else
{append(error_files, file)}
}
#save data frame
setwd(adir)
write.csv(output, file = paste("all_ext", ".csv", sep = ""))
#show errors
error_files
# #set directory
# dir = setwd("~/Documents/R_stuff/MPP")
# #name of info file
# nameMetaFile = "MannerPath_data.csv"
#
#set directories; might need to change this on your comp!
repodir = "/Users/mekline/Dropbox/_Projects/PrimingMannerPath/MannerPathPriming/"
adir = paste(repodir, "Analysis/", sep="")
ddir = paste(repodir, "MPP_Stim_and_Data/data/" , sep="")
#name of info file
nameMetaFile = paste(repodir,"MannerPath_data.csv",sep="")
####################################################################################
####################################################################################
#get all .dat files in the directory
files = list.files(ddir, pattern = ".dat$")
#create an empty error vector
error_files = c()
#generate an empty data frame for output
output = data.frame(EXPERIMENT = '', TRIAL = '',BIAS = '',TEST = '', SUBNUM = '', DAYSOLD = '', AGEYEARS = '', INCDECISION = '', stringsAsFactors=F)
#load the info data file
setwd(adir)
meta = read.csv(nameMetaFile, sep = ",", header = T)
setwd(ddir)
#loop over files (participants) and the rows in the file
#MK hack - MPP_1 and MPP_2 are formatted differently, so I hid them in a subfolder!
#And currently, this skips the .dat files of all extension participants (anyone with extra columns...)
i=1 #This counter keeps track of the size of the output file (since participants have unpredictable # of trials)
for (j in 1:length(files))
{
file = files[j]
#read in the file
#If instead of a table we get an error message, move on!
data = try(read.table(file, sep = ",", header = T))
if (length(data) == 1) {next}
#test if there is data in that file, else place in the error vector
if (length(data[,1]) > 0)
{
#get info for current participant
info = meta[meta$Participant.. == data$SubjectNo[1],]
for (row in 1:length(data[,1]))
{
#store experiment and trialnumber
output[i,1] = toString(data$Experiment[row])
output[i,2] = data$trialNo[row]
#transform variables into BIAS and TEST
if (data$mannerSideBias[row] == "L" & data$kidResponseBias[row] == "z") output[i,3] = "MANNERBIAS"
if (data$pathSideBias[row] == "R" & data$kidResponseBias[row] == "c") output[i,3] = "PATHBIAS"
if (data$mannerSideBias[row] == "R" & data$kidResponseBias[row] == "c") output[i,3] = "MANNERBIAS"
if (data$pathSideBias[row] == "L" & data$kidResponseBias[row] == "z") output[i,3] = "PATHBIAS"
if (data$mannerSideTest[row] == "L" & data$kidResponseTest[row] == "z") output[i,4] = "MANNERBIAS"
if (data$pathSideTest[row] == "R" & data$kidResponseTest[row] == "c") output[i,4] = "PATHBIAS"
if (data$mannerSideTest[row] == "R" & data$kidResponseTest[row] == "c") output[i,4] = "MANNERBIAS"
if (data$pathSideTest[row] == "L" & data$kidResponseTest[row] == "z") output[i,4] = "PATHBIAS"
#Store subject number, days old, age in years and inclusion criteria
output[i,5] = data$SubjectNo[row]
output[i,6] = info$Days.Old
output[i,7] = info$Age.Years
output[i,8] = info$Inclusion.Decision
i = i+1 #Next row
}
}
else
{append(error_files, file)}
}
#save data frame
setwd(adir)
write.csv(output, file = paste("all", ".csv", sep = ""))
#show errors
error_files
#To get last unique rows...
#d[ !duplicated(d$x,fromLast=TRUE), ]
1+2
library(swirl)
install.packages("swirl")
library(swirl)
ls()
rm(list=ls())
swirl()
1 + 2
foo = 1
help(t.test)
library(dplyr)
library(tidyr)
# This file is going to have the full analysis pipeline for the MannerPath studies!
#It will pull data from the main MannerPath_Data.csv and from the trial data
#(Repo/MPP_Stim_and_Data/Data) from each child. There are (currently) two different
#experiments/conditions in the dataset:
#
# MannerPath - the original version (MP learning/bias), with no extension version
# ActionEffect+Extend - AE learning/bias, followed by MP trials which have only bias phase
# Just for super awesome fun times, subjects before #77 in AE-Extend have a variety of
# slightly different matlab outputs, and some of them only have AE data but no extension.
# Hence data cleaning/reformatting is...a bit messy.
#
# See #TODO for unfinished places
# See line 140ish for analysis
######
# LIBRARIES, FILES, DIRECTORIES
######
library(dplyr)
library(tidyr)
library(ggplot2)
library(lme4)
library(pwr)
rm(list=ls()) #Clear any lingering variables
#Set directories; might need to change this on your computer!
#repodir = "C:/Users/Anna/Documents/GitHub/MannerPathPriming/"
repodir = "/Users/mekline/Dropbox/_Projects/PrimingMannerPath/MannerPathPriming/"
adir = paste(repodir, "Analysis/", sep="")
ddir = paste(repodir, "MPP_Stim_and_Data/Data/" , sep="")
setwd(repodir)