Skip to content

R CMD check Test Failure After Dependency Update #423

@Andrew-Acker125

Description

@Andrew-Acker125

Hello, We've been running R CMD check for packages for our package registry manager PRISM (Home | PRISM ) and noticed that estimatr is failing with the following error:

checking tests Running testthat.R
  Running the tests in tests/testthat.R failed.
  Last 13 lines of output:
    Lengths differ: 10 is not 12
    Failure ('test-iv-robust.R:273:5'): iv_robust matches AER + clubSandwich
    Expected `as.matrix(tidy(ivcrw)[, cols])` to be equivalent to
    `as.matrix(clubsandw[, -1])`.
    Lengths differ: 10 is not 12
    Failure ('test-iv-robust.R:293:5'): iv_robust matches AER + clubSandwich
    Expected `na.omit(as.matrix(tidy(ivcr_rd)[, cols]))` to be equivalent to
    `na.omit(as.matrix(clubsand_rd[, -1]))`.
    Lengths differ: 10 is not 12
    Failure ('test-iv-robust.R:313:5'): iv_robust matches AER + clubSandwich
    Expected `na.omit(as.matrix(tidy(ivcrw_rd)[, cols]))` to be equivalent to
    `na.omit(as.matrix(clubsandw_rd[, -1]))`.
    Lengths differ: 10 is not 12
    [ FAIL 12 | WARN 0 | SKIP 2 | PASS 1317 ]
    Error: ! Test failures.
    Execution halted

Here are the failing tests:

test-iv-robust.R:

test_that("iv_robust matches AER + clubSandwich", {
  skip_if_not_installed("AER")
  skip_if_not_installed("clubSandwich")
  skip_on_cran()

  for (se_type in cr_se_types) {

    ivfit <- AER::ivreg(y ~ x | z, data = dat)
    ivfitw <- AER::ivreg(y ~ x | z, weights = w, data = dat)

    ivcr <- iv_robust(y ~ x | z, data = dat, clusters = clust, se_type = se_type)
    clubsand <- clubSandwich::coef_test(ivfit,
                                        vcov = ifelse(se_type == "stata", "CR1S", se_type),
                                        cluster = dat$clust,
                                        test = ifelse(se_type == "CR2", "Satterthwaite", "naive-t"))
    clubsand <- as.data.frame(clubsand)

    cols <- c("estimate", "std.error", "statistic", "df", "p.value")

    expect_equivalent(
      as.matrix(tidy(ivcr)[, cols]),
      as.matrix(clubsand[,-1])
    )

    expect_equivalent(
      ivfit$fitted.values,
      ivcr$fitted.values
    )

    ivcrw <- iv_robust(y ~ x | z, data = dat, clusters = clust, weights = w, se_type = se_type)
    clubsandw <- clubSandwich::coef_test(ivfitw,
                                         vcov = ifelse(se_type == "stata", "CR1S", se_type),
                                         cluster = dat$clust,
                                         test = ifelse(se_type == "CR2", "Satterthwaite", "naive-t"))
    clubsandw <- as.data.frame(clubsandw)

    expect_equivalent(
      as.matrix(tidy(ivcrw)[, cols]),
      as.matrix(clubsandw[,-1])
    )

    expect_equivalent(
      ivfitw$fitted.values,
      ivcrw$fitted.values
    )

    ivfit_rd <- AER::ivreg(y ~ x + x1_c | z + z2, data = dat)
    ivcr_rd <- iv_robust(y ~ x + x1_c | z + z2, data = dat, clusters = clust, se_type = se_type)
    clubsand_rd <- clubSandwich::coef_test(ivfit_rd,
                                           vcov = ifelse(se_type == "stata", "CR1S", se_type),
                                           cluster = dat$clust,
                                           test = ifelse(se_type == "CR2", "Satterthwaite", "naive-t"))
    clubsand_rd <- as.data.frame(clubsand_rd)

    expect_equivalent(
      na.omit(as.matrix(tidy(ivcr_rd)[, cols])),
      na.omit(as.matrix(clubsand_rd[,-1]))
    )

    expect_equivalent(
      ivfit_rd$fitted.values,
      ivcr_rd$fitted.values
    )

    ivfitw_rd <- AER::ivreg(y ~ x + x1_c | z + z2, weights = w, data = dat)
    ivcrw_rd <- iv_robust(y ~ x + x1_c | z + z2, data = dat, weights = w, clusters = clust, se_type = se_type)
    clubsandw_rd <- clubSandwich::coef_test(ivfitw_rd,
                                            vcov = ifelse(se_type == "stata", "CR1S", se_type),
                                            cluster = dat$clust,
                                            test = ifelse(se_type == "CR2", "Satterthwaite", "naive-t"))
    clubsandw_rd <- as.data.frame(clubsandw_rd)

    expect_equivalent(
      na.omit(as.matrix(tidy(ivcrw_rd)[, cols])),
      na.omit(as.matrix(clubsandw_rd[,-1]))
    )

    expect_equivalent(
      ivfitw_rd$fitted.values,
      ivcrw_rd$fitted.values
    )
  }
})

Investigating the error, we found the root cause of this failure to be clubSandwich 0.6.1, as the tests pass when using a previous version of clubSandwich 0.5.11. It appears that clubSandwich::coef_test() changed its output structure in 0.6.1, which causes the dimension mismatch in the test comparisons. Happy to provide any additional details if helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions