-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2_sol-ichart-processing.Rmd
More file actions
826 lines (654 loc) · 30 KB
/
Copy path2_sol-ichart-processing.Rmd
File metadata and controls
826 lines (654 loc) · 30 KB
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
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
---
title: "SOL Data Processing"
author: "Kyle MacDonald"
date: "February 5, 2016"
output: html_document
---
This script takes in raw eye movement data and processes it. The outputs are:
1. Data frame with Accuracy and RT measures at the participant-level.
4. Data frame with Accuracy and RT measures at the trial-level.
2. Data frame with cleaned eye movement data for plotting.
3. Data frame with exclusionary information.
# Data processing
```{r chunk_options}
rm(list=ls())
knitr::opts_chunk$set(warning=FALSE, message=FALSE, sanitize = T,
fig.height=8, fig.width=10, echo=F, cache = T)
```
```{r}
source("../helper_functions//libraries_v_3.6.R")
source("../helper_functions//useful.R")
library(magrittr); library(kmr); library(tidyverse)
```
## Read in data
```{r}
# Demographic data
sol_demo <- read.csv("../../data/demographics/sol_demo_all.csv", stringsAsFactors = F) %>%
mutate(Sub.Num = as.character(Sub.Num))
sol_demo$Sub.Num <- as.character(sol_demo$Sub.Num)
# eye movement data
iChart <- read.csv("../../data/processed_data/processed_em_data/sol-ichart-merged-post-gating.csv",
check.names=F, stringsAsFactors=F) %>%
mutate(Sub.Num = as.character(Sub.Num))
# Stimuli information
sol_target_signs_df <- read.csv("../../data/demographics/target_sign_lengths_all.csv")
```
## Filter dataset
Filter out trials/participants that should not go into analyses based on preset exclusionary criteria: a) didn’t know signs in the tas and b) not enough ASL exposur.
```{r}
include <- sol_demo %>%
filter(include == "yes") %>%
select(Sub.Num, include,
reason_excluded, stimuli,
age_code, signs_produced,
hearing_status_participant) %>%
mutate(Sub.Num = as.character(Sub.Num))
iChart <- left_join(iChart, include, by = c("Sub.Num", "stimuli")) %>%
filter(include == "yes")
```
## Remove unknown signs
Make a clean target signs variable for filtering later on.
```{r}
targets <- c("juice", "cookie", "cup", "ball", "shoe", "kitty",
"doll", "teddy", "book", "birdy", "car", "sock")
make_clean_target <- function (target_image, targets) {
target_img_clean <- targets[str_detect(target_image, targets)]
return(target_img_clean)
}
iChart$clean_target_img <- unlist(sapply(iChart$Target.Image,
function (x) make_clean_target(x, targets)))
```
Add unknown signs variable. Taken from the sol_demo data frame.
```{r}
ss_unknown_signs <- sol_demo %>%
filter(include == "yes") %>%
select(Sub.Num, parent_report_unknown_signs) %>%
mutate(parent_report_unknown_signs = ifelse(is.na(parent_report_unknown_signs) == T,
"none", parent_report_unknown_signs))
iChart <- left_join(iChart, ss_unknown_signs, by = "Sub.Num")
```
Now we can filter the iChart, removing the "unknown" signs.
```{r}
# get number of trial for each participant prior to filtering
ss_trials_df <- iChart %>%
group_by(Sub.Num, parent_report_unknown_signs) %>%
dplyr::summarise(Trials = n())
```
Flag and remove unknown trials
```{r}
iChart %<>%
mutate(unknown_sign = str_detect(string = parent_report_unknown_signs,
pattern = clean_target_img)) %>%
filter(unknown_sign == FALSE)
```
Check to make sure our filtering worked correctly:
```{r}
post_filter_n <- iChart %>%
group_by(Sub.Num) %>%
dplyr::summarise(Trials = n()) %>%
select(Trials)
ss_trials_df$post_filter <- post_filter_n$Trials
ss_trials_df %<>% mutate(trials_removed = as.integer(Trials) - as.integer(post_filter))
# Get total number of trials removed because of unknown signs
sum(ss_trials_df$trials_removed)
```
## Remove prescreened out trials
```{r}
ss_prescreened <- iChart %>%
group_by(Sub.Num) %>%
filter(Prescreen.Notes != "") %>%
dplyr::summarise(num_prescreened = n())
ss_trials_df <- left_join(ss_trials_df, ss_prescreened, by = "Sub.Num")
ss_trials_df %<>%
mutate(num_prescreened = as.numeric(num_prescreened),
num_prescreened = ifelse(is.na(num_prescreened), 0, num_prescreened),
good_trials = Trials - (trials_removed + num_prescreened))
```
Filter
```{r}
iChart <- filter(iChart, Prescreen.Notes == "")
```
## Remove participants for having too few trials
We define too few trials as less than or equal to 25% of the total number of
trials in the task.
```{r}
total_trials <- 32
trials_cut_point <- total_trials * .25
trials_filter <- ss_trials_df %>%
mutate(exclude_few_trials = ifelse(good_trials <= trials_cut_point,
"exclude", "include")) %>%
select(Sub.Num, good_trials, exclude_few_trials)
# get the number of participants removed by filter
trials_filter %>% group_by(exclude_few_trials) %>% dplyr::summarise(n())
# merge filtering information with iChart
iChart <- left_join(iChart, trials_filter, by = "Sub.Num")
# now filter
iChart <- filter(iChart, exclude_few_trials == "include")
```
### Get median split by age
```{r}
kids_age_descriptives <- iChart %>%
filter(age_code == "child") %>%
select(Sub.Num, Months) %>%
distinct() %>%
dplyr::summarise(median(Months),
max(Months),
min(Months),
sd(Months),
n())
# add median split variable to iChart
iChart$age_group <- ifelse(iChart$Months < kids_age_descriptives$`median(Months)`,
"< 27 Months",
ifelse(iChart$Months >= kids_age_descriptives$`median(Months)` &
iChart$Months <= kids_age_descriptives$`max(Months)`,
">= 27 Months",
"Adults"))
iChart %<>% mutate(age_group_collapsed = ifelse(age_group == "Adults", "Adults", "Kids"))
gender_df <- iChart %>%
filter(age_code == "child") %>%
select(Sub.Num, Sex, age_group) %>%
unique() %>%
group_by(Sex, age_group) %>%
dplyr::summarise(count = n())
iChart %>% group_by(age_group) %>%
dplyr::summarise(count = n_distinct(Sub.Num),
mean_val = mean(Months),
min_val = min(Months),
max_val = max(Months)) %>%
knitr::kable()
```
### Process iChart
First, we need to process the data, keeping only those trials on which the child was looking at the signer at F0.
* C: Center
* D: Distractor
* T: Target
* A: Away
includeOffCenter == FALSE -> only include trials child was looking at center at F0
includeOffCenter == TRUE -> include trials child was looking at center, target, or distractor at F0
```{r}
iChart %>% group_by("0", Response) %>% dplyr::summarise(Trials = n())
# change all trials to "Vanilla"
iChart$Condition <- "Vanilla"
## define critical onset, change Cs to Ds and everything else to As
iChart <- defineOnsetSOL(iChart, critonset=0, end_critonset=300,
includeOffCenter = FALSE, includeWindow = FALSE)
iChart %>% group_by("0", Response) %>% dplyr::summarise(Trials = n())
```
### Flag C-T and C-D Trials
Datawiz does not tell us which shifts land on a target vs. a disctractor. So we need to use a function that flags each trial as one of the following:
* C_T: center to target
* C_D: center to distractor
* C-C: center to center (child leaves the signer, goes away, and comes back to signer)
* no_shift
* off_signer
```{r}
# apply fun to each row in our dataset to flag trial type
trial_types <- apply(iChart, 1, trial_type_fun, start = "0", end = "5000")
# merge trial type information with iChart
iChart <- cbind(iChart, trial_types)
iChart %>% group_by(trial_types) %>% dplyr::summarise(Trials = n())
```
Next, we compute statistics over long window 0-5000 ms. This will allow us to see a
distribution of RTs, which we will use to determine our analysis window.
First, for adults.
```{r get RT analysis window adults, warning=F, message=F, fig.height = 5}
iChart_adults <- filter(iChart, age_group == "Adults")
iChart_adults <- computeStatistics(iChart_adults, startWindow=0, endWindow=4000)
# get analyisis window where 90% of RTs occur for kids, include all shifts
rts_adults <- filter(iChart_adults, trial_types %in% c("C_T"))
analysis.window_adults <- quantile(rts_adults$RT, probs=c(0.05, 0.95), na.rm=T)
```
```{r}
ggplot(aes(RT), data = rts_adults) +
geom_histogram() +
labs(x = "RT (msec)",
title = "Analysis Window (Adults)") +
geom_vline(xintercept = analysis.window_adults[1], col="red",
lwd=1.5, linetype = "dashed") +
geom_vline(xintercept = analysis.window_adults[2], col="red",
lwd=1.5, linetype = "dashed") +
annotate("text", x = 2500, y = 30,
label = "Analysis Window \n (90% RTs)")
```
Now do the same for kids.
```{r get rt analysis window kids, warning=F, message=F, fig.height = 5}
iChart_kids <- filter(iChart, age_group != "Adults")
iChart_kids <- computeStatistics(iChart_kids, startWindow=0, endWindow=4000)
# get analyisis window where 90% of RTs occur for kids, include all shifts
rts <- filter(iChart_kids, trial_types %in% c("C_T"), age_group != "Adults")
analysis.window <- quantile(rts$RT, probs=c(0.05, 0.95), na.rm=T)
```
```{r}
ggplot(aes(x=RT), data=rts) +
geom_histogram() +
labs(x = "RT (msec)",
title = "Analysis Window (Kids)") +
geom_vline(xintercept=analysis.window[1], col="red", lwd=1.5, linetype = "dashed") +
geom_vline(xintercept=analysis.window[2], col="red", lwd=1.5, linetype = "dashed") +
annotate("text", x = 3000, y = 30,
label = "Analysis Window \n (90% RTs)")
```
Compute statistics over analysis window: 0 to analysis window + 500ms. We add 500ms because it allows us to include trials in which the participant initiates and completes a shift at the very end of the window.
```{r, message=F, warning=F}
iChart <- computeStatistics(iChart, startWindow=0,
endWindow=analysis.window[2]+500)
iChart_kids <- computeStatistics(iChart_kids, startWindow=0,
endWindow=analysis.window[2]+500)
iChart_adults <- computeStatistics(iChart_adults, startWindow=0,
endWindow=analysis.window_adults[2]+500)
```
Reject trials with really long RTs and with long gaps. Gaps are defined as
a sequence of frames when the child is not looking at either picture or
at the signer.
```{r RT filters}
# filter for both kids and adults
iChart <- filteriChart(iChart, minRT = analysis.window[1],
maxRT = analysis.window[2],
maxfirstgap=15, maxlonggap=15)
# filter for kids
iChart_kids <- filteriChart(iChart_kids, minRT = analysis.window[1],
maxRT = analysis.window[2],
maxfirstgap=15, maxlonggap=15)
# filter for adults
iChart_adults <- filteriChart(iChart_adults, minRT = analysis.window_adults[1],
maxRT = analysis.window_adults[2],
maxfirstgap=15, maxlonggap=15)
```
### Compute mean accuracy and RT for each participant
```{r, warning=F, message=F, eval = F}
acc_ss <- poolData(meanAccuracy(iChart_kids, startWindowAcc=analysis.window[1],
endWindowAcc=analysis.window[2]),
RejectFirstGap=TRUE,RejectLongestGap=TRUE,
RejectRT=FALSE, color=TRUE, dependent="Accuracy",
group="", facet="", dodge="",
xlab="", ylab= "Proportion\n Looking\n to target",
paired=TRUE, miny = 0.2, maxy = 0.80,
size=13, legend.direction="horizontal",
legend.position="bottom",
breaks=c(0.25, 0.50, 0.75))
rt_ss <- poolData(iChart_kids,
RejectFirstGap=TRUE, RejectLongestGap=TRUE,
RejectRT=TRUE, color=FALSE, dependent="RT", group="trial_types",
facet="", dodge="Response",
xlab="", ylab="mean RT (ms)",
paired=TRUE,
miny = 400, maxy=1300,
size=13,
legend.direction = "horizontal",
legend.position="bottom",
breaks=c(400, 800, 1200))
acc_ss_adults <- poolData(meanAccuracy(iChart_adults, startWindowAcc=300,
endWindowAcc=analysis.window_adults[2]),
RejectFirstGap=TRUE,RejectLongestGap=TRUE,
RejectRT=FALSE, color=TRUE, dependent="Accuracy",
group="", facet="", dodge="",
xlab="", ylab= "Proportion\n Looking\n to target",
paired=TRUE, miny = 0.2, maxy = 0.80,
size=13, legend.direction="horizontal",
legend.position="bottom",
breaks=c(0.25, 0.50, 0.75))
rt_ss_adults <- poolData(iChart_adults,
RejectFirstGap=TRUE, RejectLongestGap=TRUE,
RejectRT=TRUE, color=FALSE, dependent="RT", group="trial_types",
facet="", dodge="Response",
xlab="", ylab="mean RT (ms)",
paired=TRUE,
miny = 400, maxy=1300,
size=13,
legend.direction = "horizontal",
legend.position="bottom",
breaks=c(400, 800, 1200))
```
### Compute Acc and RT for each participant by age group
```{r, warning=F, message=F, eval = F}
acc_hearing_status <- poolData(meanAccuracy(iChart_kids, startWindowAcc=analysis.window[1],
endWindowAcc=analysis.window[2]),
RejectFirstGap=TRUE,RejectLongestGap=TRUE,
RejectRT=FALSE, color=TRUE, dependent="Accuracy",
group="hearing_status_participant", facet="", dodge="",
xlab="", ylab= "Proportion\n Looking\n to target",
paired=TRUE, miny = 0.2, maxy = 0.80,
size=13, legend.direction="horizontal",
legend.position="bottom",
breaks=c(0.25, 0.50, 0.75))
rt_hearing_status <- poolData(iChart_kids,
RejectFirstGap=TRUE, RejectLongestGap=TRUE,
RejectRT=TRUE, color=FALSE, dependent="RT",
group="hearing_status_participant",
facet="", dodge="Response",
xlab="", ylab="mean RT (ms)",
paired=TRUE,
miny = 400, maxy=1300,
size=13,
legend.direction = "horizontal",
legend.position="bottom",
breaks=c(400, 800, 1200))
acc <- poolData(meanAccuracy(iChart_kids, startWindowAcc = analysis.window[1],
endWindowAcc = analysis.window[2]),
RejectFirstGap=TRUE,RejectLongestGap=TRUE,
RejectRT=FALSE, color=TRUE, dependent="Accuracy",
group="age_group", facet="", dodge="",
xlab="", ylab= "Proportion\n Looking\n to target",
paired=TRUE, miny = 0.2, maxy = 0.80,
size=13, legend.direction="horizontal",
legend.position="bottom",
breaks=c(0.25, 0.50, 0.75))
rt <- poolData(iChart_kids,
RejectFirstGap=TRUE, RejectLongestGap=TRUE,
RejectRT=TRUE, color=FALSE, dependent="RT", group="age_group",
facet="", dodge="Response",
xlab="", ylab="mean RT (ms)",
paired=TRUE,
miny = 400, maxy=1300,
size=13,
legend.direction = "horizontal",
legend.position="bottom",
breaks=c(400, 800, 1200))
acc_adults <- poolData(meanAccuracy(iChart_adults, startWindowAcc=300,
endWindowAcc=analysis.window_adults[2]),
RejectFirstGap=TRUE,RejectLongestGap=TRUE,
RejectRT=FALSE, color=TRUE, dependent="Accuracy",
group="age_group", facet="", dodge="",
xlab="", ylab= "Proportion\n Looking\n to target",
paired=TRUE, miny = 0.2, maxy = 0.80,
size=13, legend.direction="horizontal",
legend.position="bottom",
breaks=c(0.25, 0.50, 0.75))
rt_adults <- poolData(iChart_adults,
RejectFirstGap=TRUE, RejectLongestGap=TRUE,
RejectRT=TRUE, color=FALSE, dependent="RT", group="age_group",
facet="", dodge="Response",
xlab="", ylab="mean RT (ms)",
paired=TRUE,
miny = 400, maxy=1300,
size=13,
legend.direction = "horizontal",
legend.position="bottom",
breaks=c(400, 800, 1200))
```
### Tanenhaus computation
Here we analyze window accuracy based on proportion looking to either target, distractor, or signer. Since there are three fixations points, chance looking behavior is 0.33.
First, we grab just the eye movement data and age group information.
```{r}
ss_iChart <- iChart %>%
filter(GoodFirstGap == T, GoodLongestGap == T) %>%
select(Sub.Num, Tr.Num, age_group, Response, `0`:`4000`)
```
Convert the data to long format.
```{r}
ss_iChart_long <- ss_iChart %>%
gather(key = Time.ms, value = value, `0`:`4000`) %>%
filter(value %in% c("0", "1", "0.5", ".", "-")) %>%
mutate(value = ifelse(value == "-", ".", value),
value_cat = factor(value, labels = c("Away", "Distractor", "Signer", "Target")),
Time.ms_numeric = to.n(Time.ms))
```
Get proportion looking to Target, Distractor, Away, and Signer at each time slice.
```{r}
## Include all types of looking
ms_iChart_count <- ss_iChart_long %>%
filter(value %in% c("0", "1", ".", "0.5")) %>% ## specify acc computation
group_by(Sub.Num, Time.ms, age_group, value_cat) %>%
dplyr::summarise(count = ifelse(n() == 0, 0, n())) %>%
dplyr::summarise(sum_count = sum(count))
ms_iChart <- as.data.frame(xtabs(~ Sub.Num + value_cat + Time.ms,
data = filter(ss_iChart_long,
value %in% c("0", "1", ".", "0.5")))) %>%
left_join(x = ms_iChart_count, by = c("Sub.Num", "Time.ms")) %>%
mutate(proportion_looking = Freq / sum_count,
age_group_factor = as.factor(age_group))
## Only include Target and Distractor looking
ms_iChart_count_TD <- ss_iChart_long %>%
filter(value %in% c("0", "1", ".")) %>% ## specify acc computation
group_by(Sub.Num, Time.ms, age_group, value_cat) %>%
dplyr::summarise(count = ifelse(n() == 0, 0, n())) %>%
dplyr::summarise(sum_count = sum(count))
ms_iChart_TD <- as.data.frame(xtabs(~ Sub.Num + value_cat + Time.ms,
data = filter(ss_iChart_long,
value %in% c("0", "1", ".")))) %>%
left_join(x = ms_iChart_count_TD, by = c("Sub.Num", "Time.ms")) %>%
mutate(proportion_looking = Freq / sum_count,
age_group_factor = as.factor(age_group))
```
Now we can compute mean proportion looking to signer, target, and distractor for each participant and for each age group.
```{r}
ss_tanenhaus_comp <- ms_iChart %>%
filter(to.n(Time.ms) >= analysis.window[1], to.n(Time.ms) <= analysis.window[2]) %>%
group_by(Sub.Num, value_cat, age_group) %>%
dplyr::summarise(mean_prop_looking_signer = mean(proportion_looking, na.rm = T))
ss_tanenhaus_comp_TD <- ms_iChart_TD %>%
filter(to.n(Time.ms) >= analysis.window[1], to.n(Time.ms) <= analysis.window[2]) %>%
group_by(Sub.Num, value_cat, age_group) %>%
dplyr::summarise(mean_prop_looking_TD = mean(proportion_looking, na.rm = T))
```
## Create summary table at the participant-level
Get mean accuracy and rt for each participant.
Some munging to get data frame for analysis. Variables needed for each subject:
* Mean acc
* Mean rt
* Signs produced
* Age
* Age condition
```{r bind summary statistics}
ss_acc <- bind_rows(acc_ss, acc_ss_adults)
ss_rt <- bind_rows(rt_ss, rt_ss_adults)
# merge acc/rt van1
ss <- left_join(ss_acc, ss_rt, by="Sub.Num")
# merge with demo info
ss <- left_join(ss, filter(sol_demo, include=="yes"), by="Sub.Num")
# clean up variable names in data frame
names(ss)[names(ss)=="Vanilla"] <- "mean_accuracy"
names(ss)[names(ss)=="Vanilla_C_D_D"] <- "mean_incorrect_rt"
names(ss)[names(ss)=="Vanilla_C_T_D"] <- "mean_correct_rt"
```
Add in Tanenhaus proportion looking computation for each participant.
```{r}
ss <- ss_tanenhaus_comp %>%
filter(value_cat %in% c("Target", "Distractor", "Signer")) %>%
select(Sub.Num, value_cat, age_group, mean_prop_looking_signer, value_cat) %>%
dplyr::rename(prop_looking = mean_prop_looking_signer) %>%
left_join(ss, ., by = c("Sub.Num"))
ss <- ss_tanenhaus_comp_TD %>%
filter(value_cat %in% c("Target", "Distractor", "Signer")) %>%
select(Sub.Num, value_cat, age_group, mean_prop_looking_TD, value_cat) %>%
left_join(ss, ., by = c("Sub.Num", "value_cat", "age_group"))
```
## First Shift Analysis
First we need to categorize each trial type based on the analysis window.
```{r}
trial_types_analysis_kids <- apply(iChart_kids, 1, trial_type_fun,
start = analysis.window[1],
end = analysis.window[2])
# merge trial type information with iChart
iChart_kids <- cbind(iChart_kids, trial_types_analysis_kids)
```
Then we add this information to the summary data frame.
```{r}
# kids
ss_first_shifts <- iChart_kids %>%
filter(trial_types_analysis_kids %in% c("C_T", "C_D", "no_shift")) %>%
group_by(Sub.Num, trial_types, age_group, Months) %>%
dplyr::summarise(count = n()) %>%
spread(trial_types, count) %>%
ungroup() %>%
mutate(C_D = ifelse(is.na(C_D), 0, C_D),
no_shift = ifelse(is.na(no_shift), 0, no_shift),
total_trials_shifting = C_D + C_T,
total_trials = C_D + C_T + no_shift,
C_D_prop = round(C_D / total_trials_shifting, 2),
C_T_prop = round(C_T / total_trials_shifting, 2),
C_D_prop_all = round(C_D / total_trials, 2),
C_T_prop_all = round(C_T / total_trials, 2))
# add adults
ss_first_shifts <- iChart_adults %>%
filter(trial_types %in% c("C_T", "C_D", "no_shift")) %>%
group_by(Sub.Num, trial_types, age_group, Months) %>%
dplyr::summarise(count = n()) %>%
spread(trial_types, count) %>%
ungroup() %>%
mutate(C_D = ifelse(is.na(C_D), 0, C_D),
no_shift = ifelse(is.na(no_shift), 0, C_D),
total_trials_shifting = C_D + C_T,
total_trials = C_D + C_T + no_shift,
C_D_prop = round(C_D / total_trials_shifting, 2),
C_T_prop = round(C_T / total_trials_shifting, 2),
C_D_prop_all = round(C_D / total_trials, 2),
C_T_prop_all = round(C_T / total_trials, 2)) %>%
bind_rows(ss_first_shifts)
# add shifts to full data frame
ss <- ss_first_shifts %>%
dplyr::rename(Sub.Num = Sub.Num, C_D_count = C_D, C_T_count = C_T) %>%
left_join(ss, by = c("Sub.Num", "age_group"))
# flag chance first shifters = more than 50% posterior mass on guessing strategy
# in latent mixture model
ss <- ss %>%
mutate(C_D_prop = ifelse(C_T_prop == 1, 0, C_D_prop),
age_group_collapsed = ifelse(age_group == "Adults", "Adults", "Kids"))
```
## Median RT
```{r}
ss_medians <- iChart %>%
filter(trial_types == "C_T", GoodRT == T) %>%
group_by(Sub.Num, age_group, age_group_collapsed, Months) %>%
dplyr::summarise(median_ct_rt = median(RT, na.rm = T))
ss <- ss_medians %>%
ungroup() %>%
select(Sub.Num, median_ct_rt) %>%
left_join(x = ss, by = "Sub.Num")
```
```{r}
ss %>%
filter(age_group_collapsed == "Kids") %>%
select(Sub.Num) %>%
unique() %>%
nrow()
```
```{r}
write.csv(ss, "../../data/processed_data/summary_tables/sol_ss_all_600_2500.csv",
row.names = F)
```
# Profile Plot Processing
## Get confidence intervals for graph values
```{r, warning=F, message=F, eval=F}
# keeping age bins
createPlots(iChart_kids, startWindow=0, endWindow=4000, RejectLongestGap=FALSE,
RejectFirstGap=FALSE, RejectRT=FALSE, color=TRUE, smooth=400,
targetEnd=800, carrier="", targets=c(""),
group="age_group", plotStats="PP", miny = 0.4, maxy=0.95, size=15,
legend.direction = "vertical", legend.position=c(0.85, 0.9),
breaks=c(0.25, 0.50, 0.75), x.target=0.33)
# keeping age bins
createPlots(iChart_adults, startWindow=0, endWindow=4000, RejectLongestGap=FALSE,
RejectFirstGap=FALSE, RejectRT=FALSE, color=TRUE, smooth=400,
targetEnd=800, carrier="", targets=c(""),
group="age_group", plotStats="PP", miny = 0.4, maxy=0.95, size=15,
legend.direction = "vertical", legend.position=c(0.85, 0.9),
breaks=c(0.25, 0.50, 0.75), x.target=0.33)
# keeping target signs and separating by stimuli
iChart_v1 <- filter(iChart_kids, stimuli == "V1")
iChart_v2 <- filter(iChart_kids, stimuli == "V2")
createPlots(iChart_v1, startWindow=0, endWindow=4000, RejectLongestGap=FALSE,
RejectFirstGap=FALSE, RejectRT=FALSE, color=TRUE, smooth=400,
targetEnd=800, carrier="V1", targets=c(""),
group="clean_target_img", plotStats="PP", miny = 0.4, maxy=0.95, size=15,
legend.direction = "vertical", legend.position=c(0.85, 0.9),
breaks=c(0.25, 0.50, 0.75), x.target=0.33)
createPlots(iChart_v2, startWindow=0, endWindow=4000, RejectLongestGap=FALSE,
RejectFirstGap=FALSE, RejectRT=FALSE, color=TRUE, smooth=400,
targetEnd=800, carrier="V2", targets=c(""),
group="clean_target_img", plotStats="PP", miny = 0.4, maxy=0.95, size=15,
legend.direction = "vertical", legend.position=c(0.85, 0.9),
breaks=c(0.25, 0.50, 0.75), x.target=0.33)
```
## Data processing Tanenhaus-style Plot
First, we munge the raw iChart data.
Grab just the eye movement data and group information
```{r}
ss_iChart <- iChart %>%
filter(Response == "D", GoodFirstGap == T, GoodLongestGap == T) %>%
select(Sub.Num, Tr.Num, stimuli, age_group_collapsed, Response, RT, trial_types,
clean_target_img, `0`:`4000`)
```
Convert to long format
```{r}
ss_iChart_long <- ss_iChart %>%
gather(key = Time.ms, value = value, `0`:`4000`) %>%
filter(value %in% c("0", "0.5", "1")) %>%
mutate(value_cat = factor(value, labels = c("Distractor", "Signer", "Target")),
Time.ms_numeric = to.n(Time.ms))
```
Summarize for each participant - get proportion looking at each time slice
```{r}
ms_iChart_count <- ss_iChart_long %>%
group_by(Sub.Num, Time.ms, age_group_collapsed, value_cat) %>%
dplyr::summarise(count = ifelse(n() == 0, 0, n())) %>%
dplyr::summarise(sum_count = sum(count))
ms_iChart <- as.data.frame(xtabs(~ Sub.Num + value_cat + Time.ms,
data = ss_iChart_long)) %>%
left_join(y = ms_iChart_count, by = c("Sub.Num", "Time.ms")) %>%
mutate(proportion_looking = Freq / sum_count,
age_group_factor = as.factor(age_group_collapsed))
```
Get means and CIs for proportion looking at each time slice across particpants
```{r}
ms_mean_iChart <- ms_iChart %>%
group_by(Time.ms, age_group_collapsed, value_cat) %>%
dplyr::summarise(mean_prop_looking = mean(proportion_looking),
ci_low = ci.low(proportion_looking),
ci_high = ci.high(proportion_looking))
```
Write graph values to CSV.
```{r}
write.csv(x = ms_mean_iChart,
file = "../../data/processed_data/graph_values/sol_gvals_all.csv",
row.names = F)
```
## Tanenhaus plot codas vs. deaf
```{r coda-deaf-plot-munging}
# grab just the eye movement data and group information
ss_iChart_coda <- iChart %>%
filter(age_group != "Adults", Response == "D", GoodFirstGap == T, GoodLongestGap == T) %>%
select(Sub.Num, hearing_status_participant, Response, `0`:`4000`)
# convert to long format
ss_iChart_long_coda <- ss_iChart_coda %>%
gather(key = Time.ms, value = value, `0`:`4000`) %>%
filter(value %in% c("0", "0.5", "1")) %>%
mutate(value_cat = factor(value, labels = c("Distractor", "Signer", "Target")),
Time.ms_numeric = to.n(Time.ms))
# dplyr::summarise
ms_iChart_count_coda <- ss_iChart_long_coda %>%
group_by(Sub.Num, Time.ms, hearing_status_participant, value_cat) %>%
dplyr::summarise(count = ifelse(n() == 0, 0, n())) %>%
dplyr::summarise(sum_count = sum(count))
ms_iChart_coda <- as.data.frame(xtabs(~ Sub.Num + value_cat + Time.ms,
data = ss_iChart_long_coda)) %>%
left_join(y = ms_iChart_count_coda, by = c("Time.ms", "Sub.Num")) %>%
mutate(proportion_looking = Freq / sum_count,
hearing_status_participant_factor = as.factor(hearing_status_participant))
# get means and CIs for proportion looking at each time slice across particpants
ms_mean_iChart_coda <- ms_iChart_coda %>%
group_by(Time.ms, hearing_status_participant, value_cat) %>%
dplyr::summarise(mean_prop_looking = mean(proportion_looking, na.rm = T),
ci_low = ci.low(proportion_looking),
ci_high = ci.high(proportion_looking))
```
Write participant-level graph values to CSV.
```{r}
write.csv(x = ms_mean_iChart_coda,
file = "../../data/processed_data/graph_values/sol_gvals_coda.csv",
row.names = F)
```
### Save trial-level data
Mean accuracy and RT for each trial
```{r}
ss_trial_level_df <- iChart %>%
select(Sub.Num, Sex, Response, Tr.Num, clean_target_img, stimuli, age_code,
age_peek_months = Months, hearing_status_participant, trial_types,
RT, Accuracy, signs_produced, include, GoodRT, reason_excluded) %>%
mutate(correct = ifelse(trial_types == "C_T", 1, 0))
```
```{r}
write.csv(x = ss_trial_level_df,
file = "../../data/processed_data/summary_tables/sol_trial_level_df.csv",
row.names = F)
```