Skip to content

Commit

Permalink
fix tests (added design_label to output)
Browse files Browse the repository at this point in the history
  • Loading branch information
acoppock committed Jun 7, 2018
1 parent 3ae5a65 commit a1455cc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 54 deletions.
47 changes: 18 additions & 29 deletions tests/testthat/test-diagnosands.R
Expand Up @@ -88,9 +88,8 @@ test_that("test diagnosands without estimands", {
my_dig <- declare_diagnosands(mean_est = mean(est), sd_est = sd(est), keep_defaults = FALSE)
diagnosis <- diagnose_design(my_design2, sims = 2, diagnosands = my_dig, bootstrap_sims = FALSE)

head(diagnosis$simulations_df)

expect_equal(dim(diagnosis$diagnosands_df), c(1,5))
expect_equal(dim(diagnosis$diagnosands_df), c(1,6))

})

Expand Down Expand Up @@ -167,10 +166,8 @@ test_that("diagnosis, no estimator", {
diagnosand <- declare_diagnosands(z = mean(estimand > 0), keep_defaults = FALSE)

expect_equivalent(diagnose_design(d, diagnosands = diagnosand, sims = 5, bootstrap_sims = 5)$diagnosands_df,
structure(list(estimand_label = c("bar", "foo"), z = c(1, 1), `se(z)` = c(0, 0), n_sims = c(5, 5)),
.Names = c("estimand_label", "z", "se(z)", "n_sims"),
class = "data.frame", row.names = c("bar", "foo"))
)
structure(list(design_label = c("d", "d"), estimand_label = c("bar", "foo"), z = c(1, 1), `se(z)` = c(0, 0), n_sims = c(5L, 5L)), row.names = 1:2, class = "data.frame")
)
})


