-
Notifications
You must be signed in to change notification settings - Fork 0
/
analysis3.qmd
349 lines (291 loc) · 14.1 KB
/
analysis3.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
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
---
title: "Analysis for Transfer Experiment"
format: html
editor: visual
---
Packages.
```{r}
library(here)
library(tidyverse)
library(janitor)
library(lme4)
library(ggthemes)
```
```{r}
pilotA_data <- read_csv(here("data","amg_gamelogs_socialtransfer_experiment_pilota.csv"))
pilotA_data <- pilotA_data |>
filter(game_type != 'practice') |>
filter(game_type != 'complete') |>
filter(prolific_id != 'julio_test') |>
group_by(prolific_id, session_index, session_id, game_type,
game_sequence, teacher, transfer, block_index) |>
summarise(total_reward = max(game_total_reward)) |>
ungroup()
pilotA_data
# Calculate mean and standard error for total_reward
data_summary <- pilotA_data %>%
group_by(transfer, teacher, game_sequence, block_index) %>%
summarise(
mean_reward = mean(total_reward),
se_reward = sd(total_reward) / sqrt(n()), # Standard error
.groups = 'drop' # This ensures the result is not grouped
)
data_summary
```
```{r}
# Create the plot
ggplot(data_summary, aes(x = block_index, y = mean_reward, group = teacher, color = teacher)) +
geom_line() + # Line for mean rewards
geom_errorbar(aes(ymin = mean_reward - se_reward, ymax = mean_reward + se_reward), width = 0.1) +
facet_grid(game_sequence ~ transfer, scales = "free_x") + # Organizing plots by game sequence and transfer
scale_color_manual(values = c("expert" = "blue", "novice" = "red", "none" = "green")) +
labs(title = "Game Reward Analysis (Mean and SE)",
x = "Game Index",
y = "Mean Total Reward") +
theme_minimal() +
theme(strip.background = element_blank(),
strip.text.x = element_text(size = 12, face = "bold"),
strip.text.y = element_text(size = 12, face = "bold"),
legend.position = "bottom",
legend.title = element_blank())
```
```{r}
# Mapping block_index values
data_summary$block_index_mapped <- dplyr::recode(data_summary$block_index,
`0` = 24,
`1` = 48,
`2` = 52,
`3` = 76)
# Create the plot with the adjusted facet grid layout using the mapped block_index
#data_summary$transfer <- factor(data_summary$transfer, labels = c("Transfer: True", "Transfer: False"))
# Correctly assigning factor levels and labels
data_summary$transfer <- factor(data_summary$transfer, levels = c(TRUE, FALSE), labels = c("Transfer: True", "Transfer: False"))
p <- ggplot(data_summary, aes(x = block_index_mapped, y = mean_reward, group = teacher, color = teacher)) +
geom_line() + # Line for mean rewards
geom_errorbar(aes(ymin = mean_reward - se_reward, ymax = mean_reward + se_reward), width = 0.1) +
facet_grid(transfer ~ game_sequence, scales = "free_x") + # Adjusted for Transfer on rows and Game Sequence on columns
scale_color_manual(values = c("expert" = "blue", "novice" = "red", "none" = "green")) +
scale_x_continuous(breaks = c(24, 48, 52, 76), labels = c("24", "48", "52", "76")) + # Set custom x-axis ticks
labs(title = "Game Reward Analysis (Mean and SE)",
x = "Number of Trials (Shots)",
y = "Mean Total Reward") +
theme_minimal() +
theme(strip.background = element_blank(),
strip.text.x = element_text(size = 12, face = "bold"),
strip.text.y = element_text(size = 12, face = "bold"),
legend.position = "bottom",
legend.title = element_blank())
ggsave(here("figures", "exploratory_plot1.png"), plot = p, width = 7.5, height = 5)
# Display the plot
p
```
```{r}
pilotB_prolific_data <- read_csv(here("data","socialtransferbandits_pilotb_prolific_export.csv"))
pilotB_prolific_data
pilotB_prolific_data_filtered <- pilotB_prolific_data |>
dplyr::filter(!(Status == "RETURNED" | grepl("^Yes", Colourblindness)))
pilotB_prolific_data_filtered
```
```{r}
pilotB_data <- read_csv(here("data","socialtransferbandits_pilotb_amg_gamelogs.csv"))
pilotB_data <- pilotB_data |>
filter(prolific_id %in% pilotB_prolific_data_filtered$`Participant id`) |>
filter(game_type != 'practice') |>
filter(game_type != 'complete') |>
filter(prolific_id != 'julio_test') |>
group_by(prolific_id, session_index, session_id, game_type,
game_sequence, teacher, transfer, block_index) |>
summarise(total_reward = max(game_total_reward)) |>
ungroup()
pilotB_data
# Calculate mean and standard error for total_reward
data_summary <- pilotB_data %>%
group_by(transfer, teacher, game_sequence, block_index) %>%
summarise(
mean_reward = mean(total_reward),
se_reward = sd(total_reward) / sqrt(n()), # Standard error
.groups = 'drop' # This ensures the result is not grouped
)
data_summary
```
```{r}
# Mapping block_index values
data_summary <- data_summary %>%
mutate(block_index_mapped = case_when(
game_sequence == "play-play-play" & block_index == 0 ~ 24,
game_sequence == "play-play-play" & block_index == 1 ~ 48,
game_sequence == "play-play-play" & block_index == 2 ~ 72,
game_sequence != "play-play-play" & block_index == 0 ~ 24,
game_sequence != "play-play-play" & block_index == 1 ~ 48,
game_sequence != "play-play-play" & block_index == 2 ~ 52,
game_sequence != "play-play-play" & block_index == 3 ~ 76,
TRUE ~ NA_real_ # This line ensures that any other cases result in NA
))
# Correctly assigning factor levels and labels for game_sequence
data_summary$game_sequence <- factor(data_summary$game_sequence,
levels = c("play-play-play",
"play-watch-indicate-play",
"play-play-indicate-play"))
# Correctly assigning factor levels and labels for transfer with False first
data_summary$transfer <- factor(data_summary$transfer, levels = c(FALSE, TRUE), labels = c("Transfer: False", "Transfer: True"))
# Create the plot with the adjusted facet grid layout using the mapped block_index
p <- ggplot(data_summary, aes(x = block_index_mapped, y = mean_reward, group = teacher, color = teacher)) +
geom_line() + # Line for mean rewards
geom_errorbar(aes(ymin = mean_reward - se_reward, ymax = mean_reward + se_reward), width = 0.1) +
facet_grid(transfer ~ game_sequence, scales = "free_x") + # Adjusted for Transfer on rows and Game Sequence on columns
scale_color_manual(values = c("expert" = "blue", "novice" = "red", "none" = "green")) +
scale_x_continuous(breaks = c(24, 48, 52, 76), labels = c("24", "48", "52", "76")) + # Set custom x-axis ticks
labs(title = "Game Reward Analysis (Mean and SE)",
x = "Number of Trials (Shots)",
y = "Mean Total Reward") +
theme_minimal() +
theme(strip.background = element_blank(),
strip.text.x = element_text(size = 12, face = "bold"),
strip.text.y = element_text(size = 12, face = "bold"),
legend.position = "bottom",
legend.title = element_blank())
# Save and display the plot
ggsave(here("figures", "transfer_pilotb.png"), plot = p, width = 7.5, height = 5)
# Display the plot
p
```
## Pilot Filter Data
```{r}
pilotC_demographics_raw <- read_csv(here("data","socialtransferbandits_pilotc_prolific_demographics.csv"))
pilotC_demographics_filtered <- pilotC_demographics_raw |>
dplyr::filter(!(Status == "RETURNED" | Status == "TIMED-OUT" | grepl("^Yes", Colourblindness)))
pilotC_demographics_filtered
pilotC_data_raw <- read_csv(here("data","socialtransferbandits_pilotc_amg_gamelogs.csv"))
pilotC_data_raw
pilotC_data_filtered <- pilotC_data_raw |>
filter(prolific_id %in% pilotC_demographics_filtered$`Participant id`) |>
filter(game_type != 'practice') |>
filter(game_type != 'complete') |>
filter(prolific_id != 'julio_test')
pilotC_data_filtered
```
```{r}
```
## Mean Total Reward Plots
```{r}
# Calculate mean and standard error for total_reward
data_summary <- pilotC_data_filtered %>%
group_by(prolific_id, session_index, session_id, game_type,
game_sequence, teacher, transfer, block_index) |>
summarise(total_reward = max(game_total_reward)) |>
ungroup() |>
group_by(transfer, teacher, game_sequence, block_index) |>
summarise(
mean_reward = mean(total_reward),
se_reward = sd(total_reward) / sqrt(n()), # Standard error
.groups = 'drop' # This ensures the result is not grouped
)
data_summary
# Mapping block_index values
data_summary <- data_summary |>
mutate(block_index_mapped = case_when(
game_sequence == "play-play-play" & block_index == 0 ~ 24,
game_sequence == "play-play-play" & block_index == 1 ~ 48,
game_sequence == "play-play-play" & block_index == 2 ~ 72,
game_sequence != "play-play-play" & block_index == 0 ~ 24,
game_sequence != "play-play-play" & block_index == 1 ~ 48,
game_sequence != "play-play-play" & block_index == 2 ~ 52,
game_sequence != "play-play-play" & block_index == 3 ~ 76,
TRUE ~ NA_real_ # This line ensures that any other cases result in NA
))
# Correctly assigning factor levels and labels for game_sequence
data_summary$game_sequence <- factor(data_summary$game_sequence,
levels = c("play-play-play",
"play-watch-indicate-play",
"play-play-indicate-play"))
# Correctly assigning factor levels and labels for transfer with False first
data_summary$transfer <- factor(data_summary$transfer, levels = c(FALSE, TRUE), labels = c("Transfer: False", "Transfer: True"))
# Create the plot with the adjusted facet grid layout using the mapped block_index
p <- ggplot(data_summary, aes(x = block_index_mapped, y = mean_reward, group = teacher, color = teacher)) +
geom_line() + # Line for mean rewards
geom_errorbar(aes(ymin = mean_reward - se_reward, ymax = mean_reward + se_reward), width = 0.1) +
facet_grid(transfer ~ game_sequence, scales = "free_x") + # Adjusted for Transfer on rows and Game Sequence on columns
scale_color_manual(values = c("expert" = "blue", "novice" = "red", "none" = "green")) +
scale_x_continuous(breaks = c(24, 48, 52, 76), labels = c("24", "48", "52", "76")) + # Set custom x-axis ticks
labs(title = "Game Reward Analysis (Mean and SE)",
x = "Number of Trials (Shots)",
y = "Mean Total Reward") +
theme_minimal() +
theme(strip.background = element_blank(),
strip.text.x = element_text(size = 12, face = "bold"),
strip.text.y = element_text(size = 12, face = "bold"),
legend.position = "bottom",
legend.title = element_blank())
# Save and display the plot
ggsave(here("figures", "transfer_pilotc_reward.png"), plot = p, width = 7.5, height = 5, bg="white")
# Display the plot
p
```
## Mean Entropy Plots
```{r}
# Function to calculate entropy
calculate_entropy <- function(x) {
# Calculate the proportion of each unique position
p <- table(x) / length(x)
# Calculate entropy
entropy <- -sum(p * log2(p))
return(entropy)
}
# Filter the data to include only rows where action is 'shoot' or 'indicate'
filtered_data <- pilotC_data_filtered %>%
filter(action %in% c("shoot", "indicate"))
# Compute the entropy of position within each group
entropy_summary <- filtered_data %>%
group_by(prolific_id, session_index, session_id, game_type,
game_sequence, teacher, transfer, block_index) %>%
summarise(position_entropy = calculate_entropy(position)) %>%
ungroup()
# Calculate the mean of the position entropy and its standard error
mean_entropy_summary <- entropy_summary %>%
group_by(transfer, teacher, game_sequence, block_index) %>%
summarise(
mean_position_entropy = mean(position_entropy, na.rm = TRUE),
se_position_entropy = sd(position_entropy, na.rm = TRUE) / sqrt(n()), # Standard error
.groups = 'drop'
)
mean_entropy_summary
# Mapping block_index values
mean_entropy_summary <- mean_entropy_summary %>%
mutate(block_index_mapped = case_when(
game_sequence == "play-play-play" & block_index == 0 ~ 24,
game_sequence == "play-play-play" & block_index == 1 ~ 48,
game_sequence == "play-play-play" & block_index == 2 ~ 72,
game_sequence != "play-play-play" & block_index == 0 ~ 24,
game_sequence != "play-play-play" & block_index == 1 ~ 48,
game_sequence != "play-play-play" & block_index == 2 ~ 52,
game_sequence != "play-play-play" & block_index == 3 ~ 76,
TRUE ~ NA_real_ # This line ensures that any other cases result in NA
))
# Correctly assigning factor levels and labels for game_sequence
mean_entropy_summary$game_sequence <- factor(mean_entropy_summary$game_sequence,
levels = c("play-play-play",
"play-watch-indicate-play",
"play-play-indicate-play"))
# Correctly assigning factor levels and labels for transfer with False first
mean_entropy_summary$transfer <- factor(mean_entropy_summary$transfer, levels = c(FALSE, TRUE), labels = c("Transfer: False", "Transfer: True"))
# Create the plot with the adjusted facet grid layout using the mapped block_index
p <- ggplot(mean_entropy_summary, aes(x = block_index_mapped, y = mean_position_entropy, group = teacher, color = teacher)) +
geom_line() + # Line for mean rewards
geom_errorbar(aes(ymin = mean_position_entropy - se_position_entropy, ymax = mean_position_entropy + se_position_entropy), width = 0.1) +
facet_grid(transfer ~ game_sequence, scales = "free_x") + # Adjusted for Transfer on rows and Game Sequence on columns
scale_color_manual(values = c("expert" = "blue", "novice" = "red", "none" = "green")) +
scale_x_continuous(breaks = c(24, 48, 52, 76), labels = c("24", "48", "52", "76")) + # Set custom x-axis ticks
labs(title = "Game Reward Analysis (Mean and SE)",
x = "Number of Trials (Shots)",
y = "Mean Position Entropy") +
theme_minimal() +
theme(strip.background = element_blank(),
strip.text.x = element_text(size = 12, face = "bold"),
strip.text.y = element_text(size = 12, face = "bold"),
legend.position = "bottom",
legend.title = element_blank())
# Save and display the plot
ggsave(here("figures", "transfer_pilotc_entropy.png"), plot = p, width = 7.5, height = 5, bg="white")
# Display the plot
p
```