Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Oct 25, 2023
1 parent 44993d1 commit e5a7da7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 30 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ Suggests:
truncreg,
tweedie,
TMB,
VGAM
VGAM,
withr
VignetteBuilder:
knitr
Encoding: UTF-8
Expand Down
26 changes: 15 additions & 11 deletions tests/testthat/test-plm.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,18 @@ test_that("find_statistic", {
expect_identical(find_statistic(m2), "t-statistic")
})

test_that("get_varcov, pgmm", {
data("EmplUK", package = "plm")
mar <- suppressWarnings(plm::pgmm(
log(emp) ~ lag(log(emp), 1:2) + lag(log(wage), 0:1) + log(capital) +
lag(log(capital), 2) + log(output) + lag(log(output), 2) | lag(log(emp), 2:99),
data = EmplUK, effect = "twoways", model = "twosteps"
))
out1 <- sqrt(diag(insight::get_varcov(mar, vcov = "HC1", component = "all")))
validate1 <- sqrt(diag(plm::vcovHC(mar)))
expect_equal(out1, validate1, tolerance = 1e-4, ignore_attr = TRUE)
})
skip_if_not_installed("withr")
withr::with_package(
"plm",
test_that("get_varcov, pgmm", {
data("EmplUK", package = "plm")
mar <- suppressWarnings(plm::pgmm(
log(emp) ~ lag(log(emp), 1:2) + lag(log(wage), 0:1) + log(capital) +
lag(log(capital), 2) + log(output) + lag(log(output), 2) | lag(log(emp), 2:99),
data = EmplUK, effect = "twoways", model = "twosteps"
))
out1 <- sqrt(diag(insight::get_varcov(mar, vcov = "HC1", component = "all")))
validate1 <- sqrt(diag(plm::vcovHC(mar)))
expect_equal(out1, validate1, tolerance = 1e-4, ignore_attr = TRUE)
})
)
38 changes: 20 additions & 18 deletions tests/testthat/test-survfit.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,24 @@ test_that("find_statistic", {
expect_null(find_statistic(m1))
})

test_that("find_predictors works with strata", {
library(survival)
data(mtcars)
mod <- suppressWarnings(survival::clogit(
am ~ mpg + cyl + mpg:cyl + survival::strata(carb, gear),
data = mtcars
))
out <- find_predictors(mod)
expect_identical(out, list(conditional = c("mpg", "cyl"), strata = c("carb", "gear")))
skip_if_not_installed("withr")
withr::with_package(
"survival",
test_that("find_predictors works with strata", {
data(mtcars)
mod <- suppressWarnings(survival::clogit(
am ~ mpg + cyl + mpg:cyl + survival::strata(carb, gear),
data = mtcars
))
out <- find_predictors(mod)
expect_identical(out, list(conditional = c("mpg", "cyl"), strata = c("carb", "gear")))

# works with reserved arguments inside "strata()"
mod <- suppressWarnings(survival::clogit(
am ~ mpg + cyl + mpg:cyl + survival::strata(carb, gear, shortlabel = TRUE),
data = mtcars
))
out <- find_predictors(mod)
expect_identical(out, list(conditional = c("mpg", "cyl"), strata = c("carb", "gear")))
unloadNamespace("survival")
})
# works with reserved arguments inside "strata()"
mod <- suppressWarnings(survival::clogit(
am ~ mpg + cyl + mpg:cyl + survival::strata(carb, gear, shortlabel = TRUE),
data = mtcars
))
out <- find_predictors(mod)
expect_identical(out, list(conditional = c("mpg", "cyl"), strata = c("carb", "gear")))
})
)

0 comments on commit e5a7da7

Please sign in to comment.