Skip to content

Commit

Permalink
Merge pull request #372 from DeclareDesign/cran-patch-again
Browse files Browse the repository at this point in the history
lfe tests removed per CRAN email
  • Loading branch information
graemeblair authored Feb 26, 2021
2 parents 1820dc9 + e3439a7 commit 23154bc
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 226 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: estimatr
Type: Package
Title: Fast Estimators for Design-Based Inference
Version: 0.30.0
Version: 0.30.2
Authors@R: c(person("Graeme", "Blair", email = "[email protected]", role = c("aut", "cre")),
person("Jasper", "Cooper", email = "[email protected]", role = c("aut")),
person("Alexander", "Coppock", email = "[email protected]", role = c("aut")),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# estimatr 0.30.1

* Remove lfe from tests

# estimatr 0.30.0

* Test suite changes (skip if not installed for checking against other packages)
Expand Down
6 changes: 4 additions & 2 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
## Submission

Thank you for accepting this patch, which skips tests for suggests packages if they are not installed per email from Prof. Ripley. This fixes all ERRORs on CRAN now. This also addresses the DOI problems raised in the submission.
Thank you for accepting this patch, which addresses the issue raised by Kurt that we had an unstated dependency on lfe. We removed the tests associated with lfe.

There are no changes to worse in reverse depends.

We have checked this in win builder and on OS X, linux, and Windows in release, oldrel, and devel on Github Actions with no issues.
We have checked this in win builder and on OS X, linux, and Windows in release, oldrel, and devel on Github Actions with no issues.


133 changes: 0 additions & 133 deletions tests/testthat/test-iv-robust-fes.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,139 +104,6 @@ test_that("FE matches with multiple FEs and covars", {
}
})

