Skip to content

Commit

Permalink
Test plot, update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kolesarm committed Apr 13, 2019
1 parent ed2c4f3 commit 11d7957
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 40 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ RoxygenNote: 6.1.1
URL: https://github.com/kolesarm/RDHonest
VignetteBuilder: knitr
Language: en-US
BugReports: https://github.com/kolesarm/RDHonest/issues
27 changes: 13 additions & 14 deletions R/bnm.R
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
#' Critical values for CIs based on a biased Gaussian estimator.
#'
#' Computes the critical value \eqn{cv_{1-\alpha}(B)} such that the confidence
#' interval \eqn{X\pm cv_{1-\alpha}(B)} will have coverage \eqn{1-\alpha}, where
#' \eqn{X} is Normally distributed with variance equal to \eqn{1} and maximum
#' bias at most \eqn{B}.
#' Computes the critical value \eqn{cv_{1-\alpha}(B)}{cv_{1-alpha}(B)} such that
#' the confidence interval \eqn{X\pm cv_{1-\alpha}(B)}{X +/- cv_{1-alpha}(B)}
#' will have coverage \eqn{1-\alpha}{1-alpha}, where \eqn{X} is normally
#' distributed with variance equal to \eqn{1} and maximum bias at most \eqn{B}.
#'
#' @param B Maximum bias, vector of non-negative numbers.
#' @param alpha Determines CI level, \code{1-alpha}. Needs to be between 0 and
#' 1. Can be a vector of values.
#' @param alpha Determines CI level, \eqn{1-\alpha}{1-alpha}. Vector of values
#' between 0 and 1.
#' @return Data frame with the following columns:
#'
#' \describe{
#'
#' \item{bias}{Value of bias as specified by \code{B}}
#'
#' \item{alpha}{Value of \eqn{\alpha} as specified by \code{alpha}}
#' \item{alpha}{Value of \eqn{\alpha}{alpha} as specified by \code{alpha}}
#'
#' \item{cv}{Critical value}
#'
#' \item{TeXDescription}{LaTeX-friendly description of current row}}
#' \item{TeXDescription}{LaTeX-friendly description of the current row}}
#' @examples
#' ## 90% critical value:
#' CVb(B = 1, alpha = 0.1)
#' ## Returns data frame with 4 rows
#' CVb(B = c(0, 0.5, 1), alpha = c(0.05, 0.1))
#' @importFrom stats pnorm qnorm
#' @export
CVb <- function(B, alpha=0.05) {
## Single B
cv <- function(B, alpha = 0.05) {
if(is.na(B)) return(NA)
## Single B and alpha
cv <- function(B, alpha) {
if (is.na(B)) return(NA)
stopifnot(B >= 0 & alpha > 0 & alpha < 1)
if (B<10)
return(sqrt(stats::qchisq(1-alpha, df = 1, ncp = B^2)))
Expand All @@ -38,9 +37,9 @@ CVb <- function(B, alpha=0.05) {
}

d <- data.frame(expand.grid(bias=B, alpha=alpha), cv=NA)
d$cv <- vapply(seq_len(nrow(d)),
d$cv <- vapply(seq_along(d$bias),
function(j) cv(d$bias[j], d$alpha[j]), numeric(1))
d$TeXDescription <- paste("$\\alpha=", d$alpha, "$", sep="")
d$TeXDescription <- paste0("$\\alpha=", d$alpha, "$")

d
}
4 changes: 2 additions & 2 deletions R/documentation.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#'
#' Subset of Ludwig-Miller data. Counties with missing poverty rate, of with
#' both outcomes missing (\code{hs} and \code{mortality}) were removed. In the
#' original dataset, Yellowstone County, MT (\code{oldcode==27056}) was entered
#' original dataset, Yellowstone County, MT (\code{oldcode = 27056}) was entered
#' twice, here the duplicate is removed. Yellowstone National Park, MT
#' (\code{oldcode==27057}) is also removed due to it being an outlier for both
#' (\code{oldcode = 27057}) is also removed due to it being an outlier for both
#' outcomes. Counties with \code{oldcode} equal to (3014, 32032, 47010, 47040,
#' 47074, 47074, 47078, 47079, 47096) matched more than one FIPS entry, so the
#' county labels may not be correct. Mortality data is missing for Alaska.
Expand Down
9 changes: 5 additions & 4 deletions R/kernels.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#' Equivalent kernel for local linear regression.
#'
#' Calculates equivalent kernel for local polynomial regression.
#' @param kernel kernel type. Can be a function supported on \eqn{[-1, 1]}
#' (boundary kernel) or \eqn{[0,1]} (interior kernel), or else one of
#' \code{"uniform"} (\eqn{I(|u|<1)}), \code{"triangular"} (\eqn{(1-|u|)I(|u|<1)}),
#' or \code{"epanechnikov"} (k(u)=(3/4)(1-u^2)I(|u|<1)).
#' @param kernel kernel type. Can be a function supported on \eqn{[0, 1]}
#' (boundary kernel) or \eqn{[-1, 1]} (interior kernel), or else one of
#' \code{"triangular"} (\eqn{k(u)=(1-|u|)_{+}}), \code{"epanechnikov"}
#' (\eqn{k(u)=(3/4)(1-u^2)_{+}}), or \code{"uniform"} (\eqn{k(u)=
#' (|u|<1)/2}).
#' @param boundary Logical scalar, specifying whether we are at a boundary.
#' @param order Order of local polynomial: \code{0} means local constant,
#' \code{1} local linear, \code{2} local quadratic etc.
Expand Down
2 changes: 2 additions & 0 deletions R/plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#' \code{avg=Inf}). Otherwise the size of points is constant.
#' @examples
#' plot_RDscatter(RDData(lee08, cutoff=0), avg=20)
#' plot_RDscatter(RDData(data.frame(y=log(cghs$earnings), x=cghs$yearat14),
#' cutoff=1947), avg=Inf, propdotsize=TRUE)
#' @export
plot_RDscatter <- function(d, avg=10, xlab=NULL, ylab=NULL,
window=NULL, vert=TRUE, propdotsize=FALSE) {
Expand Down
16 changes: 8 additions & 8 deletions man/CVb.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions man/EqKern.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/headst.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/plot_RDscatter.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
# RDHonest

Honest and efficient confidence intervals in regression discontinuity designs
using procedures
from
[Armstrong and Kolesár (2018)](https://arxiv.org/abs/1606.01200),
[Armstrong and Kolesár (2018)](https://arxiv.org/abs/1511.06028),
and [Kolesár and Rothe (2018)](https://arxiv.org/abs/1606.04086)
using procedures from [Armstrong and Kolesár
(2018)](https://arxiv.org/abs/1606.01200), [Armstrong and Kolesár
(2018)](https://doi.org/10.3982/ECTA14434)
([preprint](https://arxiv.org/abs/1511.06028)), and [Kolesár and Rothe
(2018)](https://doi.org/10.1257/aer.20160945)
([preprint](https://arxiv.org/abs/1606.04086))

See vignette `RDHonest.pdf` (stored under `doc/`) for description of the
package.
package, and `manual.pdf` (also stored under `doc/`) for documentation of the
package functions.

This software package is based upon work supported by the National Science
Foundation under grant numbers SES-1628939 (Armstrong) and SES-1628878
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test_rd.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ test_that("IK bandwidth calculations", {
expect_equal(sqrt(mean(d$sigma2m)), 12.4627517531)
})

test_that("Plots", {
if (requireNamespace("ggplot2", quietly = TRUE)) {
expect_silent(invisible(plot_RDscatter(
RDData(data.frame(y=log(cghs$earnings),
x=cghs$yearat14),
cutoff=1947), avg=Inf, propdotsize=TRUE)))
}
})


test_that("Honest inference in Lee and LM data", {

## Replicate 1606.01200v2
Expand Down

0 comments on commit 11d7957

Please sign in to comment.