knitr::opts_chunk$set(collapse = T, comment = "#>")
RDDtools works in an object-oriented way: the user has to define once the characteristic of the data, creating a rdd_data object, on which different anaylsis tools can be applied.
Load the package, and load the built-in dataset from [Lee 2008]:
library(rddtools) data(house)
Declare the data to be a rdd_data object:
house_rdd <- rdd_data(y=house$y, x=house$x, cutpoint=0)
You can now directly summarise and visualise this data:
summary(house_rdd) plot(house_rdd)
Estimate parametrically, by fitting a 4th order polynomial.
reg_para <- rdd_reg_lm(rdd_object=house_rdd, order=4) reg_para plot(reg_para)
Run a simple local regression, using the [Imbens and Kalyanaraman 2012] bandwidth.
bw_ik <- rdd_bw_ik(house_rdd) reg_nonpara <- rdd_reg_np(rdd_object=house_rdd, bw=bw_ik) print(reg_nonpara)
One can easily check the sensitivity of the estimate to different bandwidths:
plotSensi(reg_nonpara, from=0.05, to=1, by=0.1)
Or run the Placebo test, estimating the RDD effect based on fake cutpoints:
plotPlacebo(reg_nonpara)
Design sensitivity tests check whether the discontinuity found can actually be attributed ot other causes. Two types of tests are available:
use simply the function dens_test(), on either the raw data, or the regression output:
dens_test(reg_nonpara)
Two tests available: + equal means of covariates: covarTest_mean() + equal density of covariates: covarTest_dens()
We need here to simulate some data, given that the Lee (2008) dataset contains no covariates. We here simulate three variables, with the second having a different mean on the left and the right.
set.seed(123) n_Lee <- nrow(house) Z <- data.frame(z1 = rnorm(n_Lee, sd=2), z2 = rnorm(n_Lee, mean = ifelse(house<0, 5, 8)), z3 = sample(letters, size = n_Lee, replace = TRUE)) house_rdd_Z <- rdd_data(y = house$y, x = house$x, covar = Z, cutpoint = 0)
Tests correctly reject equality of the second, and correctly do not reject equality for the first and third.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.