Created
March 5, 2019 18:28
-
-
Save nelsonroque/6cffa5edd7c2d70f0bfc1ca85031eb78 to your computer and use it in GitHub Desktop.
Symbol Search: Scoring and Summary Scripts (for use with R's tidyverse package)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# for scoring raw, parsed data | |
score_symbol_search <- function(df) { | |
scored <- df %>% mutate(accuracy = ifelse(user_response == correct_response,1,0)) | |
return(scored) | |
} | |
# for summarizing scored data | |
summary_symbol_search <- function(df, group_var) { | |
TASK_NAME <- "SYMBOL_SEARCH" | |
summary.df <- df %>% | |
group_by_(.dots = group_var) %>% | |
mutate(accuracy = ifelse(user_response == correct_response,1,0)) %>% | |
summarise(median.RT.all_trials = median(response_time, na.rm=T), | |
median.RT.accurate_trials = median(response_time[accuracy == 1], na.rm=T), | |
median.RT.error_trials = median(response_time[accuracy == 0], na.rm=T), | |
median.RT.lure_trials = median(response_time[trial_type == "LURE"], na.rm=T), | |
median.RT.normal_trials = median(response_time[trial_type == "NORMAL"], na.rm=T), | |
sd.RT.all_trials = sd(response_time, na.rm=T), | |
sd.RT.accurate_trials = sd(response_time[accuracy == 1], na.rm=T), | |
sd.RT.error_trials = sd(response_time[accuracy == 0], na.rm=T), | |
sd.RT.lure_trials = sd(response_time[trial_type == "LURE"], na.rm=T), | |
sd.RT.normal_trials = sd(response_time[trial_type == "NORMAL"], na.rm=T), | |
proportion.accurate.trials = sum(accuracy)/n(), | |
proportion.error.trials = (n() - sum(accuracy))/n(), | |
n.filtered.trials = sum(is.na(response_time)), | |
n.accurate.trials = sum(accuracy), | |
n.error.trials = n() - sum(accuracy), | |
n.lure.trials = sum(trial_type == "LURE"), | |
n.normal.trials = sum(trial_type == "NORMAL"), | |
n.trials = n()) | |
# add task name to column names | |
len_group_var = length(group_var) | |
names(summary.df)[(len_group_var+1):ncol(summary.df)] <- paste0(TASK_NAME,".",names(summary.df)[(len_group_var+1):ncol(summary.df)]) | |
return(summary.df) | |
} | |
df.scored <- score_symbol_search(symbol_search.path) | |
df.summary <- summary_symbol_search(df.scored,c("user_id")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment