Description Usage Arguments Details Value Author(s) References See Also Examples
View source: R/rdplotdensity.R
rdplotdensity
constructs density plots. It is based on the
local polynomial density estimator proposed in Cattaneo, Jansson and Ma (2020, 2021a).
A companion Stata
package is described in Cattaneo, Jansson and Ma (2018).
Companion command: rddensity
for manipulation (density discontinuity) testing.
Related Stata and R packages useful for inference in regression discontinuity (RD) designs are described in the website: https://rdpackages.github.io/.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31  rdplotdensity(
rdd,
X,
plotRange = NULL,
plotN = 10,
plotGrid = c("es", "qs"),
alpha = 0.05,
type = NULL,
lty = NULL,
lwd = NULL,
lcol = NULL,
pty = NULL,
pwd = NULL,
pcol = NULL,
CItype = NULL,
CIuniform = FALSE,
CIsimul = 2000,
CIshade = NULL,
CIcol = NULL,
bwselect = NULL,
hist = TRUE,
histBreaks = NULL,
histFillCol = 3,
histFillShade = 0.2,
histLineCol = "white",
title = "",
xlabel = "",
ylabel = "",
legendTitle = NULL,
legendGroups = NULL
)

rdd 
Object returned by 
X 
Numeric vector or one dimensional matrix/data frame, the running variable. 
plotRange 
Numeric, specifies the lower and upper bound of the plotting region. Default is

plotN 
Numeric, specifies the number of grid points used for plotting on the two sides of the cutoff.
Default is 
plotGrid 
String, specifies how the grid points are positioned. Options are 
alpha 
Numeric scalar between 0 and 1, the significance level for plotting confidence regions. If more than one is provided, they will be applied to the two sides accordingly. 
type 
String, one of 
lty 
Line type for point estimates, only effective if 
lwd 
Line width for point estimates, only effective if 
lcol 
Line color for point estimates, only effective if 
pty 
Scatter plot type for point estimates, only effective if 
pwd 
Scatter plot size for point estimates, only effective if 
pcol 
Scatter plot color for point estimates, only effective if 
CItype 
String, one of 
CIuniform 

CIsimul 
Positive integer, the number of simulations used to construct critical values (default is 2000). This
option is ignored if 
CIshade 
Numeric, opaqueness of the confidence region, should be between 0 (transparent) and 1. Default is 0.2. If more than one is provided, they will be applied to the two sides accordingly. 
CIcol 
Color of the confidence region. 
bwselect 
String, the method for datadriven bandwidth selection. Available options
are (1) 
hist 

histBreaks 
Numeric vector, giving the breakpoints between histogram cells. 
histFillCol 
Color of the histogram cells. 
histFillShade 
Opaqueness of the histogram cells, should be between 0 (transparent) and 1. Default is 0.2. 
histLineCol 
Color of the histogram lines. 
title, xlabel, ylabel 
Strings, title of the plot and labels for x and yaxis. 
legendTitle 
String, title of legend. 
legendGroups 
String Vector, group names used in legend. 
Bias correction is only used for the construction of confidence intervals/bands, but not for point
estimation. The point estimates, denoted by f_p
, are constructed using local polynomial estimates of order
p
, while the centering of the confidence intervals/bands, denoted by f_q
, are constructed using local
polynomial estimates of order q
. The confidence intervals/bands take the form:
[f_q  cv * SE(f_q) , f_q + cv * SE(f_q)]
, where cv
denotes the appropriate critical value and
SE(f_q)
denotes a standard error estimate
for the centering of the confidence interval/band. As a result, the confidence intervals/bands may not be
centered at the point estimates because they have been biascorrected. Setting q
and p
to be equal
results on centered at the point estimate confidence intervals/bands, but requires undersmoothing for valid
inference (i.e., (I)MSEoptimal bandwdith for the density point estimator cannot be used). Hence the bandwidth
would need to be specified manually when q=p
, and the point estimates will not be (I)MSE optimal. See
Cattaneo, Jansson and Ma (2021a,b) for details, and also Calonico, Cattaneo, and Farrell (2018, 2020) for
robust bias correction methods.
Sometimes the density point estimates may lie outside of the confidence intervals/bands, which can happen if
the underlying distribution exhibits high curvature at some evaluation point(s). One possible solution in this
case is to increase the polynomial order p
or to employ a smaller bandwidth.
Estl, Estr 
Matrices containing estimation results:
(1) 
Estplot 
A stadnard 
Matias D. Cattaneo, Princeton University cattaneo@princeton.edu.
Michael Jansson, University of California Berkeley. mjansson@econ.berkeley.edu.
Xinwei Ma (maintainer), University of California San Diego. x1ma@ucsd.edu.
Calonico, S., M. D. Cattaneo, and M. H. Farrell. 2018. On the Effect of Bias Estimation on Coverage Accuracy in Nonparametric Inference. Journal of the American Statistical Association 113(522): 767779.
Calonico, S., M. D. Cattaneo, and M. H. Farrell. 2020. Coverage Error Optimal Confidence Intervals for Local Polynomial Regression. Working paper.
Cattaneo, M. D., M. Jansson, and X. Ma. 2018. Manipulation Testing based on Density Discontinuity. Stata Journal 18(1): 234261.
Cattaneo, M. D., M. Jansson, and X. Ma. 2020. Simple Local Polynomial Density Estimators. Journal of the American Statistical Association, 115(531): 14491455.
Cattaneo, M. D., M. Jansson, and X. Ma. 2021a. Local Regression Distribution Estimators. Journal of Econometrics, forthcoming.
Cattaneo, M. D., M. Jansson, and X. Ma. 2021b. lpdensity: Local Polynomial Density Estimation and Inference. Journal of Statistical Software, forthcoming.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  # Generate a random sample with a density discontinuity at 0
set.seed(42)
x < rnorm(2000, mean = 0.5)
x[x > 0] < x[x > 0] * 2
# Estimation
rdd < rddensity(X = x)
summary(rdd)
# Density plot (from 2 to 2 with 25 evaluation points at each side)
plot1 < rdplotdensity(rdd, x, plotRange = c(2, 2), plotN = 25)
# Plotting a uniform confidence band
set.seed(42) # fix the seed for simulating critical values
plot3 < rdplotdensity(rdd, x, plotRange = c(2, 2), plotN = 25, CIuniform = TRUE)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.