diff --git a/R/behavioral_data_preprocessing.R b/R/behavioral_data_preprocessing.R index ba10814..4c435d4 100644 --- a/R/behavioral_data_preprocessing.R +++ b/R/behavioral_data_preprocessing.R @@ -72,7 +72,8 @@ get_all_hits_with_reaction_times <- function(participants, combined_df) { signals %>% mutate( hit_time = get_hit_times(signals$signal_time, responses$resp_time), - reaction_time = hit_time - signal_time + reaction_time = hit_time - signal_time, + is_hit = as.integer(!is.na(hit_time)) ) }) } diff --git a/notebooks/behavioral_data_preprocessing.html b/notebooks/behavioral_data_preprocessing.html deleted file mode 100644 index 1fc3916..0000000 --- a/notebooks/behavioral_data_preprocessing.html +++ /dev/null @@ -1,876 +0,0 @@ - - - - - - - - - - - - - - - - - - -

Behavioral Data Preprocessing

-

Ari Dyckovsky

- -

Load extracted CSV files

-

Construct a list of the extracted behavioral CSV file targets by participant.

-
extracted_behavioral_csv_files <- participants %>%
-  unlist(use.names = FALSE) %>%
-  map(~ str_c("extracted_behavioral_csv_file_", .x))
-

Read CSVs into dataframe combined_df after using tar_read_raw to get the file path for participants from targets. Will include all participants and include an id column to identify the participant individually.

-
withr::with_dir(here::here(), {
-  combined_df <- extracted_behavioral_csv_files %>%
-    map_df(~ read_csv(tar_read_raw(.)))
-})
-
-# Transform step and response types to 0 or 1 integer values to simulate boolean behavior.
-combined_df <- combined_df %>%
-  mutate(
-    is_signal = as.integer(step_type > 1),
-    is_response = as.integer(resp_type)
-  ) %>%
-  select(-c(resp_type, step_type))
-

Sanity checks

-

Count of participants by unique id.

-
length(unique(combined_df$id))
-
## [1] 50
-
-
combined_df %>%
-  select(trial, id, is_response, is_signal, resp_time, step_time) %>%
-  group_by(id) %>%
-  tally(is_response) %>%
-  summarise(mean(n), sd(n), min(n), max(n))
-
## # A tibble: 1 x 4
-##   `mean(n)` `sd(n)` `min(n)` `max(n)`
-##       <dbl>   <dbl>    <int>    <int>
-## 1      37.3    32.9        4      170
-
-

Combined hits dataframe for all participants

-

The function to get each participant’s hit times vector is itrackvalr::get_hit_times, and the function to get a dataframe of all participants’ hits is itrackvalr::get_all_hits_with_reaction_times, including each hit time and reaction time between that hit time and the nearest signal prompting a response within a fixed interval.

-

Get the combined hits using the function:

-
combined_hits_df <- get_all_hits_with_reaction_times(participants, combined_df)
-

Check out a quick preview of the table of hits

-
knitr::kable(head(combined_hits_df, 10))
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
trialidimage_indexsignal_timehit_timereaction_time
81CSN00180180.0604399294NANA
117CSN001941116.0665163944116.9840918450.917575450165
119CSN0013131118.0679634164NANA
211CSN0011325210.0571848214NANA
235CSN001752234.0716901990NANA
361CSN001103360.0647047530NANA
461CSN0012804460.0590288559NANA
591CSN00128590.0714484362NANA
823CSN001929822.0630183384822.7725248340.709506495599
845CSN001517844.0589960678845.9231865611.864190493347
-

Check out the reaction time summary statistics by id:

-
knitr::kable(head(
-  combined_hits_df %>%
-    drop_na() %>%
-    group_by(id) %>%
-    summarise(
-      reaction_time_mean = mean(reaction_time),
-      reaction_time_min = min(reaction_time),
-      reaction_time_max = max(reaction_time),
-      reaction_time_sd = sd(reaction_time)
-    ),
-  10
-))
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
idreaction_time_meanreaction_time_minreaction_time_maxreaction_time_sd
CSN0011.719815961740.0301773006784.734948483171.185127808038
CSN0021.993592132680.4393996556177.771711266771.727003771770
CSN0041.706465934090.9963161628992.840902087760.543133623999
CSN0053.060804741181.5336210489307.643231210762.120246304387
CSN0061.472374778580.0935939496787.994347869881.763412125625
CSN0071.794549947350.7599969817753.990193928860.965011326176
CSN0083.094175138410.8504212004567.924662693981.627078951623
CSN0091.317594929690.5991574015732.199128169370.469031982754
CSN0102.155909230060.2461947773127.992834555602.249618738692
CSN0111.364055984540.6928280050163.649245175830.651777575973
-

Gut-check plot of reaction times by signal times

-

