11# 03_confidence-ratings.r - error confidence rating analyses
2- # author: [your name]
2+ # author: marlene buch
33
44# this script assumes it's sourced from batch_behavioral-analyses.r
55# with data & directories already loaded
@@ -87,13 +87,18 @@ if (CONFIDENCE_ANALYSES$visible_correctness) {
8787 # prepare data
8888 conf_correctness <- prepare_confidence_data(transformed_data , " visible_correctness" )
8989
90- # calculate descriptives
91- descriptives_correctness <- conf_correctness %> %
90+ # step 1: aggregate to subject level
91+ subject_means_correctness <- conf_correctness %> %
92+ group_by(subject , social , correctness ) %> %
93+ summarise(mean_confidence = mean(confidenceRating , na.rm = TRUE ), .groups = " drop" )
94+
95+ # step 2: calculate descriptives across subjects
96+ descriptives_correctness <- subject_means_correctness %> %
9297 group_by(social , correctness ) %> %
9398 summarise(
9499 n = n(),
95- mean = mean(confidenceRating , na.rm = TRUE ),
96- sd = sd(confidenceRating , na.rm = TRUE ),
100+ mean = mean(mean_confidence , na.rm = TRUE ),
101+ sd = sd(mean_confidence , na.rm = TRUE ),
97102 se = sd / sqrt(n ),
98103 .groups = " drop"
99104 )
@@ -135,8 +140,7 @@ if (CONFIDENCE_ANALYSES$visible_correctness) {
135140
136141 # create plot
137142 plot_path <- file.path(confidence_dir , " confidence_visible_correctness.png" )
138- plot_confidence_interaction(conf_correctness %> %
139- mutate(is_error = correctness == " error" ),
143+ plot_confidence_interaction(subject_means_correctness ,
140144 plot_type = " correctness" ,
141145 save_path = plot_path )
142146}
@@ -161,13 +165,18 @@ if (CONFIDENCE_ANALYSES$visible_error_type) {
161165
162166 # only run if sufficient data
163167 if (all(cell_counts $ n_subjects > = 10 )) {
164- # calculate descriptives
165- descriptives_error_type <- conf_error_type %> %
168+ # step 1: aggregate to subject level
169+ subject_means_error_type <- conf_error_type %> %
170+ group_by(subject , social , error_type ) %> %
171+ summarise(mean_confidence = mean(confidenceRating , na.rm = TRUE ), .groups = " drop" )
172+
173+ # step 2: calculate descriptives across subjects
174+ descriptives_error_type <- subject_means_error_type %> %
166175 group_by(social , error_type ) %> %
167176 summarise(
168177 n = n(),
169- mean = mean(confidenceRating , na.rm = TRUE ),
170- sd = sd(confidenceRating , na.rm = TRUE ),
178+ mean = mean(mean_confidence , na.rm = TRUE ),
179+ sd = sd(mean_confidence , na.rm = TRUE ),
171180 se = sd / sqrt(n ),
172181 .groups = " drop"
173182 )
@@ -209,8 +218,7 @@ if (CONFIDENCE_ANALYSES$visible_error_type) {
209218
210219 # create plot
211220 plot_path <- file.path(confidence_dir , " confidence_visible_error_type.png" )
212- plot_confidence_interaction(conf_error_type %> %
213- mutate(is_flanker = error_type == " flanker" ),
221+ plot_confidence_interaction(subject_means_error_type ,
214222 plot_type = " error_type" ,
215223 save_path = plot_path )
216224
@@ -227,13 +235,18 @@ if (CONFIDENCE_ANALYSES$invisible_response_type) {
227235 # prepare data
228236 conf_response_type <- prepare_confidence_data(transformed_data , " invisible_response_type" )
229237
230- # calculate descriptives
231- descriptives_response_type <- conf_response_type %> %
238+ # step 1: aggregate to subject level
239+ subject_means_response_type <- conf_response_type %> %
240+ group_by(subject , social , response_type ) %> %
241+ summarise(mean_confidence = mean(confidenceRating , na.rm = TRUE ), .groups = " drop" )
242+
243+ # step 2: calculate descriptives across subjects
244+ descriptives_response_type <- subject_means_response_type %> %
232245 group_by(social , response_type ) %> %
233246 summarise(
234247 n = n(),
235- mean = mean(confidenceRating , na.rm = TRUE ),
236- sd = sd(confidenceRating , na.rm = TRUE ),
248+ mean = mean(mean_confidence , na.rm = TRUE ),
249+ sd = sd(mean_confidence , na.rm = TRUE ),
237250 se = sd / sqrt(n ),
238251 .groups = " drop"
239252 )
@@ -275,8 +288,7 @@ if (CONFIDENCE_ANALYSES$invisible_response_type) {
275288
276289 # create plot
277290 plot_path <- file.path(confidence_dir , " confidence_invisible_response_type.png" )
278- plot_confidence_interaction(conf_response_type %> %
279- mutate(is_flanker_error = response_type == " flanker_error" ),
291+ plot_confidence_interaction(subject_means_response_type ,
280292 plot_type = " response_type" ,
281293 save_path = plot_path )
282294}
0 commit comments