test_that("IV FE matches lfe including proj r2", {
skip_if_not_installed("lfe")
skip_on_cran()
## unweighted

## Classical
rfo <- iv_robust(Y ~ X1 + X2 | Z + X2, fixed_effects = ~ B + B2, data = dat, se_type = "classical")
feo <- lfe::felm(Y ~ X2 | B + B2 | (X1 ~ Z), data = dat)
sfeo <- lfe:::summary.felm(feo)

expect_equivalent(
tidy(rfo)[rfo$term %in% c("X1", "X2"), c("estimate", "std.error")],
data.frame(feo$coefficients, feo$se)[c(2, 1), ]
)

expect_equivalent(
rfo[c("r.squared", "adj.r.squared", "proj_r.squared", "proj_adj.r.squared")],
sfeo[c("r.squared", "adj.r.squared", "P.r.squared", "P.adj.r.squared")]
)

expect_equivalent(
rfo[["proj_fstatistic"]],
sfeo[["P.fstat"]][c("F", "df1", "df2")]
)

## HC1
rfo <- iv_robust(Y ~ X1 + X2 | Z + X2, fixed_effects = ~ B + B2, data = dat, se_type = "HC1")

feo <- lfe::felm(Y ~ X2 | B + B2 | (X1 ~ Z), data = dat)
sfeo <- lfe:::summary.felm(feo, robust = T)

expect_equivalent(
tidy(rfo)[rfo$term %in% c("X1", "X2"), c("estimate", "std.error")],
data.frame(feo$coefficients, sqrt(diag(feo$robustvcv)))[c(2, 1), ]
)

expect_equivalent(
rfo[c("r.squared", "adj.r.squared", "proj_r.squared", "proj_adj.r.squared")],
sfeo[c("r.squared", "adj.r.squared", "P.r.squared", "P.adj.r.squared")]
)

expect_equivalent(
rfo[["proj_fstatistic"]],
sfeo[["P.fstat"]][c("F", "df1", "df2")]
)

## CR1stata
rfo <- iv_robust(Y ~ X1 + X2 | Z + X2, fixed_effects = ~ B + B2, clusters = cl, data = dat, se_type = "stata")
feo <- lfe::felm(Y ~ X2 | B + B2 | (X1 ~ Z) | cl, data = dat)

sfeo <- lfe:::summary.felm(feo)

expect_equivalent(
tidy(rfo)[rfo$term %in% c("X1", "X2"), c("estimate", "std.error")],
data.frame(feo$coefficients, sqrt(diag(feo$clustervcv)))[c(2, 1), ]
)

expect_equivalent(
rfo[c("r.squared", "adj.r.squared", "proj_r.squared", "proj_adj.r.squared")],
sfeo[c("r.squared", "adj.r.squared", "P.r.squared", "P.adj.r.squared")]
)

expect_true(
max(abs(
rfo[["proj_fstatistic"]] - sfeo[["P.fstat"]][c("F", "df1", "df2")]
)) < 1e-7
)

## Weighted
rfo <- iv_robust(Y ~ X1 + X2 | Z + X2, fixed_effects = ~ B + B2, data = dat, weights = w, se_type = "classical")
feo <- lfe::felm(Y ~ X2 | B + B2 | (X1 ~ Z), data = dat, weights = dat$w)
sfeo <- lfe:::summary.felm(feo)

expect_equivalent(
tidy(rfo)[rfo$term %in% c("X1", "X2"), c("estimate", "std.error")],
data.frame(feo$coefficients, feo$se)[c(2, 1), ]
)

expect_equivalent(
rfo[c("r.squared", "adj.r.squared", "proj_r.squared", "proj_adj.r.squared")],
sfeo[c("r.squared", "adj.r.squared", "P.r.squared", "P.adj.r.squared")]
)

expect_equivalent(
rfo[["proj_fstatistic"]],
sfeo[["P.fstat"]][c("F", "df1", "df2")]
)

## HC1
rfo <- iv_robust(Y ~ X1 + X2 | Z + X2, fixed_effects = ~ B + B2, data = dat, weights = w, se_type = "HC1")

feo <- lfe::felm(Y ~ X2 | B + B2 | (X1 ~ Z), data = dat, weights = dat$w)
sfeo <- lfe:::summary.felm(feo, robust = T)

expect_equivalent(
tidy(rfo)[rfo$term %in% c("X1", "X2"), c("estimate", "std.error")],
data.frame(feo$coefficients, sqrt(diag(feo$robustvcv)))[c(2, 1), ]
)

expect_equivalent(
rfo[c("r.squared", "adj.r.squared", "proj_r.squared", "proj_adj.r.squared")],
sfeo[c("r.squared", "adj.r.squared", "P.r.squared", "P.adj.r.squared")]
)

expect_equivalent(
rfo[["proj_fstatistic"]],
sfeo[["P.fstat"]][c("F", "df1", "df2")]
)

## CR1stata
rfo <- iv_robust(Y ~ X1 + X2 | Z + X2, fixed_effects = ~ B + B2, clusters = cl, data = dat, weights = w, se_type = "stata")
feo <- lfe::felm(Y ~ X2 | B + B2 | (X1 ~ Z) | cl, data = dat, weights = dat$w)

sfeo <- lfe:::summary.felm(feo)

expect_equivalent(
tidy(rfo)[rfo$term %in% c("X1", "X2"), c("estimate", "std.error")],
data.frame(feo$coefficients, sqrt(diag(feo$clustervcv)))[c(2, 1), ]
)

expect_equivalent(
rfo[c("r.squared", "adj.r.squared", "proj_r.squared", "proj_adj.r.squared")],
sfeo[c("r.squared", "adj.r.squared", "P.r.squared", "P.adj.r.squared")]
)

expect_true(
max(abs(
rfo[["proj_fstatistic"]] - sfeo[["P.fstat"]][c("F", "df1", "df2")]
)) < 1e-6
)

})

