-
Notifications
You must be signed in to change notification settings - Fork 0
/
Study3_Switching_Multiple_Policies_to_the_Preferred_Option_at_Start.R
111 lines (91 loc) · 5.87 KB
/
Study3_Switching_Multiple_Policies_to_the_Preferred_Option_at_Start.R
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
####################################################################################
# Switching Multiple Policies to the Preferred Option at the Beginning of Learning #
####################################################################################
# Import Libraries
library("tidyverse")
# Import data
Switching_Multiple_Policies_to_the_Preferred_Option_at_Start <- tibble(read.csv("Study3_Switching_Multiple_Policies_to_the_Preferred_Option_at_Start.csv"))
# preview data
head(Switching_Multiple_Policies_to_the_Preferred_Option_at_Start)
# data dictionary:
## "Participant" = participant number
## "Function_Exposure" = denotes assignment to function exposure condition or not (1=yes, 0=no)
## "Trial" = trial number (range: 11-150; only includes trials which participant had control of policies decisions)
## "Function" = Function number (range 1-6; refer to payoff function figure)
## "Confounded_Testing" = denotes if function/policy test was controlled (coded as 0; no other tests co-occurring) or confounded (coded as 1; two or more tests occurring at same time)
## "Switched_to_Preferred" = denotes if function/policy test was to preferred policy (1=change to preferred policy; 0=change to non-preferred policy, -88=change from neutral policy to another neutral policy)
# new variables:
## trial_adj is reflective of when participants actually had control of the economic system.
Switching_Multiple_Policies_to_the_Preferred_Option_at_Start$Trial_adj <- Switching_Multiple_Policies_to_the_Preferred_Option_at_Start$Trial-10
## Code trial to examine behavior on first trial (1) versus all other trials (2)
Switching_Multiple_Policies_to_the_Preferred_Option_at_Start$Trial_coded <- ifelse(Switching_Multiple_Policies_to_the_Preferred_Option_at_Start$Trial_adj==1,1,2)
#-----------------------------------------------------------------------------------------------------------------------
# was confounded testing different on the first trial versus other trials?
aggregate(Switching_Multiple_Policies_to_the_Preferred_Option_at_Start$Confounded_Testing,
by=list(Switching_Multiple_Policies_to_the_Preferred_Option_at_Start$Trial_coded,
Switching_Multiple_Policies_to_the_Preferred_Option_at_Start$Switched_to_Preferred),
sum) %>%
rename("Trial_Coded"=Group.1,
"Switched_to_Preferred"=Group.2,
"Confounded_Testing_Count"=x) %>%
arrange(Trial_Coded) %>%
filter(Switched_to_Preferred!=-88) # filter the few neutral policies that participants had
#-----------------------------------------------------------------------------------------------------------------------
# was there a difference in single policy (controlled) testing by preference and across first and latter trials
single_tests_only <- Switching_Multiple_Policies_to_the_Preferred_Option_at_Start %>%
filter(Confounded_Testing==0,
Switched_to_Preferred!=-88) # filter the few neutral policies that participants had
aggregate(single_tests_only$Confounded_Testing,
by=list(single_tests_only$Switched_to_Preferred,
single_tests_only$Trial_coded),
length) %>%
rename("Switched_to_Preferred"=Group.1,
"Trial_coded"=Group.2,
"Non_Confounded_Testing_Count"=x)
#-----------------------------------------------------------------------------------------------------------------------
# create a figure to examine when confounded tests occurred
# create two dataframes examining 1) confounded testing and 2) single-policy testing
conf_test <- aggregate(Switching_Multiple_Policies_to_the_Preferred_Option_at_Start$Confounded_Testing, by=list(Switching_Multiple_Policies_to_the_Preferred_Option_at_Start$Function_Exposure, Switching_Multiple_Policies_to_the_Preferred_Option_at_Start$Trial_adj), sum) %>%
rename("Function_Exposure"=Group.1,
"Trial"=Group.2,
"Confounded_Testing_Count"=x)
single_test <- aggregate(single_tests_only$Confounded_Testing, by=list(single_tests_only$Function_Exposure, single_tests_only$Trial_adj), length) %>%
rename("Function_Exposure"=Group.1,
"Trial"=Group.2,
"Confounded_Testing_Count"=x)
# stack the two above dataframes
Test_Type <- c(rep("Confounded", length(conf_test$Confounded_Testing_Count)),
rep("Controlled", length(single_test$Confounded_Testing_Count)))
Function_Exposure <- c(conf_test$Function_Exposure, single_test$Function_Exposure)
Trial <- c(conf_test$Trial, single_test$Trial)
Counts <- c(conf_test$Confounded_Testing_Count, single_test$Confounded_Testing_Count)
Number_of_controlled_and_confounded_changes_by_per_trial <- tibble(Test_Type, Function_Exposure, Trial, Counts)
# collapsing across function exposure (paper version)
ggplot(data=Number_of_controlled_and_confounded_changes_by_per_trial, aes(x=Trial, y=Counts, group=Test_Type)) +
geom_line(aes(color=Test_Type)) +
scale_color_manual(values = c("#BFBFBF", "black")) +
scale_x_continuous(limits=c(0,140), breaks=c(0, 20,40,60,80,100,120, 140)) +
labs(x='Trial') +
theme_bw() +
theme(
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
strip.text.x = element_text(size = 10, color='black'),
axis.text.y = element_text(size = 10, color='black'),
axis.text.x = element_text(size = 10, color='black')
)
# showing function exposure groups
ggplot(data=Number_of_controlled_and_confounded_changes_by_per_trial, aes(x=Trial, y=Counts, group=Test_Type)) +
geom_line(aes(color=Test_Type)) +
scale_color_manual(values = c("#BFBFBF", "black")) +
scale_x_continuous(limits=c(0,140), breaks=c(0, 20,40,60,80,100,120, 140)) +
labs(x='Trial') +
theme_bw() +
theme(
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
strip.text.x = element_text(size = 10, color='black'),
axis.text.y = element_text(size = 10, color='black'),
axis.text.x = element_text(size = 10, color='black')
) +
facet_grid(.~Function_Exposure)