Expand Down Expand Up @@ -210,17 +207,14 @@ test_that("diagnosis, NAs if no estimand", {
d <- declare_design(sleep, ols = declare_estimator(extra ~ group))

sleep_ols <-
structure(list(estimator_label = "ols", coefficient = "group2",
bias = NA_real_, `se(bias)` = NA_real_, rmse = NA_real_,
`se(rmse)` = NA_real_, power = 0, `se(power)` = 0, coverage = NA_real_,
`se(coverage)` = NA_real_, mean_estimate = 1.58, `se(mean_estimate)` = 0,
sd_estimate = 0, `se(sd_estimate)` = 0, mean_se = 0.849091017238762,
`se(mean_se)` = 0, type_s_rate = NaN, `se(type_s_rate)` = NA_real_,
mean_estimand = NA_real_, `se(mean_estimand)` = NA_real_, n_sims = 4), .Names = c("estimator_label",
"coefficient", "bias", "se(bias)", "rmse", "se(rmse)", "power",
"se(power)", "coverage", "se(coverage)", "mean_estimate", "se(mean_estimate)",
"sd_estimate", "se(sd_estimate)", "mean_se", "se(mean_se)", "type_s_rate",
"se(type_s_rate)", "mean_estimand", "se(mean_estimand)", "n_sims"), row.names = "ols.group2", class = "data.frame")
structure(list(design_label = "d", estimator_label = "ols", coefficient = "group2",
bias = NA_real_, `se(bias)` = NA_real_, rmse = NA_real_,
`se(rmse)` = NA_real_, power = 0, `se(power)` = 0, coverage = NA_real_,
`se(coverage)` = NA_real_, mean_estimate = 1.58, `se(mean_estimate)` = 0,
sd_estimate = 0, `se(sd_estimate)` = 0, mean_se = 0.849091017238762,
`se(mean_se)` = 0, type_s_rate = NaN, `se(type_s_rate)` = NA_real_,
mean_estimand = NA_real_, `se(mean_estimand)` = NA_real_,
n_sims = 4L), row.names = 1L, class = "data.frame")


expect_equivalent(diagnose_design(d, sims = 4, bootstrap_sims = 5)$diagnosands_df, sleep_ols)
Expand All @@ -231,19 +225,14 @@ test_that("diagnosis, NAs if no estimand", {
d <- declare_design(sleep, mu = declare_estimand(mean(extra)))

sleep_ols <-
structure(list(estimand_label = "mu", bias = NA_real_, `se(bias)` = NA_real_,
rmse = NA_real_, `se(rmse)` = NA_real_, power = NA_real_,
`se(power)` = NA_real_, coverage = NA_real_, `se(coverage)` = NA_real_,
mean_estimate = NA_real_, `se(mean_estimate)` = NA_real_,
sd_estimate = NA_real_, `se(sd_estimate)` = NA_real_, mean_se = NA_real_,
`se(mean_se)` = NA_real_, type_s_rate = NA_real_, `se(type_s_rate)` = NA_real_,
mean_estimand = 1.54, `se(mean_estimand)` = 0, n_sims = 4), .Names = c("estimand_label",
"bias", "se(bias)", "rmse", "se(rmse)", "power", "se(power)",
"coverage", "se(coverage)", "mean_estimate", "se(mean_estimate)",
"sd_estimate", "se(sd_estimate)", "mean_se", "se(mean_se)", "type_s_rate",
"se(type_s_rate)", "mean_estimand", "se(mean_estimand)", "n_sims"), row.names = "mu", class = "data.frame")
structure(list(design_label = "d", estimand_label = "mu", bias = NA_real_,
`se(bias)` = NA_real_, rmse = NA_real_, `se(rmse)` = NA_real_,
power = NA_real_, `se(power)` = NA_real_, coverage = NA_real_,
`se(coverage)` = NA_real_, mean_estimate = NA_real_, `se(mean_estimate)` = NA_real_,
sd_estimate = NA_real_, `se(sd_estimate)` = NA_real_, mean_se = NA_real_,
`se(mean_se)` = NA_real_, type_s_rate = NA_real_, `se(type_s_rate)` = NA_real_,
mean_estimand = 1.54, `se(mean_estimand)` = 0, n_sims = 4L), row.names = 1L, class = "data.frame")
expect_equivalent(diagnose_design(d, sims = 4)$diagnosands_df, sleep_ols)

})

test_that("error if diagnosand not named", {
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-factorial.R
Expand Up @@ -38,8 +38,8 @@ test_that("Factorial", {

diagnosis <- diagnose_design(my_design, sims = 2, bootstrap_sims = FALSE)

expect_equal(diagnosis %>% get_simulations %>% dim, c(2, 10))
expect_equal(diagnosis %>% get_simulations %>% dim, c(2, 11))

expect_equal(diagnosis %>% get_diagnosands %>% dim, c(1,13))
expect_equal(diagnosis %>% get_diagnosands %>% dim, c(1,14))

})
19 changes: 0 additions & 19 deletions tests/testthat/test-function-expand.R
Expand Up @@ -54,22 +54,3 @@ test_that("expand_design works",{
})


library(DesignLibrary)

designs1 = expand_design(simple_two_arm_designer, rho = c(.3, .4), prefix = "rho_design")

designs2 = expand_design(simple_two_arm_designer, N = 6:7, ate = 1:2, prefix = "mo_design")

designs3 <- c(designs1, designs2)

sims1 <- simulate_design(designs1, sims = 2)
sims2 <- simulate_design(designs2, sims = 2)
sims3 <- simulate_design(designs3, sims = 2)


diag1 <- diagnose_design(designs1, sims = 2, bootstrap_sims = FALSE)
str(diag1)
diag2 <- diagnose_design(designs2, sims = 2, bootstrap_sims = FALSE)
str(diag2)
diag3 <- diagnose_design(designs3, sims = 2, bootstrap_sims = FALSE)
str(diag3)
8 changes: 4 additions & 4 deletions tests/testthat/test-multiple-coefficients.R
@@ -1,6 +1,6 @@
context("Factorial Design")
context("Multiple Coefficients")

test_that("Factorial", {
test_that("Multiple Coefficients", {

alpha = 1
beta = 3
Expand All @@ -23,8 +23,8 @@ test_that("Factorial", {

diagnosis <- diagnose_design(my_design, sims = 2, bootstrap_sims = FALSE)

expect_equal(diagnosis %>% get_simulations %>% dim, c(4, 10))
expect_equal(diagnosis %>% get_simulations %>% dim, c(4, 11))

expect_equal(diagnosis %>% get_diagnosands %>% dim, c(2,13))
expect_equal(diagnosis %>% get_diagnosands %>% dim, c(2,14))

})

0 comments on commit a1455cc

Please sign in to comment.