-
Notifications
You must be signed in to change notification settings - Fork 0
/
analysis.qmd
176 lines (140 loc) · 4.3 KB
/
analysis.qmd
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
---
title: "social-rl prelim analysis"
format: html
---
Packages.
```{r}
library(here)
library(tidyverse)
library(janitor)
```
Load data.
```{r}
run <- "exp1"
```
```{r}
if (run == "pilota"){
d_raw <- read_csv(here("data","amg_gamelogs_pilota.csv")) |>
clean_names()
} else if (run == "pilotb") {
d_raw <- read_csv(here("data","amg_gamelogs_pilotb.csv")) |>
clean_names()
} else if (run == "exp1") {
d_raw <- read_csv(here("data","amg_gamelogs_experiment1.csv")) |>
clean_names()
}
d_raw
```
Clean up data.
```{r}
if (run == "pilota"){
d <- d_raw |>
filter(!is.na(condition_index)) |>
select(-id, -v)
} else if (run == "pilotb") {
d <- d_raw |>
filter(prolific_id!="Julio_test") |>
filter(uid!="lpz173o40.k42j9exeqx") |>
filter(!is.na(condition_index)) |>
select(-id, -v, -payoffs, -payoffs_id, -policy)
# Remove users who refresh their web-browser
ids_to_remove <- d |>
filter(refresh_count > 0) |>
distinct(prolific_id) |>
pull(prolific_id)
d <- d |>
filter(!prolific_id %in% ids_to_remove)
} else if (run == "exp1") {
prolific_ids_to_remove <- c('650c562d8a6ee3fcc26ee7ba', unique(filter(d_raw, refresh_count > 0)$prolific_id) )
uids_to_remove <- c("lq1fvt8g0.ohk0zzv23oa", "lq1guank0.7qsa7lr1yjq", "lq1gdwe80.5ogj3d9flwk")
d <- d_raw |>
filter(!prolific_id %in% prolific_ids_to_remove) |>
filter(!uid %in% uids_to_remove) |>
filter(!is.na(condition_index)) |>
select(-id, -v, -payoffs, -payoffs_id, -policy)
}
d
```
```{r}
# Assuming your dataframe is named df
# Check for condition_count_index
df <- d
uids_condition_count <- df |>
group_by(uid, condition_index, block_index) |>
summarise(unique_condition_count = n_distinct(condition_count_index)) |>
filter(unique_condition_count != 2) |>
pull(uid)
# Check for block_index
uids_block <- df |>
group_by(uid, condition_index) |>
summarise(unique_blocks = n_distinct(block_index)) |>
filter(unique_blocks != 3) |>
pull(uid)
# Check for condition_index
uids_condition <- df |>
group_by(uid) |>
summarise(unique_conditions = n_distinct(condition_index)) |>
filter(unique_conditions != 4) |>
pull(uid)
# Combine all uids and get unique values
uids_not_satisfying <- unique(c(uids_condition_count, uids_block, uids_condition))
# View the uids that do not satisfy the criteria
print(uids_not_satisfying)
d <- d |>
filter(!uid %in% uids_not_satisfying)
```
# Descriptives
```{r}
d |>
select(prolific_id) |>
distinct() |>
count()
```
```{r}
d |>
group_by(uid) |>
summarise(time = max(timestamp) - min(timestamp))
```
# Main analysis
Aggregation.
```{r}
participant_block_scores <- d |>
group_by(uid, condition_index, teacher, block_index, game_type) |>
summarise(total_reward = max(total_reward))
participant_block_scores
```
```{r}
mean_block_scores <- participant_block_scores |>
group_by(uid, condition_index) |>
arrange(uid, condition_index, block_index, game_type) |>
mutate(teacher_condition = teacher[!is.na(teacher)][1],
block_condition = reduce(game_type, paste)) |>
group_by(teacher_condition, block_condition, block_index, game_type) |>
select(teacher_condition, block_condition, block_index, game_type, condition_index, total_reward)
mean_block_scores$method <- "participants"
mean_block_scores
write_csv(mean_block_scores, here("data","exp1_human_performance.csv"))
```
```{r}
mean_block_scores <- participant_block_scores |>
group_by(uid, condition_index) |>
arrange(uid, condition_index, block_index, game_type) |>
mutate(teacher_condition = teacher[!is.na(teacher)][1],
block_condition = reduce(game_type, paste)) |>
group_by(teacher_condition, block_condition, block_index, game_type) |>
summarize(mean_reward = mean(total_reward),
sd_reward = sd(total_reward),
sem_reward = sd(total_reward)/sqrt(length(total_reward)),
ci_reward = 1.96 * sem_reward)
mean_block_scores
```
```{r}
ggplot(mean_block_scores,
aes(x = block_index, y = mean_reward, col = teacher_condition)) +
facet_wrap(~block_condition) +
geom_pointrange(aes(shape = game_type, ymin = mean_reward - ci_reward,
ymax = mean_reward + ci_reward),
position = position_dodge(width = .1)) +
labs( x = "block index", y = "mean reward") +
geom_line()
```