Note the 1.000s to 1.100s gap where hits were not recorded.

-
combined_hits_df %>%
-  drop_na() %>%
-  ggplot(aes(x = signal_time, y = reaction_time)) +
-    geom_point(color = 'orange') +
-    geom_smooth(method=lm) +
-    theme_classic()
-

-

Reaction times per participant centered at the median

-
combined_hits_df %>%
-  drop_na() %>%
-  arrange(reaction_time) %>%
-  ggplot(aes(x = reorder(id, reaction_time, FUN = median), y = reaction_time)) +
-    geom_point(alpha = 0.8, size = 0.7, color = 'darkblue', position = 'jitter') +
-    geom_boxplot(alpha = 0) +
-    geom_hline(yintercept = 1, color = 'coral') +
-  theme_minimal() +
-  theme(
-    aspect.ratio = 1,
-    text = element_text(size = 15),
-    plot.margin = margin(18, 18, 18, 18, 'pt')
-  ) +
-  labs(
-    title = 'Reaction times of participants by id',
-    subtitle = 'Boxplot per participant anchored at median of reaction time',
-    y = 'Reaction time for HIT after double-tick signal',
-    x = 'Participant'
-  ) +
-  coord_flip()
-

- - - diff --git a/notebooks/behavioral_data_preprocessing.md b/notebooks/behavioral_data_preprocessing.md index 8cd3172..888f499 100644 --- a/notebooks/behavioral_data_preprocessing.md +++ b/notebooks/behavioral_data_preprocessing.md @@ -1,5 +1,20 @@ -Behavioral Data Preprocessing -================ + + - [Behavioral Data Preprocessing](#behavioral-data-preprocessing) + - [Load extracted CSV files](#load-extracted-csv-files) + - [Sanity checks](#sanity-checks) + - [Combined hits dataframe for all + participants](#combined-hits-dataframe-for-all-participants) + - [Check out a quick preview of the table of + hits](#check-out-a-quick-preview-of-the-table-of-hits) + - [Check out the reaction time summary statistics by + id:](#check-out-the-reaction-time-summary-statistics-by-id) + - [Gut-check plot of reaction times by signal + times](#gut-check-plot-of-reaction-times-by-signal-times) + - [Reaction times per participant centered at the + median](#reaction-times-per-participant-centered-at-the-median) + +# Behavioral Data Preprocessing + Ari Dyckovsky - [Load extracted CSV files](#load-extracted-csv-files) @@ -89,18 +104,18 @@ combined_hits_df <- get_all_hits_with_reaction_times(participants, combined_df) knitr::kable(head(combined_hits_df, 10)) ``` -| trial | id | image\_index | signal\_time | hit\_time | reaction\_time | -| ----: | :----- | -----------: | -------------: | ------------: | -------------: | -| 81 | CSN001 | 801 | 80.0604399294 | NA | NA | -| 117 | CSN001 | 941 | 116.0665163944 | 116.984091845 | 0.917575450165 | -| 119 | CSN001 | 3131 | 118.0679634164 | NA | NA | -| 211 | CSN001 | 1325 | 210.0571848214 | NA | NA | -| 235 | CSN001 | 752 | 234.0716901990 | NA | NA | -| 361 | CSN001 | 103 | 360.0647047530 | NA | NA | -| 461 | CSN001 | 2804 | 460.0590288559 | NA | NA | -| 591 | CSN001 | 28 | 590.0714484362 | NA | NA | -| 823 | CSN001 | 929 | 822.0630183384 | 822.772524834 | 0.709506495599 | -| 845 | CSN001 | 517 | 844.0589960678 | 845.923186561 | 1.864190493347 | +| trial | id | image\_index | signal\_time | hit\_time | reaction\_time | is\_hit | +| ----: | :----- | -----------: | -------------: | ------------: | -------------: | ------: | +| 81 | CSN001 | 801 | 80.0604399294 | NA | NA | 0 | +| 117 | CSN001 | 941 | 116.0665163944 | 116.984091845 | 0.917575450165 | 1 | +| 119 | CSN001 | 3131 | 118.0679634164 | NA | NA | 0 | +| 211 | CSN001 | 1325 | 210.0571848214 | NA | NA | 0 | +| 235 | CSN001 | 752 | 234.0716901990 | NA | NA | 0 | +| 361 | CSN001 | 103 | 360.0647047530 | NA | NA | 0 | +| 461 | CSN001 | 2804 | 460.0590288559 | NA | NA | 0 | +| 591 | CSN001 | 28 | 590.0714484362 | NA | NA | 0 | +| 823 | CSN001 | 929 | 822.0630183384 | 822.772524834 | 0.709506495599 | 1 | +| 845 | CSN001 | 517 | 844.0589960678 | 845.923186561 | 1.864190493347 | 1 | ## Check out the reaction time summary statistics by id: