Skip to content

Commit

Permalink
Unify behavioral results
Browse files Browse the repository at this point in the history
  • Loading branch information
psychelzh committed Oct 18, 2024
1 parent f662725 commit 0d44a6e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
13 changes: 8 additions & 5 deletions R/behav.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
calc_mem_perf <- function(data, subjs) {
data |>
clean_events <- function(file, subjs) {
read_tsv(file, show_col_types = FALSE) |>
mutate(subj_id = match(subj, subjs)) |>
filter(!is.na(subj_id)) |>
mutate(acc = resp != 0 & xor(old_new == 1, resp >= 3)) |>
filter(resp != 0, !is.na(subj_id)) |>
mutate(acc = resp != 0 & xor(old_new == 1, resp >= 3))
}

calc_mem_perf <- function(data) {
data |>
preproc.iquizoo:::calc_sdt(
type_signal = 1,
by = "subj_id",
Expand All @@ -20,6 +24,5 @@ calc_simil_mem <- function(mem_perf) {

calc_memorability <- function(data) {
data |>
mutate(acc = xor(old_new == 1, resp >= 3)) |>
summarise(pc = mean(acc == 1), .by = trial_id)
}
19 changes: 7 additions & 12 deletions _targets.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,22 @@ list(
"data/subj_206.txt",
read = scan(!!.x)
),
tar_target(file_events_retrieval, "data/behav/retrieval.tsv", format = "file"),
tar_target(
mem_perf,
read_tsv(file_events_retrieval, show_col_types = FALSE) |>
calc_mem_perf(subjs)
tarchetypes::tar_file_read(
events_retrieval,
"data/behav/retrieval.tsv",
read = clean_events(!!.x, subjs)
),
tar_target(mem_perf, calc_mem_perf(events_retrieval)),
tarchetypes::tar_file_read(
smc,
"data/behav/simil.rds", # use pre-calculated
read = readRDS(!!.x)$mat[[4]]
),
tar_target(simil_mem, calc_simil_mem(mem_perf)),
tar_target(
memorability,
read_tsv(file_events_retrieval, show_col_types = FALSE) |>
calc_memorability()
),
tar_target(memorability, calc_memorability(events_retrieval)),
tar_target(
memorability_content,
read_tsv(file_events_retrieval, show_col_types = FALSE) |>
filter(resp > 0) |>
events_retrieval |>
left_join(memorability, by = "trial_id") |>
summarise(
r = psych::polyserial(pick(pc), pick(resp))[, 1],
Expand Down

0 comments on commit 0d44a6e

Please sign in to comment.