test_that("IV FE warns about diagnostics", {

expect_warning(
Expand Down
90 changes: 0 additions & 90 deletions tests/testthat/test-lm-robust-fes.R
Original file line number Diff line number Diff line change
Expand Up @@ -337,26 +337,6 @@ test_that("FEs handle collinear FEs", {
}
}

# lo <- lfe::felm(Y ~ Z + X|B + B2 + Bdup, data = dat)
#
# mtcars$cyl2 <- mtcars$cyl
# # Doesn't properly deal if collinearity not in first two
# lfe:::summary.felm(lfe::felm(mpg ~ hp | cyl + am + cyl2, data = mtcars))$coefficients
# library(estimatr)
# mtcars$cyl2 <- mtcars$cyl
# tidy(lm_robust(mpg ~ hp, fixed_effects = ~ cyl + cyl2 + am, data = mtcars))
#
# tidy(lm_robust(mpg ~ hp, fixed_effects = ~ cyl + am, data = mtcars))
# tidy(lm_robust(mpg ~ hp + factor(cyl) + factor(am), data = mtcars))[2,]
#
# tidy(lm_robust(mpg ~ hp, fixed_effects = ~ cyl + cyl2 + am, data = mtcars))
# tidy(lm_robust(mpg ~ hp + factor(cyl) + factor(cyl2) + factor(am), data = mtcars))[2,]
# tidy(lm_robust(mpg ~ hp + factor(cyl) + factor(am), data = mtcars))[2,]
#
# # LFE does the right thing if the dependency is in the first two
# lfe:::summary.felm(lfe::felm(mpg ~ hp | cyl + cyl2 + am, data = mtcars))$coefficients
# tidy(lm_robust(mpg ~ hp + factor(cyl) + factor(cyl3) + factor(am), data = mtcars, se_type = "classical"))[2,]

## Collinear factors
for (se_type in cr_se_types) {
ro <- tidy(lm_robust(Y ~ Z + X + factor(B) + factor(Bdup) + factor(B2), clusters = cl, data = dat, se_type = se_type))
Expand Down Expand Up @@ -454,76 +434,6 @@ test_that("test matches stata absorb", {

})


test_that("FEs give correct projected F-stats", {

skip_if_not_installed("lfe")
skip_on_cran()

feo <- lfe::felm(Y ~ Z + X | B + B2, data = dat)
sfeo <- lfe:::summary.felm(feo)
sfeor <- lfe:::summary.felm(feo, robust = TRUE)

cfeo <- lfe::felm(Y ~ Z + X | B + B2 | 0 | cl, data = dat)
sfeoc <- lfe:::summary.felm(cfeo, robust = TRUE)

# classical
rfo <- lm_robust(Y ~ Z + X, fixed_effects = ~ B + B2, data = dat, se_type = "classical")

expect_equivalent(
tidy(rfo)[rfo$term %in% c("Z", "X"), c("estimate", "std.error", "statistic", "p.value")],
as.data.frame(sfeo$coefficients[, 1:4])
)

expect_equivalent(
rfo[c("r.squared", "adj.r.squared", "proj_r.squared", "proj_adj.r.squared")],
sfeo[c("r.squared", "adj.r.squared", "P.r.squared", "P.adj.r.squared")]
)

expect_equivalent(
rfo[["proj_fstatistic"]],
sfeo[["P.fstat"]][c("F", "df1", "df2")]
)

## HC1
rfo <- lm_robust(Y ~ Z + X, fixed_effects = ~ B + B2, data = dat, se_type = "HC1")

expect_equivalent(
tidy(rfo)[rfo$term %in% c("Z", "X"), c("estimate", "std.error", "statistic", "p.value")],
as.data.frame(sfeor$coefficients[, 1:4])
)

expect_equivalent(
rfo[c("r.squared", "adj.r.squared", "proj_r.squared", "proj_adj.r.squared")],
sfeor[c("r.squared", "adj.r.squared", "P.r.squared", "P.adj.r.squared")]
)

expect_equivalent(
rfo[["proj_fstatistic"]],
sfeor[["P.fstat"]][c("F", "df1", "df2")]
)

## CR stata
rfo <- lm_robust(Y ~ Z + X, fixed_effects = ~ B + B2, clusters = cl, data = dat, se_type = "stata")

# Different pval because lfe doesn't use J-1 as it's DoF
expect_equivalent(
tidy(rfo)[rfo$term %in% c("Z", "X"), c("estimate", "std.error")],
as.data.frame(sfeoc$coefficients[, c(1, 2)])
)

expect_equivalent(
rfo[c("r.squared", "adj.r.squared", "proj_r.squared", "proj_adj.r.squared")],
sfeoc[c("r.squared", "adj.r.squared", "P.r.squared", "P.adj.r.squared")]
)

expect_equivalent(
rfo[["proj_fstatistic"]],
sfeoc[["P.fstat"]][c("F", "df1", "df2")]
)

})

test_that("FE matches lm_robust with one block", {

skip_if_not_installed("sandwich")
Expand Down

0 comments on commit 23154bc

Please sign in to comment.