Skip to content

Commit

Permalink
Tests and updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ngreifer committed Feb 23, 2024
1 parent 8eb02ce commit 595d8e9
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 15 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: cobalt
Title: Covariate Balance Tables and Plots
Version: 4.5.3.9000
Version: 4.5.3.9001
Authors@R: c(
person("Noah", "Greifer", role=c("aut", "cre"),
email = "noah.greifer@gmail.com",
Expand Down Expand Up @@ -54,4 +54,4 @@ URL: https://ngreifer.github.io/cobalt/,
BugReports: https://github.com/ngreifer/cobalt/issues
Config/testthat/edition: 3
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export(splitfactor)
export(unsplitfactor)
export(var.names)
import(stats)
import(utils)
importFrom(crayon,italic)
importFrom(crayon,underline)
importFrom(ggplot2,.data)
Expand Down
8 changes: 8 additions & 0 deletions do_not_include/tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ ps.out.s <- ps(f.build("treat", covs), data = lalonde,
bal.tab(ps.out.s, un = T)
bal.tab(covs, lalonde$treat, weights = get.w(ps.out.s), s.weights = sampw,
un = T, distance = ps.out.s$ps)

mnps.out <- mnps(f.build("race", covs[-3]), data = lalonde,
stop.method = c("ks.max", "es.max"),
estimand = "ATT", treatATT = "white",
verbose = FALSE, n.trees = 2000, bag.fraction = .6)

bal.tab(mnps.out)

#CBPS: binary
library("CBPS")
cbps.out <- CBPS(treat ~ log(age)*married + poly(educ,2) + rcs(age,3) + race + factor(nodegree) + re74 + re75, data = lalonde, ATT = F)
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-bal.tab.data.frame.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ test_that("bal.tab() works with data.frames", {
sw <- runif(nrow(lalonde))
dist <- runif(nrow(lalonde))

expect_s3_class(bal.tab(covs, treat = lalonde$treat), "bal.tab")
expect_s3_class(bal.tab(covs, treat = lalonde$treat, distance = dist,
expect_s3_class(bal.tab(covs, treat = lalonde$treat, s.d.denom = "pooled"), "bal.tab")
expect_s3_class(bal.tab(covs, treat = lalonde$treat, s.d.denom = "pooled", distance = dist,
weights = w, s.weights = sw), "bal.tab")
expect_s3_class(bal.tab(covs, treat = lalonde$treat, distance = dist,
expect_s3_class(bal.tab(covs, treat = lalonde$treat, s.d.denom = "pooled", distance = dist,
weights = w, s.weights = sw, cluster = lalonde$race), "bal.tab.cluster")
expect_s3_class(bal.tab(covs, treat = lalonde$race, distance = dist,
expect_s3_class(bal.tab(covs, treat = lalonde$race, s.d.denom = "pooled", distance = dist,
weights = w, s.weights = sw), "bal.tab.multi")
})
32 changes: 24 additions & 8 deletions tests/testthat/test-github-issues.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Tests for specific github issues

skip_on_cran()
test_that("(#71) `addl` argument not throwing correct error when variable not available", {
#Note: actual error was something else, but addl should have thrown a more informative error
skip_if_not_installed("MatchIt")
Expand All @@ -13,7 +13,7 @@ test_that("(#71) `addl` argument not throwing correct error when variable not av
fixed = TRUE)

expect_no_condition(bal.tab(m, addl = "race", data = lalonde))
})
})

test_that("(#74) bal.tab() works with mnps objects", {
skip_if_not_installed("twang")
Expand All @@ -37,17 +37,20 @@ test_that("(#76) bal.tab() doesn't produce an error with missing covariates", {

data("lalonde_mis")

expect_no_error(
b <- bal.tab(treat ~ age + educ + race + married + nodegree + re74 + re75,
data = lalonde_mis)
)
expect_warning(
b <- bal.tab(treat ~ age + educ + race + married + nodegree + re74 + re75,
data = lalonde_mis),
data = lalonde_mis, s.d.denom = "pooled"),
"Missing values exist in the covariates. Displayed values omit these observations.",
fixed = TRUE
)

expect_no_error(
suppressWarnings(
b <- bal.tab(treat ~ age + educ + race + married + nodegree + re74 + re75,
data = lalonde_mis, s.d.denom = "pooled")
)
)

expect_identical(rownames(b$Balance),
c("age", "educ", "race_black", "race_hispan", "race_white",
"married", "married:<NA>", "nodegree",
Expand All @@ -63,4 +66,17 @@ test_that("(#77) no conflict with `cluster` argument to bal.tab() when {caret} i

expect_no_condition(bal.tab(treat ~ age + educ + race, data = lalonde, cluster = "married",
s.d.denom = "pooled"))
})
})

test_that("(#82) love.plot() doesn't throw any ggplo2-related warnings with multiple stats", {
skip_if_not_installed("MatchIt")

data("lalonde")

m.out <- MatchIt::matchit(treat ~ age + educ + race + married +
nodegree + re74 + re75,
data = lalonde)

expect_no_condition(love.plot(m.out, stats = c("mean.diffs", "variance.ratios"),
binary = "std"))
})

0 comments on commit 595d8e9

Please sign in to comment.