-
Notifications
You must be signed in to change notification settings - Fork 3
/
4choice_analysis.Rmd
98 lines (92 loc) · 3.71 KB
/
4choice_analysis.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
---
title: "Prob switch analyses"
output: html_notebook
---
```{r Set up parameters}
data_dir = 'C:/Users/maria/Desktop/SLCN/reversal4choicegame/logs'
# data_dir = 'C:/Users/prokofiev/Desktop/SLCN Tasks/SLCN/reversal4choicegame/logs'
library("ggplot2"); theme_set(theme_bw())
library("plyr")
```
```{r Read in data files}
filenames = list.files(data_dir, pattern = "*.txt")
all_files = data.frame()
for(filename in filenames) {
file = read.table(file.path(data_dir, filename), header = T)
if (!"Date" %in% colnames(file)) {
file$Date = NA
file$CurrentTime = NA
}
file$trials_till_reversal = NA
counter = 1
for (trial in rev(file$TrialNumber)) {
if (file$Reversal[file$TrialNumber == trial] == 0) {
file$trials_till_reversal[file$TrialNumber == trial] = counter
counter = counter + 1
}
}
all_files = rbind(all_files, file)
}
all_files$pID = factor(all_files$pID)
all_files$Reversal = factor(all_files$Reversal, levels = c(0, 1), labels = c("Discrimination", "Reversal"))
all_files$Choice = factor(all_files$Choice)
all_files$age_bin = 7
for (age_bin in seq(9, 30, 2)) {
all_files$age_bin[all_files$Age >= age_bin] = age_bin
}
summary(all_files)
head(all_files)
```
```{r Do kids reach criterion}
all_files_sum = ddply(all_files, .(pID, Age, age_bin, Gender, Reversal), summarize,
ReversalTrial = max(TrialNumPhase),
ResponseTime = median(ResponseTime))
all_files_sum_wide = reshape(all_files_sum,
direction = "wide", timevar = "Reversal", idvar = c("pID", "Age", "age_bin", "Gender"))
all_files_sum_wide$ReversalTrial.Diff = with(all_files_sum_wide, ReversalTrial.Reversal - ReversalTrial.Discrimination)
# Individual
ggplot(all_files_sum, aes(reorder(pID, ReversalTrial), ReversalTrial, color = Reversal)) +
geom_point(size = 5) +
coord_cartesian(y = c(0, 30)) +
labs(x = "Participant ID", y = "# trials to / after reversal")
# Summary
ggplot(all_files_sum, aes(Reversal, ReversalTrial, color = Reversal)) +
geom_point(alpha = .3, position = "jitter") +
stat_summary(fun.data = mean_cl_normal, fun.args = list(mult = 1), geom = "pointrange") +
coord_cartesian(y = c(0, 30))
# Diff scores
ggplot(all_files_sum_wide, aes(Gender, ReversalTrial.Diff, color = Gender)) +
stat_summary(fun.data = mean_cl_normal, fun.args = list(mult = 1), geom = "pointrange") +
geom_point(alpha = .5, position = "jitter") +
labs(y = "# Reversal trials - # Discrimination trials")
```
```{r Learning curve}
ggplot(all_files, aes(TrialNumPhase, Correct)) +
stat_summary(fun.data = mean_cl_normal, fun.args = list(mult = 1), geom = "pointrange") +
labs(x = "Trial") +
coord_cartesian(x = c(1, 8)) +
facet_grid(~ Reversal)
ggplot(subset(all_files, trials_till_reversal < 10), aes(reorder(trials_till_reversal, -trials_till_reversal), Correct)) +
stat_summary(fun.data = mean_cl_normal, fun.args = list(mult = 1), geom = "pointrange") +
labs(x = "Trials until reversal") +
coord_cartesian(x = c(1, 8))
```
```{r RTs}
all_files$ResponseTime[all_files$ResponseTime > 50] = NA
ggplot(all_files, aes(TrialNumPhase, ResponseTime)) +
stat_summary(fun.data = mean_cl_normal, fun.args = list(mult = 1), geom = "bar") +
stat_summary(fun.data = mean_cl_normal, fun.args = list(mult = 1), geom = "pointrange") +
coord_cartesian(x = c(1, 8), y = c(0, 50)) +
geom_point(alpha = .4, position = "jitter") +
labs(x = "Trial", y = "Response Time (sec)") +
facet_grid(~ Reversal)
```
```{r Read in param data}
# Reading in all data files
params = read.csv('C:/Users/prokofiev/Desktop/4choice_rawdata/params.csv')
par(mfrow=c(2,2))
boxplot(params$alpha,ylim=c(0,1))
boxplot(params$beta,ylim=c(0,1))
boxplot(params$r.alpha,ylim=c(0,1))
boxplot(params$r.beta,ylim=c(0,1))
```