dc_test
implements the McCrary (2008) sorting test to identify violations of assignment rules.
It is based on the DCdensity
function in the "rdd" package.
dc_test(
runvar,
cutpoint,
bin = NULL,
bw = NULL,
verbose = TRUE,
plot = TRUE,
ext.out = FALSE,
htest = FALSE,
level = 0.95,
digits = max(3, getOption("digits") - 3),
timeout = 30
)
If ext.out
is FALSE
, dc_test
returns a numeric value specifying the p-value of the McCrary (2008) sorting test.
Additional output is enabled when ext.out
is TRUE
.
In this case, dc_test
returns a list with the following elements:
The estimated log difference in heights of the density curve at the cutpoint.
The standard error of theta
.
The z statistic of the test.
The p-value of the test. A p-value below the significance threshold indicates that the user can reject the null hypothesis of no sorting.
The calculated size of bins for the test.
The calculated bandwidth for the test.
The cutpoint used.
A dataframe for the binning of the histogram. Columns are cellmp
(the midpoints of each cell) and cellval
(the normalized height of each cell).
A numeric vector containing the running variable.
A numeric value containing the cutpoint at which assignment to the treatment is determined. The default is 0.
A numeric value containing the binwidth. The default is 2*sd(runvar)*length(runvar)^(-.5)
.
A numeric value containing bandwidth to use. If no bandwidth is supplied, the default uses bandwidth selection calculation from McCrary (2008).
A logical value indicating whether to print diagnostic information to
the terminal. The default is TRUE
.
A logical value indicating whether to plot the histogram and density estimations
The default is TRUE
. The user may wrap this function in additional graphical options
to modify the plot.
A logical value indicating whether to return extended output.
The default is FALSE
. When FALSE
dc_test
will return only the p-value of the test, but will print more information.
When TRUE
, dc_test
will return and print the additional information documented below.
A logical value indicating whether to return an "htest"
object
compatible with base R's hypothesis test output. The default is FALSE
.
A numerical value between 0 and 1 specifying the confidence level for confidence intervals. The default is 0.95.
A non-negative integer specifying the number of digits to display in all output.
The default is max(3, getOption("digits") - 3)
.
A non-negative numerical value specifying the maximum number of seconds that
expressions in the function are allowed to run. The default is 30. Specify Inf
to run all expressions
to completion.
McCrary, J. (2008). Manipulation of the running variable in the regression discontinuity design: A density test. Journal of Econometrics, 142(2), 698-714. tools:::Rd_expr_doi("10.1016/j.jeconom.2007.05.005").
Drew Dimmery (2016). rdd: Regression Discontinuity Estimation. R package version 0.57. https://CRAN.R-project.org/package=rdd
set.seed(12345)
# No discontinuity
x <- runif(1000, -1, 1)
dc_test(x, 0)
# Discontinuity
x <- runif(1000, -1, 1)
x <- x + 2 * (runif(1000, -1, 1) > 0 & x < 0)
dc_test(x, 0)
Run the code above in your browser using DataLab