Skip to content

Commit b882aea

Browse files
BuchBuch
authored andcommitted
fixed confidence rating analyses to use correct DFd
1 parent 9fefcc2 commit b882aea

File tree

3 files changed

+42
-30
lines changed

3 files changed

+42
-30
lines changed

code/analyses-behavior/03_confidence-ratings.R

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
}

code/analyses-behavior/04_generate-report.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Behavioral Analyses Report"
3-
author: "SocCEr Study"
3+
author: "Marlene Buch"
44
date: "`r format(Sys.time(), '%Y-%m-%d %H:%M:%S')`"
55
output:
66
html_document:

code/analyses-behavior/functions/plot_confidence-ratings.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# plot_confidence-ratings.r - plotting functions for confidence analyses
2-
# author: [your name]
2+
# author: marlene buch
33

44
# === confidence rating plotting functions ===
55

@@ -8,7 +8,7 @@ plot_confidence_interaction <- function(conf_data, plot_type = "correctness",
88
# create interaction plot for confidence ratings
99
#
1010
# inputs:
11-
# conf_data - data with confidence ratings
11+
# conf_data - data with subject-level mean confidence ratings
1212
# plot_type - "correctness", "error_type", or "response_type"
1313
# save_path - optional path to save plot
1414
# title - optional title
@@ -33,12 +33,12 @@ plot_confidence_interaction <- function(conf_data, plot_type = "correctness",
3333
if (is.null(title)) title <- "Confidence Ratings: Response Type × Social (Invisible)"
3434
}
3535

36-
# calculate summary statistics
36+
# calculate summary statistics from subject means
3737
plot_data <- conf_data %>%
3838
group_by(across(all_of(c(x_var, color_var)))) %>%
3939
summarise(
40-
mean = mean(confidenceRating, na.rm = TRUE),
41-
se = sd(confidenceRating, na.rm = TRUE) / sqrt(n()),
40+
mean = mean(mean_confidence, na.rm = TRUE),
41+
se = sd(mean_confidence, na.rm = TRUE) / sqrt(n()),
4242
.groups = "drop"
4343
) %>%
4444
mutate(social = factor(social, levels = c("social", "nonsocial")))
@@ -81,17 +81,17 @@ plot_confidence_bars <- function(conf_data, group_var, save_path = NULL, title =
8181
# create bar plot for confidence ratings
8282
#
8383
# inputs:
84-
# conf_data - data with confidence ratings
84+
# conf_data - data with subject-level mean confidence ratings
8585
# group_var - variable to group by (e.g., "social", "correctness")
8686
# save_path - optional path to save plot
8787
# title - optional title
8888

89-
# calculate summary statistics
89+
# calculate summary statistics from subject means
9090
plot_data <- conf_data %>%
9191
group_by(across(all_of(group_var))) %>%
9292
summarise(
93-
mean = mean(confidenceRating, na.rm = TRUE),
94-
se = sd(confidenceRating, na.rm = TRUE) / sqrt(n()),
93+
mean = mean(mean_confidence, na.rm = TRUE),
94+
se = sd(mean_confidence, na.rm = TRUE) / sqrt(n()),
9595
.groups = "drop"
9696
)
9797

@@ -124,4 +124,4 @@ plot_confidence_bars <- function(conf_data, group_var, save_path = NULL, title =
124124
return(p)
125125
}
126126

127-
cat(" confidence rating plotting functions loaded\n")
127+
cat(" confidence rating plotting functions loaded\n")

0 commit comments

Comments
 (0)