Skip to content

Commit

Permalink
Add gss dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
psychelzh committed Sep 23, 2024
1 parent 815c6b2 commit 46e0b06
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 37 deletions.
27 changes: 27 additions & 0 deletions R/mantel.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
calc_mantel <- function(data, ydis, col_xdis = last_col()) {
data |>
mutate(
mantel = map(
pick({{ col_xdis }})[[1]],
\(xdis) vegan::mantel(xdis, ydis)
),
.keep = "unused"
)
}

extract_stats_mantel <- function(data_mantel) {
data_mantel |>
mutate(
map(mantel, tidy_mantel) |>
list_rbind(),
.keep = "unused"
)
}

tidy_mantel <- function(mantel) {
tibble(
statistic = mantel$statistic,
p.value = mantel$signif,
method = mantel$method
)
}
7 changes: 0 additions & 7 deletions R/sync.R

This file was deleted.

8 changes: 0 additions & 8 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ convert_p2_p1 <- function(statistic, p.value,
)
}

tidy_mantel <- function(mantel) {
tibble(
statistic = mantel$statistic,
p.value = mantel$signif,
method = mantel$method
)
}

get_resid <- function(y, x) {
resid(lm(y ~ x, na.action = na.exclude))
}
Expand Down
53 changes: 31 additions & 22 deletions _targets.R
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,31 @@ list(
collect() |>
calc_group_pattern()
),
tar_target(
patterns_group_dynamic,
arrow::read_parquet(file_cca_y) |>
calc_group_pattern_dynamic()
),
tar_target(data_gss_dynamic, calc_mantel(patterns_group_dynamic, pattern_semantics)),
tar_target(stats_gss_dynamic, extract_stats_mantel(data_gss_dynamic)),
tarchetypes::tar_rep(
data_gss_dynamic_permuted,
calc_mantel(
patterns_group_dynamic,
seriation::permute(pattern_semantics, sample.int(150L))
),
reps = 10,
batches = 100
),
tarchetypes::tar_rep2(
stats_gss_dynamic_permuted,
extract_stats_mantel(data_gss_dynamic_permuted),
data_gss_dynamic_permuted
),
tar_target(
clusters_stats_gss_dynamic,
calc_clusters_stats(stats_gss_dynamic, stats_gss_dynamic_permuted)
),
tar_target(
# leave one out
patterns_group_whole_loo,
Expand Down Expand Up @@ -349,10 +374,7 @@ list(
.by = cca_id
)
),
tar_target(
sync_smc,
calc_sync_smc(sync_whole_trials, smc)
),
tar_target(sync_smc, calc_mantel(sync_whole_trials, smc)),
tar_target(
sync_dynamic,
whole_erps |>
Expand All @@ -367,13 +389,14 @@ list(
.by = cca_id
)
),
tar_target(sync_smc_dynamic, calc_mantel(sync_dynamic, smc)),
tar_target(
sync_smc_dynamic,
calc_sync_smc(sync_dynamic, smc)
stats_sync_smc_dynamic,
extract_stats_mantel(sync_smc_dynamic)
),
tarchetypes::tar_rep(
sync_smc_dynamic_permuted,
calc_sync_smc(
calc_mantel(
sync_dynamic,
seriation::permute(smc, sample.int(206L))
),
Expand All @@ -382,23 +405,9 @@ list(
),
tarchetypes::tar_rep2(
stats_sync_smc_dynamic_permuted,
sync_smc_dynamic_permuted |>
mutate(
map(mantel, tidy_mantel) |>
list_rbind(),
.keep = "unused"
),
extract_stats_mantel(sync_smc_dynamic_permuted),
sync_smc_dynamic_permuted
),
tar_target(
stats_sync_smc_dynamic,
sync_smc_dynamic |>
mutate(
map(mantel, tidy_mantel) |>
list_rbind(),
.keep = "unused"
)
),
tar_target(
clusters_stats_sync_smc_dynamic,
stats_sync_smc_dynamic |>
Expand Down

0 comments on commit 46e0b06

Please sign in to comment.