Skip to content

Commit

Permalink
Merge pull request #205 from kylebutts/main
Browse files Browse the repository at this point in the history
Add a comment explaining `.create_hypotheses_mat`
  • Loading branch information
istallworthy committed Jun 21, 2024
2 parents 270cdaa + 8c5ed86 commit 8d7f87e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)"))
})

0 comments on commit 8d7f87e

Please sign in to comment.