Skip to content

Commit

Permalink
Update data input checks
Browse files Browse the repository at this point in the history
  • Loading branch information
kolesarm committed May 7, 2024
1 parent bd6e1ea commit 5f0555b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
11 changes: 6 additions & 5 deletions R/checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,24 @@ kernel_type <- function(kern) {
process_options <- function(M, se.method, method, d, kern) {
if (kernel_type(kern)=="optimal" && method!="SRD")
stop("Optimal kernel requires sharp RD design.")
m_len <- if (method=="FRD") 2 else 1
if (!missing(M)) {
m_len <- if (method=="FRD") 2 else 1
if (!check_positive(M, m_len))
stop(paste0("M must be a non-negative numeric vector of length",
m_len, "."))
}

if (min(sum(d$p), sum(d$m))==0) {
if (method=="IP") {
if (!is.null(d$covs))
stop("Covariates not allowed whem method is 'IP'.")
} else if (min(sum(d$p), sum(d$m))==0) {
stop("No observations on one side of the cutoff")
}

if (!(se.method %in% c("nn", "EHW", "supplied.var"))) {
stop("Unsupported se.method")
}
if (se.method=="nn" && !is.null(d$clusterid))
stop(paste0("'se.method=\"nn\"' not allowed with clustered standard",
" errors.\nUse 'se.method=\"EHW\"'"))

if (!is.null(d$covs) && method=="IP")
stop("Covariates not allowed whem method is 'IP'.")
}
Binary file modified doc/manual.pdf
Binary file not shown.
6 changes: 2 additions & 4 deletions tests/testthat/test_interface.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ test_that("Test inputs", {
expect_error(r2 <- RDHonest(log(cn)~elig_year, data=rcp, kern="Unif"))
expect_error(RDHonest(log(cn)|retired~elig_year, data=rcp, M=1, T0=0,
kern="optimal"))
expect_message(pp <- RDHonest(voteshare~margin, data=lee08,
M=2, h=5, subset=I(margin>0))$coefficients)
expect_equal(as.numeric(pp[c(2, 3, 11)]),
c(0L, sqrt(.Machine$double.xmax/10), NA))
expect_error(pp <- RDHonest(voteshare~margin, data=lee08,
M=2, h=5, subset=I(margin>0))$coefficients)
expect_error(RDHonest(c~elig_year, data=rcp, clusterid=seq_along(rr$c),
point.inference=TRUE))
## Insufficient unique values of the running variable to compute rule of
Expand Down

0 comments on commit 5f0555b

Please sign in to comment.