Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/testthat/test-condition-pr-matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ test_that("Complete randomization", {
})

test_that("declaration to condition_pr_mat errors", {
skip_if_not_installed("randomizr")

expect_error(
declaration_to_condition_pr_mat(randomizr::declare_ra(N = n), 1, NULL),
Expand All @@ -41,6 +42,7 @@ test_that("declaration to condition_pr_mat errors", {
})

test_that("condition args work properly", {
skip_if_not_installed("randomizr")

# Condition args work properly
mat01 <- declaration_to_condition_pr_mat(
Expand All @@ -61,6 +63,7 @@ test_that("condition args work properly", {
})

test_that("Complete randomization with number of treated units not fixed", {
skip_if_not_installed("randomizr")

#
comp_odd_ra <- randomizr::declare_ra(N = 3, prob = 0.5)
Expand All @@ -83,6 +86,7 @@ test_that("Complete randomization with number of treated units not fixed", {
})

test_that("Complete randomization with non 0.5 as remainder", {
skip_if_not_installed("randomizr")
comp_odd_ra <- randomizr::declare_ra(N = 3, prob = 0.4)
decl_cond_pr_mat <- declaration_to_condition_pr_mat(comp_odd_ra)

Expand All @@ -95,6 +99,7 @@ test_that("Complete randomization with non 0.5 as remainder", {
)
})
test_that("Simple ra", {
skip_if_not_installed("randomizr")

# Simple randomization
prs <- rep(0.4, times = n)
Expand All @@ -113,6 +118,7 @@ test_that("Simple ra", {
)
})
test_that("Blocked complete ra", {
skip_if_not_installed("randomizr")

# Blocked case
dat <- data.frame(
Expand All @@ -129,6 +135,8 @@ test_that("Blocked complete ra", {
)
})
test_that("Blocked complete ra with remainder", {
skip_if_not_installed("randomizr")

dat <- data.frame(
bl = c("A", "B", "A", "B", "B", "B"),
pr = c(0.5, 0.25, 0.5, 0.25, 0.25, 0.25)
Expand All @@ -147,6 +155,7 @@ test_that("Blocked complete ra with remainder", {
)
})
test_that("Clustered complete ra", {
skip_if_not_installed("randomizr")

# Cluster complete case
dat <- data.frame(
Expand All @@ -173,6 +182,7 @@ test_that("Clustered complete ra", {
})

test_that("Clustered ra", {
skip_if_not_installed("randomizr")

# Cluster simple ? Should this be simple or no? --NJF
dat <- data.frame(
Expand Down Expand Up @@ -204,6 +214,7 @@ test_that("Clustered ra", {
})

test_that("Blocked and Clustered ra", {
skip_if_not_installed("randomizr")

# Blocked and clustered
dat <- data.frame(
Expand All @@ -221,6 +232,7 @@ test_that("Blocked and Clustered ra", {
})

test_that("Blocked and clusted ra with remainder", {
skip_if_not_installed("randomizr")

# with remainder
dat <- data.frame(
Expand All @@ -238,6 +250,8 @@ test_that("Blocked and clusted ra with remainder", {
})

test_that("Custom ra", {
skip_if_not_installed("randomizr")

cust_perms <- cbind(c(1, 0, 1, 0), c(1, 1, 0, 0))
cust_ra <- randomizr::declare_ra(permutation_matrix = cust_perms)

Expand All @@ -248,6 +262,7 @@ test_that("Custom ra", {
})

test_that("Errors for things that we can't support", {
skip_if_not_installed("randomizr")

#
# multiple armed experiments
Expand Down Expand Up @@ -275,6 +290,8 @@ test_that("Errors for things that we can't support", {
})

test_that("probability not fixed within blocks", {
skip_if_not_installed("randomizr")

bl_small <- randomizr::declare_ra(
blocks = c(1, 1, 2, 2),
prob = 0.4
Expand All @@ -295,6 +312,7 @@ test_that("probability not fixed within blocks", {
})

test_that("N=2, m=1", {
skip_if_not_installed("randomizr")

comp <- randomizr::declare_ra(N = 2, m = 1)
assign(
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-difference-in-means.R
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ test_that("DIM works with character args", {
})

test_that("DIM unbiased", {
skip_if_not_installed("randomizr")

dat <- data.frame(
i = 1:10,
Y0 = c(
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-horvitz-thompson.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ test_that("Horvitz-Thompson matches d-i-m under certain conditions", {
})

test_that("Horvitz-Thompson works in simple case", {
skip_if_not_installed("randomizr")

n <- 40
dat <- data.frame(
y = rnorm(n)
Expand Down Expand Up @@ -167,6 +169,8 @@ test_that("Horvitz-Thompson works in simple case", {
})

test_that("Horvitz-Thompson works with clustered data", {
skip_if_not_installed("randomizr")

n <- 8
dat <- data.frame(
y = rnorm(n),
Expand Down Expand Up @@ -339,6 +343,8 @@ test_that("Horvitz-Thompson works with clustered data", {
})

test_that("Horvitz-Thompson works with missingness", {
skip_if_not_installed("randomizr")

n <- 40
dat <- data.frame(
y = rnorm(n),
Expand Down Expand Up @@ -386,6 +392,8 @@ test_that("Horvitz-Thompson works with missingness", {

# test blocks in the data
test_that("Estimating Horvitz-Thompson can be done two ways with blocks", {
skip_if_not_installed("randomizr")

n <- 40
dat <- data.frame(
y = rnorm(n),
Expand Down Expand Up @@ -449,6 +457,8 @@ test_that("Estimating Horvitz-Thompson can be done two ways with blocks", {

# errors when arguments are passed that shouldn't be together
test_that("Horvitz-Thompson properly checks arguments and data", {
skip_if_not_installed("randomizr")

n <- 8
dat <- data.frame(
y = rnorm(n),
Expand Down Expand Up @@ -618,6 +628,8 @@ test_that("Works without variation in treatment", {
})

test_that("multi-valued treatments not allowed in ra_declaration", {
skip_if_not_installed("randomizr")

dat <- data.frame(
y = rnorm(20),
ps = 0.4
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-lm-cluster.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ test_that("lm cluster se", {

lm_interact_simple <- lm(Y ~ Z * X, data = dat)

skip_if_not_installed("sandwich")
bm_interact <-
BMlmSE(
lm_interact_simple,
Expand Down Expand Up @@ -357,6 +358,8 @@ test_that("lm works with quoted or unquoted vars and withor without factor clust
})

test_that("Clustered SEs work with clusters of size 1", {
skip_if_not_installed("sandwich")

dat <- data.frame(
Y = rnorm(100),
X = rnorm(100),
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-lm-robust.R
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ test_that("multiple outcomes", {
vcov(lmro)
)

skip_if_not_installed("sandwich")
for (se_type in setdiff(se_types, "classical")) {
expect_equal(
sandwich::vcovHC(lmo, type = se_type),
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-replicate-HT-middleton.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
context("Verification - HT matches Joel Middleton code")

test_that("We match Joel's estimator", {
skip_if_not_installed("randomizr")

# Code from Joel Middleton
n <- 400
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-s3-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ test_that("tidy, glance, summary, and print work", {
)

## lh_robust
skip_if_not_installed("car")
lho <- lh_robust(
mpg ~ cyl + am,
data = mtcars,
Expand Down Expand Up @@ -1078,6 +1079,7 @@ test_that("update works", {
})

test_that("setting different alpha in lm_robust call leads to different CIs in tidy", {
skip_if_not_installed("fabricatr")

set.seed(15)
library(fabricatr)
Expand All @@ -1103,6 +1105,7 @@ test_that("setting different alpha in lm_robust call leads to different CIs in t
})

test_that("conf int for lh_robust works", {
skip_if_not_installed("fabricatr")

set.seed(15)
library(fabricatr)
Expand Down