Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lukesonnet committed Mar 28, 2018
2 parents 29f3e0c + 7366241 commit 12f9a29
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Expand Up @@ -9,7 +9,7 @@ Authors@R: c(person("Graeme", "Blair", email = "graeme.blair@ucla.edu", role = c
person("Macartan", "Humphreys", email = "macartan@gmail.com", role = c("aut")),
person("Luke", "Sonnet", email = "luke.sonnet@gmail.com", role = c("aut")),
person("Neal", "Fultz", email = "nfultz@gmail.com", role = c("ctb")))
Description: Fast procedures for small set of commonly-used, design-appropriate estimators with robust standard errors and confidence intervals. Includes estimators for linear regression, regression improving precision of experimental estimates by interacting treatment with centered pre-treatment covariates introduced by Lin (2013) <doi:10.1214/12-AOAS583>, difference-in-means, and Horvitz-Thompson estimation.
Description: Fast procedures for small set of commonly-used, design-appropriate estimators with robust standard errors and confidence intervals. Includes estimators for linear regression, instrumental variables regresion, difference-in-means, Horvitz-Thompson estimation, and regression improving precision of experimental estimates by interacting treatment with centered pre-treatment covariates introduced by Lin (2013) <doi:10.1214/12-AOAS583>.
URL: http://estimatr.declaredesign.org, https://github.com/DeclareDesign/estimatr
BugReports: https://github.com/DeclareDesign/estimatr/issues
License: MIT + file LICENSE
Expand Down
28 changes: 21 additions & 7 deletions R/helper_lm_robust_fit.R
Expand Up @@ -320,13 +320,29 @@ lm_robust_fit <- function(y,
}
if (iv_second_stage && se_type != "none") {
indices <- seq.int(has_int + 1, rank, by = 1)
fstat <- setNames(
crossprod(
fit$beta_hat[indices],
solve(vcov_fit$Vcov_hat[indices, indices], fit$beta_hat[indices])
) / (rank - has_int),
setNames(
fstat <-
tryCatch({
crossprod(
fit$beta_hat[indices],
solve(vcov_fit$Vcov_hat[indices, indices], fit$beta_hat[indices])
) / (rank - has_int)
}, error = function(e) {
if (grepl("system is computationally singular", e)) {
warning(
"Unable to compute f-statistic due to rank deficient variance-",
"covariance matrix"
)
} else {
warning(
"Unable to compute f-statistic"
)
}
NA
}),
fstat_names
)

} else {
fstat <- setNames(
return_list[["r.squared"]] * return_list[["df.residual"]] /
Expand All @@ -348,8 +364,6 @@ lm_robust_fit <- function(y,
rep(paste0(return_list[["outcome"]], ":"), each = rank),
rep(return_list$term, times = ny)
)
# print(return_list[["vcov"]])
# print(coef_names)
dimnames(return_list[["vcov"]]) <- list(
coef_names,
coef_names
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-iv-robust.R
Expand Up @@ -209,6 +209,20 @@ test_that("iv_robust matches AER + ivpack", {
na.omit(as.matrix(tidy(ivdef2clrw)[, c("estimate", "std.error", "p.value")])),
na.omit(as.matrix(ivdef2clsew)[, c(1, 2, 4)])
)

# F-stat fails properly with blocks of size 1
set.seed(42)
N <- 20
dat <- data.frame(y = rnorm(N), x = rnorm(N), z = rnorm(N), bl = sample(letters, size = N, replace = T))
expect_warning(
ivr <- iv_robust(y ~ bl + x | bl + z, data = dat, se_type = "stata"),
"Unable to compute f\\-statistic"
)
expect_equivalent(
ivr$fstatistic[1],
NA_integer_
)

})


Expand Down

0 comments on commit 12f9a29

Please sign in to comment.