% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/rdrandinf.R
\name{rdrandinf}
\alias{rdrandinf}
\title{Randomization Inference for RD Designs under Local Randomization}
\usage{
rdrandinf(
  Y,
  R,
  cutoff = 0,
  wl = NULL,
  wr = NULL,
  statistic = "diffmeans",
  p = 0,
  evall = NULL,
  evalr = NULL,
  kernel = "uniform",
  fuzzy = NULL,
  nulltau = 0,
  d = NULL,
  dscale = NULL,
  ci,
  interfci = NULL,
  bernoulli = NULL,
  reps = 1000,
  seed = 666,
  quietly = FALSE,
  covariates,
  obsmin = NULL,
  wmin = NULL,
  wobs = NULL,
  wstep = NULL,
  wasymmetric = FALSE,
  wmasspoints = FALSE,
  nwindows = 10,
  dropmissing = FALSE,
  rdwstat = "diffmeans",
  approx = FALSE,
  rdwreps = 1000,
  level = 0.15,
  plot = FALSE,
  firststage = FALSE,
  obsstep = NULL
)
}
\arguments{
\item{Y}{a vector containing the values of the outcome variable.}

\item{R}{a vector containing the values of the running variable.}

\item{cutoff}{the RD cutoff (default is 0).}

\item{wl}{the left limit of the window. The default takes the minimum of the running variable.}

\item{wr}{the right limit of the window. The default takes the maximum of the running variable.}

\item{statistic}{the randomization test statistic to be used. Allowed options are \code{diffmeans} (difference in means statistic), \code{ksmirnov} (Kolmogorov-Smirnov statistic), \code{ranksum} (Wilcoxon-Mann-Whitney standardized statistic), and \code{all}. Default option is \code{diffmeans}. The statistic \code{ttest} is equivalent to \code{diffmeans} and included for backward compatibility.}

\item{p}{the order of the polynomial for the outcome adjustment model (default is 0).}

\item{evall}{the point to the left of the cutoff at which the adjusted outcome is evaluated. Default is the cutoff value.}

\item{evalr}{the point to the right of the cutoff at which the adjusted outcome is evaluated. Default is the cutoff value.}

\item{kernel}{specifies the type of kernel to use as a weighting scheme. Allowed kernel types are \code{uniform} (uniform kernel), \code{triangular} (triangular kernel), and \code{epan} (Epanechnikov kernel). Default is \code{uniform}.}

\item{fuzzy}{indicates that the RD design is fuzzy. \code{fuzzy} can be specified as a vector containing the values of the endogenous treatment variable, or as a list where the first element is the vector of endogenous treatment values and the second element is a string containing the statistic to be used. Allowed statistics are \code{ar} or \code{itt} (Anderson-Rubin/intention-to-treat statistic) and \code{tsls} (2SLS statistic). Default statistic is \code{ar}. The \code{tsls} statistic relies on a large-sample approximation.}

\item{nulltau}{the value of the treatment effect under the null hypothesis (default is 0).}

\item{d}{the effect size for asymptotic power calculation. Default is 0.5 times the standard deviation of the outcome variable for the control group.}

\item{dscale}{the fraction of the standard deviation of the outcome variable for the control group used as the alternative hypothesis for asymptotic power calculation. Default is 0.5.}

\item{ci}{calculates a confidence interval for the treatment effect by test inversion. \code{ci} can be specified as a scalar or a vector, where the first element indicates the value of alpha for the confidence interval (typically 0.05 or 0.01) and the remaining elements, if specified, indicate the grid of treatment effects to be evaluated. This option uses \code{rdsensitivity} to calculate the confidence interval. See the corresponding help file for details. Note: the default tlist can be narrow in some cases, which may truncate the confidence interval. We recommend manually setting a large enough tlist.}

\item{interfci}{the level for Rosenbaum's confidence interval under arbitrary interference between units.}

\item{bernoulli}{the probabilities of treatment for each unit when assignment mechanism is a Bernoulli trial. This option should be specified as a vector of length equal to the length of the outcome and running variables.}

\item{reps}{the number of replications (default is 1000).}

\item{seed}{the seed to be used for the randomization test.}

\item{quietly}{suppresses the output table.}

\item{covariates}{the covariates used by \code{rdwinselect} to choose the window when \code{wl} and \code{wr} are not specified. This should be a matrix of size n x k where n is the total sample size and k is the number of covariates.}

\item{obsmin}{the minimum number of observations above and below the cutoff in the smallest window used by the companion command \code{rdwinselect}. Default is 10.}

\item{wmin}{the smallest window to be used (if \code{obsmin} is not specified) by the companion command \code{rdwinselect}. Specifying both \code{wmin} and \code{obsmin} returns an error.}

\item{wobs}{the number of observations to be added on each side of the cutoff at each step.}

\item{wstep}{the increment in window length (if \code{obsstep} is not specified) by the companion command \code{rdwinselect}. Specifying both \code{obsstep} and \code{wstep} returns an error.}

\item{wasymmetric}{allows for asymmetric windows around the cutoff when \code{wobs} is specified.}

\item{wmasspoints}{specifies that the running variable is discrete and each masspoint should be used as a window.}

\item{nwindows}{the number of windows to be used by the companion command \code{rdwinselect}. Default is 10.}

\item{dropmissing}{drop rows with missing values in covariates when calculating windows.}

\item{rdwstat}{the statistic to be used by the companion command \code{rdwinselect} (see the corresponding help file for options). Default option is \code{diffmeans}.}

\item{approx}{forces the companion command \code{rdwinselect} to conduct the covariate balance tests using a large-sample approximation instead of finite-sample exact randomization inference methods.}

\item{rdwreps}{the number of replications to be used by the companion command \code{rdwinselect}. Default is 1000.}

\item{level}{the minimum accepted value of the p-value from the covariate balance tests to be used by the companion command \code{rdwinselect}. Default is .15.}

\item{plot}{draws a scatter plot of the minimum p-value from the covariate balance test against window length implemented by the companion command \code{rdwinselect}.}

\item{firststage}{reports the results from the first step when using tsls.}

\item{obsstep}{the minimum number of observations to be added on each side of the cutoff for the sequence of fixed-increment nested windows. Default is 2. This option is deprecated and only included for backward compatibility.}
}
\value{
A list containing:
\item{sumstats}{matrix of full-sample and window-specific summary statistics.}
\item{obs.stat}{observed statistic or statistics.}
\item{p.value}{randomization p-value or p-values.}
\item{asy.pvalue}{asymptotic p-value or p-values.}
\item{window}{chosen window endpoints.}
\item{ci}{confidence interval; included only when \code{ci} is specified.}
\item{interf.ci}{confidence interval under interference; included only when
\code{interfci} is specified.}
}
\description{
\code{rdrandinf} implements randomization inference and related methods for RD designs,
using observations in a specified or data-driven selected window around the cutoff where
local randomization is assumed to hold.
}
\examples{
# Toy dataset
set.seed(123)
X <- array(rnorm(200),dim=c(100,2))
R <- X[,1] + X[,2] + rnorm(100)
Y <- 1 + R -.5*R^2 + .3*R^3 + (R>=0) + rnorm(100)
# Randomization inference in window (-.75,.75)
tmp <- rdrandinf(Y,R,wl=-.75,wr=.75,quietly=TRUE)
# Randomization inference in window (-.75,.75), all statistics
tmp <- rdrandinf(Y,R,wl=-.75,wr=.75,statistic='all',quietly=TRUE)
# Randomization inference with window selection
# Note: low number of replications to speed up process.
# The user should increase the number of replications.
tmp <- rdrandinf(Y,R,statistic='all',covariates=X,wmin=.5,wstep=.125,
                 rdwreps=500,level=0,quietly=TRUE)



}
\references{
Cattaneo, M.D., B. Frandsen and R. Titiunik. (2015). \href{https://rdpackages.github.io/references/Cattaneo-Frandsen-Titiunik_2015_JCI.pdf}{Randomization Inference in the Regression Discontinuity Design: An Application to Party Advantages in the U.S. Senate}. \emph{Journal of Causal Inference} 3(1): 1-24.

Cattaneo, M.D., R. Titiunik and G. Vazquez-Bare. (2016). \href{https://rdpackages.github.io/references/Cattaneo-Titiunik-VazquezBare_2016_Stata.pdf}{Inference in Regression Discontinuity Designs under Local Randomization}. \emph{Stata Journal} 16(2): 331-367.

Cattaneo, M.D., R. Titiunik and G. Vazquez-Bare. (2017). \href{https://rdpackages.github.io/references/Cattaneo-Titiunik-VazquezBare_2017_JPAM.pdf}{Comparing Inference Approaches for RD Designs: A Reexamination of the Effect of Head Start on Child Mortality}. \emph{Journal of Policy Analysis and Management} 36(3): 643-681.
}
\author{
Matias D. Cattaneo, Princeton University. \email{matias.d.cattaneo@gmail.com}

Rocio Titiunik, Princeton University. \email{rocio.titiunik@gmail.com}

Gonzalo Vazquez-Bare, UC Santa Barbara. \email{gvazquezbare@gmail.com}
}
