Skip to content

Commit

Permalink
Merge 12ae3f3 into 75f9fe0
Browse files Browse the repository at this point in the history
  • Loading branch information
mbannick authored Oct 19, 2024
2 parents 75f9fe0 + 12ae3f3 commit 7c57671
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ Imports:
Suggests:
knitr,
rmarkdown,
testthat (>= 3.0)
testthat (>= 3.0),
RobinCar
VignetteBuilder:
knitr
Config/testthat/edition: 3
Expand Down
55 changes: 55 additions & 0 deletions tests/testthat/test-validate-robin_glm.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
library(RobinCar)

# Compare RobinCar2 to RobinCar results
# -------------------------------------

test_that("simple randomization, difference contrast", {
# Function to compare RobinCar to RobinCar2 outputs
compare <- function(r1, r2) {
# Estimates and variance from RobinCar
estimates1 <- unname(r1$contrast$result$estimate)
variances1 <- unname(r1$contrast$result$se**2)

# Estimates and variance for the first two
# contrast vector elements from RobinCar2
estimates2 <- attributes(r2)$effects[-3]
variances2 <- attributes(r2)$variance[-3]

testthat::expect_equal(estimates1, estimates2)
}

for (family in list(gaussian, binomial)) {
for (model in c(
"~ treatment",
"~ treatment * covar",
"~ treatment * (covar + s1)"
)) {
# Set formula based on parameters
yname <- ifelse(identical(family, binomial), "y_b", "y")
form <- as.formula(paste0(yname, model))

# Use RobinCar2
robincar2 <- robin_glm(
form,
data = dummy_data,
treatment = "treatment",
vcov = vcovANHECOVA,
family = family
)

# Use RobinCar
robincar1 <- robincar_glm(
df = dummy_data,
treat_col = "treatment",
response_col = yname,
formula = form,
car_scheme = "simple",
g_family = family,
contrast_h = "diff"
)

# Compare the results
compare(robincar1, robincar2)
}
}
})

0 comments on commit 7c57671

Please sign in to comment.