diff --git a/R/utils.R b/R/utils.R index 34e48b5a..aaa82e46 100644 --- a/R/utils.R +++ b/R/utils.R @@ -270,6 +270,11 @@ perm2 <- function(r, v) { #' #' @keywords internal .create_hypotheses_mat <- function(histories, reference, comparison) { + # Create a matrix with length(histories) rows. + # Each column sets the value -1 for the reference group row + # and the value 1 for the comparison group row. + # When multiplied by the predicted values it does + # R' b = b_comparison - b_reference sub_mats <- lapply(reference, function(ref) { n_cols <- length(comparison) cus_comps <- matrix(0, ncol = n_cols, nrow = length(histories)) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 4bf4e8e4..44990c04 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -12,3 +12,16 @@ test_that(".extract_time_pts_from_vars", { ) expect_equal(unname(x2), c(1, 2, NA)) }) + + +test_that(".create_hypotheses_mat", { + mat = .create_hypotheses_mat( + histories = c("a", "b", "c"), + reference = "c", + comparison = c("a", "b") + ) + + expect_equal(mat[, 1], c(1, 0, -1)) + expect_equal(mat[, 2], c(0, 1, -1)) + expect_equal(colnames(mat), c("(a) - (c)", "(b) - (c)")) +})