Skip to content

Commit

Permalink
Add covr
Browse files Browse the repository at this point in the history
  • Loading branch information
kolesarm committed Apr 13, 2019
1 parent 11d7957 commit 86703cf
Show file tree
Hide file tree
Showing 9 changed files with 499 additions and 3 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
readme.md
notes.org
.lintr
^codecov\.yml$
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ addons:
apt:
packages:
- ghostscript
r_packages:
- covr
after_success:
- Rscript -e 'covr::codecov()'
12 changes: 12 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
comment: false

coverage:
status:
project:
default:
target: auto
threshold: 1%
patch:
default:
target: auto
threshold: 1%
87 changes: 87 additions & 0 deletions doc/RDHonest.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
## ---- include=FALSE, cache=FALSE-----------------------------------------
library("knitr")
knitr::opts_knit$set(self.contained = FALSE)
knitr::opts_chunk$set(tidy = TRUE, collapse=TRUE, comment = "#>",
tidy.opts=list(blank=FALSE, width.cutoff=55))

## ------------------------------------------------------------------------
library("RDHonest")
## Assumes first column in the data frame corresponds to outcome,
## and second to running variable
dl <- RDData(lee08, cutoff = 0)

## Transform earnings to log earnings
do <- RDData(data.frame(logearn=log(cghs$earnings),
year14=cghs$yearat14), cutoff = 1947)

## ---- fig.width=4.5, fig.height=3.5, fig.cap="Lee (2008) data"-----------
## plot 25-bin averages in for observations 50 at most points away from the cutoff.
## See Figure 1
plot_RDscatter(dl, avg=25, window = 50, xlab="Margin of victory",
ylab="Vote share in next election")

## ---- fig.width=4.5, fig.height=3.5, fig.cap="Oreopoulos (2006) data"----
## see Figure 2
f2 <- plot_RDscatter(do, avg=Inf, xlab="Year aged 14", ylab="Log earnings",
propdotsize=TRUE)
## Adjust size of dots if they are too big
f2 + ggplot2::scale_size_area(max_size = 4)

## ------------------------------------------------------------------------
## Usual critical value
CVb(0, alpha=0.05) # returns a list
CVb(1/2, alpha=0.05)$cv # extract critical value

## Tabulate critical values for different significance levels
## when bias-sd ratio equals 1/4
knitr::kable(CVb(1/4, alpha=c(0.01, 0.05, 0.1)), caption="Critical values")

## ------------------------------------------------------------------------
RDHonest(voteshare ~ margin, data=lee08, kern="uniform", M=0.1, hp=10, sclass="T")
RDHonest(voteshare ~ margin, data=lee08, kern="uniform", M=0.1, hp=10, sclass="H")

## ------------------------------------------------------------------------
RDHonest(voteshare ~ margin, data=lee08, kern="triangular",
M=0.1, opt.criterion="MSE", sclass="H")
## Choose bws optimal for length of CI, allowing for different bws
## on either side of cutoff
RDHonest(voteshare ~ margin, data=lee08, kern="triangular", M=0.1,
opt.criterion="FLCI", sclass="H", bw.equal=FALSE)

## ------------------------------------------------------------------------
RDOptBW(voteshare ~ margin, data=lee08, kern="triangular",
M=0.1, opt.criterion="MSE", sclass="H")

## ------------------------------------------------------------------------
## Replicate Table 2, column (10)
RDHonest(log(earnings) ~ yearat14, cutoff=1947,
data=cghs, kern="uniform", M=0.04, opt.criterion="FLCI", sclass="H")
## Triangular kernel generally gives tigher CIs
RDHonest(log(earnings) ~ yearat14, cutoff=1947,
data=cghs, kern="triangular", M=0.04, opt.criterion="FLCI", sclass="H")

## ------------------------------------------------------------------------
## Replicate Table 2, column (6), run local linear regression (order=1)
## with a uniform kernel (other kernels are not yet implemented)
RDHonestBME(log(earnings) ~ yearat14, cutoff=1947,
data=cghs, hp=3, order=1)

## ------------------------------------------------------------------------
2*RDHonest(voteshare ~ margin, data=lee08, kern="optimal", M=0.1, opt.criterion="FLCI", se.initial="Silverman", se.method="nn")$hl

2*RDHonest(voteshare ~ margin, data=lee08, kern="triangular", M=0.1, opt.criterion="FLCI", se.initial="Silverman", se.method="nn", sclass="T")$hl


## ------------------------------------------------------------------------
## Add variance estimate to the lee data so that the RDSmoothnessBound
## function doesn't have to compute them each time
dl <- RDHonest::RDPrelimVar(dl, se.initial="NN")

### Only use three point-average for averages of a 100 points closest to cutoff,
### and report results separately for points above and below cutoff
RDSmoothnessBound(dl, s=100, separate=TRUE, multiple=FALSE, sclass="T")

### Pool estimates based on observations below and above cutoff, and
### use three-point averages over the entire support of the running variable
RDSmoothnessBound(dl, s=100, separate=FALSE, multiple=TRUE, sclass="H")

File renamed without changes.
Binary file added doc/RDHonest.pdf
Binary file not shown.
Binary file modified doc/lpkernels.pdf
Binary file not shown.
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ using procedures from [Armstrong and Kolesár
(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, and `manual.pdf` (also stored under `doc/`) for documentation of the
package functions.
See vignette [RDHonest](doc/RDHonest.pdf) for description of the package
(available through `vignette("RDHonest")` once package is installed), and the
package [manual](doc/manual.pdf) 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
Loading

0 comments on commit 86703cf

Please sign in to comment.