From 1dbea60f7503e83001bcfdd4c2ac36bee5abe8d1 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Mon, 4 Mar 2024 17:30:15 +0800 Subject: [PATCH] Use all single runs to calculate full latent fc structure Signed-off-by: Liang Zhang --- _scripts/prepare_neural.R | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/_scripts/prepare_neural.R b/_scripts/prepare_neural.R index 5a4d9e5..f3a7e0d 100644 --- a/_scripts/prepare_neural.R +++ b/_scripts/prepare_neural.R @@ -52,21 +52,31 @@ list( tarchetypes::tar_eval( tar_target( fc, - do.call(abind::abind, c(call_list_fc, along = 3)) |> + # calculate principal component only on kept subjects + lapply(call_list_fc, \(x) x[subjs_keep_neural, ]) |> + abind::abind(along = 3) |> apply(2, \(x) princomp(x)$scores[, 1]) ), config_fc_calc |> dplyr::filter(task == "latent") |> - dplyr::left_join( - config_fc_calc |> - dplyr::filter(task != "latent" & session != "0") |> - dplyr::summarise( - call_list_fc = list( - as.call(c(quote(list), fc)) - ), - .by = c(xcpd, run) - ), - by = c("xcpd", "run") + dplyr::mutate( + call_list_fc = purrr::map2( + xcpd, run, + \(cur_xcpd, cur_run) { + config <- config_fc_calc |> + dplyr::filter( + task != "latent", + session != "0", + xcpd == cur_xcpd, + if (cur_run == "full") { + grepl("^run\\d$", run) + } else { + run == cur_run + } + ) + as.call(c(quote(list), config$fc)) + } + ) ) ), # extract mean frame-wise displacement (FD) ----