Skip to content

Commit

Permalink
adds easier df creation to make sure we only
Browse files Browse the repository at this point in the history
get the comparisons we want, and not have to do any filtering, and then uses glue to get the comparisons out.
  • Loading branch information
rmflight committed Sep 16, 2024
1 parent d3ba885 commit ef30223
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions R/variable_lod_detection.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,11 @@ var_lod_each_cor = function(ref_cor, in_cor)
{
# ref_cor = reference_cor[["icikt_na"]]
# in_cor = var_lod_correlations[["single_cutoff"]][["icikt_na"]]
ref_long = cor_matrix_2_long_df(ref_cor) |>
dplyr::rowwise() |>
dplyr::mutate(comparison = paste0(sort(c(s1, s2)), collapse = ".")) |>
dplyr::ungroup() |>
ref_long = lod_cor_matrix_2_df(ref_cor) |>
dplyr::mutate(comparison = glue::glue("{s1}.{s2}")) |>
dplyr::filter(!(s1 == s2), !duplicated(comparison))
in_long = cor_matrix_2_long_df(in_cor) |>
dplyr::rowwise() |>
dplyr::mutate(comparison = paste0(sort(c(s1, s2)), collapse = ".")) |>
dplyr::ungroup() |>
in_long = lod_cor_matrix_2_df(in_cor) |>
dplyr::mutate(comparison = glue::glue("{s1}.{s2}")) |>
dplyr::filter(!(s1 == s2), !duplicated(comparison))

compare_cor = dplyr::left_join(ref_long[, c("cor", "s1", "s2", "comparison")], in_long[, c("cor", "comparison")], suffix = c("_ref", "_lod"), by = "comparison")
Expand All @@ -152,3 +148,17 @@ triple_check_scalemax_works = function(var_lod_samples)
testthat::expect_equal(sum_lt, nrow(ici_scale$cor) * ncol(ici_scale$cor))
NULL
}

lod_cor_matrix_2_df = function(in_matrix)
{
comparisons = combn(colnames(in_matrix), 2)

cor_vals = vector(mode = "double", length = ncol(comparisons))

for (icol in seq_len(ncol(comparisons))) {
cor_vals[icol] = in_matrix[comparisons[1, icol], comparisons[2, icol]]
}

cor_df = data.frame(s1 = comparisons[1, ], s2 = comparisons[2, ], cor = cor_vals)
cor_df
}

0 comments on commit ef30223

Please sign in to comment.