From 4b2de41240bc17c5f4acc69affff6fc9f2ef147c Mon Sep 17 00:00:00 2001 From: clabima Date: Fri, 2 Aug 2019 14:43:12 +0200 Subject: [PATCH 1/4] Warning when factorial arguments conflict Warning for which value takes precedence when user inputs both `sd` and `outcome_sds` and they do not match. --- R/factorial_designer.R | 2 ++ tests/testthat/test_designers.R | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/R/factorial_designer.R b/R/factorial_designer.R index ae9ef4ee..36cafbd5 100644 --- a/R/factorial_designer.R +++ b/R/factorial_designer.R @@ -99,6 +99,8 @@ factorial_designer <- function( if(k < 2 || !is_integerish(k)) stop("`k' should be a positive integer > 1.") if(any(outcome_sds<0)) stop("`outcome_sds' should be nonnegative.") if(any(assignment_probs <= 0)) stop("`assignment_probs' should have positive values only.") + if(!is.null(sd) && !is.null(outcome_sds) && outcome_sds != rep(sd, k^2)) + warning("Both `sd` and `outcome_sd` are specified and have different values. Taking value of `outcome_sds`.") # pre-objects ------------------------------------------------------------- diff --git a/tests/testthat/test_designers.R b/tests/testthat/test_designers.R index c5d486cd..b56b1e15 100644 --- a/tests/testthat/test_designers.R +++ b/tests/testthat/test_designers.R @@ -249,7 +249,7 @@ test_that(desc = "two_arm_covariate_designer errors when it should", expect_error(two_arm_covariate_designer(rho_WZ = 10)) }) -test_that(desc = "factorial_designer errors when it should", +test_that(desc = "factorial_designer errors or warns when it should", code = { expect_error(factorial_designer(outcome_name = c("Y "))) expect_error(factorial_designer(outcome_means = 1, k = 2)) @@ -260,6 +260,7 @@ test_that(desc = "factorial_designer errors when it should", expect_error(factorial_designer(k = .5)) expect_error(factorial_designer(outcome_sds = c(-1,-1,-1,-1), k = 2)) expect_error(factorial_designer(assignment_probs = c(-.5,.5), k = 2)) + expect_warning(factorial_designer(k = 2, sd = 1, outcome_sds = rep(.5, 4))) }) test_that(desc = "process_tracing_designer errors when it should", From 068635fe9ab5885dadd2c5a4e9d63977b1550991 Mon Sep 17 00:00:00 2001 From: clabima Date: Fri, 2 Aug 2019 14:57:55 +0200 Subject: [PATCH 2/4] Update check --- R/factorial_designer.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/factorial_designer.R b/R/factorial_designer.R index 36cafbd5..8cda096e 100644 --- a/R/factorial_designer.R +++ b/R/factorial_designer.R @@ -99,7 +99,7 @@ factorial_designer <- function( if(k < 2 || !is_integerish(k)) stop("`k' should be a positive integer > 1.") if(any(outcome_sds<0)) stop("`outcome_sds' should be nonnegative.") if(any(assignment_probs <= 0)) stop("`assignment_probs' should have positive values only.") - if(!is.null(sd) && !is.null(outcome_sds) && outcome_sds != rep(sd, k^2)) + if(!is.null(sd) && !is.null(outcome_sds) && !identical(outcome_sds, rep(sd, 2^k))) warning("Both `sd` and `outcome_sd` are specified and have different values. Taking value of `outcome_sds`.") # pre-objects ------------------------------------------------------------- From 3649287917c422aacfcfbce89ae7e82764058813 Mon Sep 17 00:00:00 2001 From: clabima Date: Fri, 2 Aug 2019 15:11:09 +0200 Subject: [PATCH 3/4] Same warnings for two_by_two --- R/two_by_two_designer.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/two_by_two_designer.R b/R/two_by_two_designer.R index 105b0522..848d673a 100644 --- a/R/two_by_two_designer.R +++ b/R/two_by_two_designer.R @@ -78,6 +78,8 @@ two_by_two_designer <- function(N = 100, if(max(c(sd_i, outcome_sds) < 0) ) stop("sd_i and outcome_sds must be nonnegative") if(max(c(prob_A, prob_B) < 0)) stop("prob_ arguments must be nonnegative") if(max(c(prob_A, prob_B) > 1)) stop("prob_ arguments must not exceed 1") + if(!is.null(outcome_means) && all(!is.null(c(mean_A0B0, mean_A0B1, mean_A1B0, mean_A1B1))) && + !identical(outcome_means, c(mean_A0B0, mean_A0B1, mean_A1B0, mean_A1B1))) stop("prob_ arguments must not exceed 1") {{{ # M: Model From 1794709fb35150003aae714f04b36336b40119ce Mon Sep 17 00:00:00 2001 From: clabima Date: Fri, 2 Aug 2019 15:12:29 +0200 Subject: [PATCH 4/4] Update warning two_by_two --- R/two_by_two_designer.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/two_by_two_designer.R b/R/two_by_two_designer.R index 848d673a..12033f1f 100644 --- a/R/two_by_two_designer.R +++ b/R/two_by_two_designer.R @@ -79,7 +79,7 @@ two_by_two_designer <- function(N = 100, if(max(c(prob_A, prob_B) < 0)) stop("prob_ arguments must be nonnegative") if(max(c(prob_A, prob_B) > 1)) stop("prob_ arguments must not exceed 1") if(!is.null(outcome_means) && all(!is.null(c(mean_A0B0, mean_A0B1, mean_A1B0, mean_A1B1))) && - !identical(outcome_means, c(mean_A0B0, mean_A0B1, mean_A1B0, mean_A1B1))) stop("prob_ arguments must not exceed 1") + !identical(outcome_means, c(mean_A0B0, mean_A0B1, mean_A1B0, mean_A1B1))) stop("Both `outcome_means` and `mean_*` parameters are specified and have different values. Taking value of `mean_*` arguments.") {{{ # M: Model