Skip to content

Instantly share code, notes, and snippets.

@JimGrange
Created January 31, 2024 11:08
Show Gist options
  • Save JimGrange/89db3c0e0460f44190e68892c234e1cb to your computer and use it in GitHub Desktop.
Save JimGrange/89db3c0e0460f44190e68892c234e1cb to your computer and use it in GitHub Desktop.
flankr individual CAFs
library(tidyverse)
library(flankr)
# get example data from flankr
# ONLY SHOWING FOR CONGRUENT DATA.
d <- flankr::exampleData %>%
filter(congruency == "congruent")
# how many subjects?
n_subjects <- length(unique(d$subject))
# initiate caf tibble
caf_data <- tibble(
id = 1:n_subjects,
rt_1 = 0,
rt_2 = 0,
rt_3 = 0,
rt_4 = 0,
acc_1 = 0,
acc_2 = 0,
acc_3 = 0,
acc_4 = 0
)
# loop over subjects
for(i in 1:n_subjects){
# get the current subject's data
sub_data <- d %>%
filter(subject == i)
# get their CAFs
sub_caf <- flankr::caf(sub_data, multipleSubjects = FALSE)
# store the data
caf_data[i, 2] <- sub_caf[1, 1]
caf_data[i, 3] <- sub_caf[1, 2]
caf_data[i, 4] <- sub_caf[1, 3]
caf_data[i, 5] <- sub_caf[1, 4]
caf_data[i, 6] <- sub_caf[2, 1]
caf_data[i, 7] <- sub_caf[2, 2]
caf_data[i, 8] <- sub_caf[2, 3]
caf_data[i, 9] <- sub_caf[2, 4]
}
# THEN REPEAT FOR INCOGNRUENT. OR, BE MORE FANCY WITH HOW THE ABOVE
# IS HANDLED!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment