Skip to content

Commit

Permalink
Add correlation wth RAPM without resampling reasoning tasks
Browse files Browse the repository at this point in the history
Signed-off-by: Liang Zhang <[email protected]>
  • Loading branch information
psychelzh committed Feb 29, 2024
1 parent 7f61d32 commit 353c088
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 10 deletions.
15 changes: 15 additions & 0 deletions R/constants.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
game_id_rapm <- bit64::as.integer64(265520726213317) # 瑞文高级推理
# data for this game should be removed because another version was used
game_id_rata <- bit64::as.integer64(240052750955077) # 远距离联想A (obsolete)
game_id_reasoning <- bit64::as.integer64(
c(
355740871500677,
355740333933445,
356101783560965,
411281158706373,
324179001000709,
268008982659144,
324179964613381,
361750352892805,
324177880433541
)
)
# we define here to be used in g factor resampling
num_vars_total <- 76

# used in data quality check
thresh_prop_miss <- 0.25
Expand Down
13 changes: 7 additions & 6 deletions R/tar_prepare.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
prepare_config_vars <- function(num_vars_total, n_steps) {
num_vars_base <- num_vars_total %/% n_steps
tibble::tibble(
num_vars = seq(num_vars_base, num_vars_total, num_vars_base),
use_pairs = num_vars * 2 <= num_vars_total
) |>
prepare_config_vars <- function(num_vars_total, ...,
step = 3, from = 3, use_pairs = TRUE) {
out <- tibble::tibble(num_vars = seq(from, num_vars_total, step)) |>
dplyr::filter(choose(num_vars_total, num_vars) > 1e4)
if (use_pairs) {
out$use_pairs <- out$num_vars * 2 <= num_vars_total
}
out
}

prepare_config_cpm <- function(...) {
Expand Down
5 changes: 1 addition & 4 deletions _scripts/g_factor.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ tar_option_set(
)
setup_parallel_plan()

n_vars_total <- 76
n_steps <- 20

config_vars <- prepare_config_vars(n_vars_total, n_steps)
config_vars <- prepare_config_vars(num_vars_total)
config_cpm <- prepare_config_cpm(
config == "gsr",
task == "wm",
Expand Down
90 changes: 90 additions & 0 deletions _scripts/g_factor_cor_rapm.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
library(targets)
tar_source()
tar_option_set(
packages = c("tidyverse", "bit64", "lavaan"),
format = "qs",
controller = setup_crew_controller("gf")
)
setup_parallel_plan()

config_vars <- prepare_config_vars(
num_vars_total - length(game_id_reasoning),
use_pairs = FALSE
)
config_cpm <- prepare_config_cpm(
config == "gsr",
task == "wm",
run == "full",
thresh_method == "alpha",
thresh_level == 0.01
)
branches_g <- tarchetypes::tar_map(
config_vars,
tarchetypes::tar_rep(
vars_sample,
resample_vars(names(indices_cogstruct), num_vars),
batches = 10,
reps = 10,
iteration = "list",
deployment = "main"
),
tarchetypes::tar_rep2(
fit_g,
lapply_tar_batches(
vars_sample,
fit_efa_g,
data = indices_cogstruct,
missing = "ml"
),
vars_sample,
iteration = "list"
),
tarchetypes::tar_rep2(
scores_g,
lapply_tar_batches(
fit_g,
extract_g_scores,
data = indices_cogstruct
),
fit_g,
iteration = "list"
),
tarchetypes::tar_rep2(
cor_rapm,
lapply_tar_batches(
scores_g,
\(x) {
indices_rapm |>
merge(x, by = "row.names") |>
summarise(r = cor(score, f1, use = "pairwise"))
}
) |>
list_rbind_tar_batches(),
scores_g,
iteration = "list"
)
)

list(
tarchetypes::tar_file_read(
indices_cogstruct,
path_obj_from_proj("indices_cogstruct", "prepare_source_data"),
read = qs::qread(!!.x)
),
tarchetypes::tar_file_read(
indices_rapm,
path_obj_from_proj("indices_rapm", "prepare_source_data"),
read = qs::qread(!!.x)
),
branches_g,
tarchetypes::tar_combine(
cor_rapm,
branches_g$cor_rapm,
command = list(!!!.x) |>
lapply(bind_rows) |>
bind_rows_meta(
.names = names(config_vars),
.prefix = "cor_rapm"
)
)
)
3 changes: 3 additions & 0 deletions _targets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ prepare_neural:
g_factor:
script: _scripts/g_factor.R
store: _targets/g_factor
g_factor_cor_rapm:
script: _scripts/g_factor_cor_rapm.R
store: _targets/g_factor_cor_rapm
explore_factors:
script: _scripts/explore_factors.R
store: _targets/explore_factors
Expand Down

0 comments on commit 353c088

Please sign in to comment.