-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c443796
commit c266a80
Showing
4 changed files
with
66 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,44 @@ | ||
|
||
|
||
exper <- demo_joy() |> | ||
mediation_data("PHQ", "treatment", starts_with("ASV")) | ||
fit <- multimedia(exper) |> | ||
estimate(exper) | ||
|
||
test_that("Can nullify treatment to mediator path", { | ||
nullified <- nullify(fit, "T->M") | ||
edges <- nullified@edges |> | ||
tidygraph::activate(edges) |> | ||
as.data.frame() | ||
expect_contains(edges$state, c("active", "inactive")) | ||
expect_equal(as.integer(table(edges$state)), c(12, 5)) | ||
|
||
nullified <- nullify(fit, "T->M") | ||
edges <- nullified@edges |> | ||
tidygraph::activate(edges) |> | ||
as.data.frame() | ||
expect_contains(edges$state, c("active", "inactive")) | ||
expect_equal(as.integer(table(edges$state)), c(12, 5)) | ||
}) | ||
|
||
test_that("Can nullify the mediator to outcome path.", { | ||
nullified <- nullify(fit, "T->Y") | ||
edges <- nullified@edges |> | ||
tidygraph::activate(edges) |> | ||
as.data.frame() | ||
expect_contains(edges$state, c("active", "inactive")) | ||
expect_equal(as.integer(table(edges$state)), c(16, 1)) | ||
nullified <- nullify(fit, "T->Y") | ||
edges <- nullified@edges |> | ||
tidygraph::activate(edges) |> | ||
as.data.frame() | ||
expect_contains(edges$state, c("active", "inactive")) | ||
expect_equal(as.integer(table(edges$state)), c(16, 1)) | ||
}) | ||
|
||
|
||
test_that("Can contrast data simulated from real and synthetic.", { | ||
contrast_data <- fit |> | ||
null_contrast(exper) | ||
expect_named( | ||
contrast_data, | ||
c("source", "outcome", "indirect_setting", "contrast", "direct_effect") | ||
) | ||
expect_equal(unique(contrast_data$source), c("real", "synthetic")) | ||
contrast_data <- fit |> | ||
null_contrast(exper) | ||
expect_named( | ||
contrast_data, | ||
c("source", "outcome", "indirect_setting", "contrast", "direct_effect") | ||
) | ||
expect_equal(unique(contrast_data$source), c("real", "synthetic")) | ||
}) | ||
|
||
test_that("Can compute false discovery rates given contrast data.", { | ||
fdr_data <- fit |> | ||
null_contrast(exper) |> | ||
fdr_summary("direct_effect") | ||
expect_named( | ||
fdr_data, | ||
c("source", "outcome", "direct_effect", "rank", "fdr_hat", "keep") | ||
) | ||
expect_equal(fdr_data$source, c("real", "synthetic")) | ||
}) | ||
fdr_data <- fit |> | ||
null_contrast(exper) |> | ||
fdr_summary("direct_effect") | ||
expect_named( | ||
fdr_data, | ||
c("source", "outcome", "direct_effect", "rank", "fdr_hat", "keep") | ||
) | ||
expect_equal(sort(fdr_data$source), c("real", "synthetic")) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters