compute_diff_phase.Rd
Compute a statistic (for example, a mean) based on all matching comparisons (foreground phase) and the same statistic based on all non-matching comparisons (background phases)
compute_diff_phase(scores_list, FUNC = mean, na.rm = TRUE, both = FALSE)
a list of all phases
a function to be applied to both the foreground phase and the background phases
a logical value indicating whether NA values should be stripped before the computation proceeds
logical value. If TRUE
, return the values of the FUNC
for both the foreground phase and the background phases;
if FALSE
, return their difference
If both = TRUE
, return the values of the statistic (calculated by FUNC
) for both the foreground phase and the
background phases; if both = FALSE
, return the difference
library(tidyverse)
#> ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
#> ✔ tibble 3.1.6 ✔ dplyr 1.0.8
#> ✔ tidyr 1.2.0 ✔ stringr 1.4.0
#> ✔ readr 2.1.2 ✔ forcats 0.5.1
#> ✔ purrr 0.3.4
#> ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
#> ✖ dplyr::filter() masks stats::filter()
#> ✖ dplyr::lag() masks stats::lag()
data("bullets")
lands <- unique(bullets$bulletland)
comparisons <- data.frame(expand.grid(land1 = lands[1:6], land2 = lands[7:12]),
stringsAsFactors = FALSE)
comparisons <- comparisons %>%
left_join(bullets %>% select(bulletland, sig1=sigs),
by = c("land1" = "bulletland")) %>%
left_join(bullets %>% select(bulletland, sig2=sigs),
by = c("land2" = "bulletland"))
comparisons <- comparisons %>% mutate(
cmps = purrr::map2(sig1, sig2, .f = function(x, y) {
extract_feature_cmps(x$sig, y$sig, include = "full_result")
})
)
comparisons <- comparisons %>%
mutate(
cmps_score = sapply(comparisons$cmps, function(x) x$CMPS_score),
cmps_nseg = sapply(comparisons$cmps, function(x) x$nseg)
)
cp1 <- comparisons %>% select(land1, land2, cmps_score, cmps_nseg)
cp1 <- cp1 %>% mutate(
land1idx = land1 %>% str_sub(-1, -1) %>% as.numeric(),
land2idx = land2 %>% str_sub(-1, -1) %>% as.numeric()
)
phases <- with(cp1, {
get_all_phases(land1idx, land2idx, cmps_score, addNA = TRUE)
})
compute_diff_phase(phases)
#> [1] 10.96667