-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
9673fa1
commit 4ea5c13
Showing
13 changed files
with
181 additions
and
26 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 |
---|---|---|
|
@@ -22,6 +22,7 @@ License: GPL-3 | |
Depends: R (>= 3.0.1) | ||
Imports: | ||
car, | ||
cli, | ||
doParallel, | ||
foreach, | ||
parallel, | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#' | ||
#' Check variables | ||
#' | ||
#' @keywords internal | ||
#' | ||
|
||
check_params <- function(x, params) { | ||
params_in <- params[which(params %in% names(x))] | ||
params_out <- params[which(!params %in% names(x))] | ||
|
||
if (length(params_in) == 0) { | ||
if (length(params) > 1) { | ||
cli::cli_abort( | ||
"{.val {params}} are not variables in {.arg x}" | ||
) | ||
} else { | ||
cli::cli_abort( | ||
"{.val {params}} is not a variable in {.arg x}" | ||
) | ||
} | ||
} else { | ||
if (length(params_in) == length(params)) { | ||
if (length(params) == 1) { | ||
cli::cli_alert_success( | ||
"{.val {params}} is a variable in {.arg x}" | ||
) | ||
} else { | ||
cli::cli_alert_success( | ||
"{.val {params}} are variables in {.arg x}" | ||
) | ||
} | ||
} else { | ||
if (length(params_in) == 1) { | ||
cli::cli_bullets( | ||
c( | ||
"v" = "{.val {params_in}} is a variable in {.arg x}", | ||
"!" = ifelse( | ||
length(params_out) > 1, | ||
"{.val {params_out}} are not variables in {.arg x}", | ||
"{.val {params_out}} is not a variable in {.arg x}" | ||
), | ||
"i" = "Returning {.val {params_in}}" | ||
) | ||
) | ||
} else { | ||
cli::cli_bullets( | ||
c( | ||
"v" = "{.val {params_in}} are variables in {.arg x}", | ||
"!" = ifelse( | ||
length(params_out) > 1, | ||
"{.val {params_out}} are not variables in {.arg x}", | ||
"{.val {params_out}} is not a variable in {.arg x}" | ||
), | ||
"i" = "Returning {.val {params_in}}" | ||
) | ||
) | ||
} | ||
} | ||
} | ||
|
||
params_in | ||
} |
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 |
---|---|---|
|
@@ -15,6 +15,7 @@ PSU | |
PSUs | ||
RapidSurveys | ||
Ruel | ||
codecov | ||
doi | ||
ncol | ||
nrow | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Tests for boot_bw functions -------------------------------------------------- | ||
|
||
test_that("boot_bw_weight works as expected", { | ||
expect_s3_class(boot_bw_weight(villageData), "data.frame") | ||
expect_true( | ||
all( | ||
c("psu", "pop", "weight", "cumWeight") %in% | ||
names(boot_bw_weight(villageData)) | ||
) | ||
) | ||
expect_type( | ||
boot_bw_sample_clusters( | ||
indicatorsHH, w = boot_bw_weight(villageData), index = TRUE | ||
), | ||
"integer" | ||
) | ||
}) | ||
|
||
mean_boot <- boot_bw( | ||
x = indicatorsHH, w = boot_bw_weight(villageData), | ||
statistic = bootClassic, params = "anc1", replicates = 9 | ||
) | ||
|
||
test_that("boot_bw works as expected", { | ||
expect_s3_class(mean_boot, "data.frame") | ||
}) | ||
|
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,13 +1,27 @@ | ||
library(bbw) | ||
context("Bootstrap function for means/proportions") | ||
# Tests for bootClassic -------------------------------------------------------- | ||
|
||
xMean <- bootClassic(x = indicatorsHH, | ||
params = c("anc1", "anc2", "anc3", "anc4")) | ||
boot <- boot_bw_sample_clusters( | ||
indicatorsHH, boot_bw_weight(villageData) | ||
) |> | ||
boot_bw_sample_within_clusters() | ||
|
||
xMean <- bootClassic( | ||
x = boot, params = c("anc1", "anc2", "anc3", "anc4") | ||
) | ||
|
||
test_that("xMean is a numeric vector", { | ||
expect_is(xMean, "numeric") | ||
expect_type(xMean, "double") | ||
}) | ||
|
||
test_that("xMean length is length of params", { | ||
expect_equal(length(xMean), 4) | ||
}) | ||
|
||
test_that("bootClassic errors and messages as expected", { | ||
expect_error(bootClassic(boot, c("anc"))) | ||
expect_message(bootClassic(boot, c("anc", "anc1"))) | ||
expect_message(bootClassic(boot, c("anc", "anc1", "anc2"))) | ||
expect_message(bootClassic(boot, c("anc", "test", "anc1", "anc2"))) | ||
}) | ||
|
||
|
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,10 +1,17 @@ | ||
library(bbw) | ||
context("Bootstrap function for PROBIT") | ||
# Tests for bootPROBIT --------------------------------------------------------- | ||
|
||
xProbit <- bootPROBIT(x = indicatorsCH1, | ||
boot <- boot_bw_sample_clusters(indicatorsCH1, boot_bw_weight(villageData)) |> | ||
boot_bw_sample_within_clusters() | ||
|
||
xProbit <- bootPROBIT(x = boot, | ||
params = "muac1", | ||
threshold = 115) | ||
|
||
test_that("xProbit is a numeric vector", { | ||
expect_is(xProbit, "numeric") | ||
}) | ||
|
||
test_that("bootPROBIT errors and messages work as expected", { | ||
expect_error(bootPROBIT(boot, "test")) | ||
expect_error(bootPROBIT(boot, c("test", "not"))) | ||
}) |