<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/ratest-a-randomization-tests-package-is-available-on-cran/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://ignaciomsarmiento.github.io/2018/11/11/RDperm.html"> Ignacio Sarmiento Barbieri</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>This blog post introduces the <a rel="nofollow" href="https://cran.r-project.org/web/packages/RATest/index.html" target="_blank">RATest</a> package we released a while back on <a rel="nofollow" href="https://cran.r-project.org/" target="_blank">CRAN</a> with my colleague and good friend <a rel="nofollow" href="https://github.com/mauolivares" target="_blank">Mauricio Olivares-Gonzalez</a>. The package contains a collection of randomization tests, data sets and examples. The current version focuses on two testing problems and their implementation in empirical work, mostly related to economics. First, it facilitates the empirical researcher to test for particular hypotheses, such as comparisons of means, medians, and variances from k populations using robust permutation tests, which asymptotic validity holds under very weak assumptions, while retaining the exact rejection probability in finite samples when the underlying distributions are identical. Second, it implements Canay and Kamat (2017) permutation test for testing the continuity assumption of the baseline covariates in the sharp regression discontinuity design (RDD).</p>
<p>In this post we’ll focus on the implementation of Canay and Kamat (2017) test presening a summarized version of the <a rel="nofollow" href="https://cran.r-project.org/web/packages/RATest/vignettes/RDperm.pdf" target="_blank">vignette</a> that is available on <a rel="nofollow" href="https://cran.r-project.org/" target="_blank">CRAN</a>. For those <code>stata</code> enthusiasts there is an implementation of this function in <code>stata</code> see <a rel="nofollow" href="https://bitbucket.org/iacanay/rdperm-stata" target="_blank">RDPerm</a></p>
<h1>Set up of the problem</h1>
<p>One of the assumptions in which a Sharp Regression Discontinuity Design rests is that baseline covariates are continuous at the cutoff. However, this hypothesis of continuity is intrinsically intestable. Practitioners have relied on graphical inspections, or on <em>conditional means</em> tests, neither of which is a test for the continuity of the baseline covariates at the cutoff.[1]</p>
<p>Canay and Kamat (2017) propose a permutation test approach to test this hypothesis, where the null hypothesis states the continuity of the distribution of the baseline covariates at the cutoff. Permutation tests have several advantages in the testing problem we are concerned. They can be applied without parametric assumptions of the underlying distribution generating the data. They also can control the limiting rejection probability under general assumptions.</p>
<p>We organize this post like the <a rel="nofollow" href="https://cran.r-project.org/web/packages/RATest/vignettes/RDperm.pdf" target="_blank">vignette</a> proceding in a similar but for succinct fashion.</p>
<h1>Testable Hypothesis</h1>
<h2>Potential Outcomes</h2>
<p>Consider the simplest model for a randomized experiment with subject <em>i</em>’s (continuous) response  to a binary treatment . The treatment assignment in the sharp RDD follows the rule , where  is the so called running variable, and  is the cutoff at which the discontinuity arises. This threshold is conveniently assumed to be equal to 0.</p>
<p>For every subject , there are two mutually exclusive potential outcomes – either subject gets the treateatment or not. If subject <em>i</em> receives the treatment (), we will say the potential outcome is . Similarly, if subject <em>i</em> belongs to the control group (), the potential outcome is . We are interested in the average treatment effect (ATE) at the cutoff, i.e.</p>
<p></p>
<p>The identification assumption is not testable nonetheless as we only get to observe at most one of the potential outcomes.[2] Lee (2008) established a more restrictive but testable sufficient condition for identification – units can control the running variable except around the cutoff.[3] The identifying assumption implies that the baseline covariates are continuously distributed at the cutoff</p>
<p></p>
<p>where  denotes the baseline covariates. We can cast condition (1) in terms of a two-sample hypothesis testing problem. Let</p>
<p></p>
<p>Condition (1) is equivalent to  being right continuous at  and</p>
<p></p>
<p>Therefore, testing the null hypothesis of continuity of the baseline covariates at the cutoff  reduces to testing for condition (2).</p>
<h1>Induced Order Statistics</h1>
<p>Consider a random sample  from a distribution  of . The order statistics of the sample of the running variable,  will in sample of the baseline covariate, say,  according to the rule: if  then  for all . It is worth mentioning that the values of this induced order statistics are not necessarily ordered.</p>
<h2>The test statistic</h2>
<p>The test statistic exploits the behavior of the closest units to the left and right of the cutoff . More precisely, fix <em>q</em> ∈ ℕ and take the <em>q</em> closest values of the order statistics of  to the right, and the  closest values to the left:</p>
<p></p>
<p>and    </p>
<p></p>
<p>respectively. The induced order for the baseline covariates is then</p>
<p></p>
<p>    and    </p>
<p></p>
<p>respectively. The random variabes  can be viewed as an independent sample of  conditional on  being close to the cutoff from the left. Analogously,  can be thought of an independent sample of $ conditional on $ being close to the cutoff from the right. Let  and  be the empirical CDFs of the two samples of size , respectively,</p>
<p></p>
<p>    and    </p>
<p></p>
<p>Stack all the  observations of the baseline covariates into</p>
<p></p>
<p>The test statistic is a Cramér-von Mises type test:</p>
<p></p>
<h2>Computing <em>p</em>-values</h2>
<p>We argued that the permutation test rejects the null hypothesis (2) if  is bigger than the  quantile of the randimization distribution. Alternatively, we can define the <em>p</em>-value of a permutation test, , as</p>
<p></p>
<p>where  is the observed sample, and  is the cardinality of . It can be shown</p>
<p></p>
<p></p>
<p></p>
<p>therefore, the test that rejects when  is level .</p>
<h2>Stochastic approximation</h2>
<p>When computing the permutation distribution, we often encounter the situation that the cardinality of  might be large such that it becomes computationally prohibitive. In this situation, it is possible to approximate the -values the following way. Randomly sample permutations  from  with or without replacement. Suppose the sampling is with replacement, then  are i.i.d. and uniformly distributed on . Then</p>
<p></p>
<p>is such that</p>
<p></p>
<p>where this $P$ takes into account the randomness of  and the sampling of the . Like in the previous case, the test that rejects when  is level .</p>
<p>It is worth noticing that the approximation  satisfies the above equation regardless of , although a bigger  will improve the approximation. As a matter of fact,  as . The <a rel="nofollow" href="https://cran.r-project.org/web/packages/RATest/index.html" target="_blank">RATest</a> package uses  by default.</p>
<h2>Tuning parameter <em>q</em></h2>
<p>The implementation of the test statistic heavily relies on , the number of closest values of the running variable to the left and right of the cutoff. This quantity is small relative to the sample size , and remains fixed as . Canay and Kamat (2017) recomend the rule of thumb</p>
<p></p>
<p>where  is the smallest integer greater or equal to ,  is the density if  at zero,  is the coefficient of correlation  and , and  is the variance of . For the scalar case, it can be estimated from sample. The feasible tuning parameter is</p>
<p></p>
<p>where , and . The lower bound,  represents situations in which the randomized and non-randomized versions of the permutation test differ, whereas the upper bound,  guarantees the rate of convergence does not violate the formal results in Canay and Kamat (2017), theorem 4.1. The same reasoning applies if we replace  with . The density function  is estimated employing the univariate adaptative kernel density estimation <em>à</em> la Silverman (e.g. Portnoy and Koenker (1989), Koenker and Xiao (2002), Silverman (1986)}, and the results are obtained directly from the <code>R</code> package <a rel="nofollow" href="https://cran.r-project.org/web/packages/quantreg/index.html" target="_blank">quantreg</a>. Finally,  and  are estimated by their sample counterparts.</p>
<p>The <a rel="nofollow" href="https://cran.r-project.org/web/packages/RATest/index.html" target="_blank">RATest</a> package also computes the corresponding rule of thumb that changes a little bit in when <em>W</em> is a <em>K</em>-dimensional vector, since the variances and correlations are not scalars.</p>
<h1>Empirical Illustration</h1>
<p>The empirical illustration is based on Lee’s (2008) of the effect of party incumbency advantage in electoral outcomes. For comparative purposes we follow the same empirical study chosen by Canay and Kamat (2017).</p>
<p>The objective of Lee’s (2008) is to assess whether a Democratic candidate of the US. House of Representative has an edge over his competitors if his party won the previous election. The causal effect of party incumbency is captured by exploiting the fact that an election winner is determined by  where , the running variable, is the vote shares between Democrats and Republicans.</p>
<p>Figure 1 shows Lee (2008) sharp RD strategy. The figure illustrates the sharp change in probability of a Democrat winning against the difference in vote share in the previous election. The data used here and contained in the package have six covariates and 6,558 observations with information on the Democrat runner and the opposition. The data set is named , and it is a subset of the publicly available data set in the <a rel="nofollow" href="http://economics.mit.edu/faculty/angrist/data1/mhe" target="_blank">Mostly Harmless Econometrics Data Archive</a></p>
<div>
<div>
<pre><code><span> </span><span>#Load Package</span><span>
</span><span>require</span><span>(</span><span>&quot;RATest&quot;</span><span>)</span><span>
</span><span># Load the data set</span><span>
</span><span>lee2008</span><span>&lt;-</span><span>lee2008</span><span>
</span><span>lee2008</span><span>$</span><span>d</span><span>&lt;-</span><span> </span><span>ifelse</span><span>(</span><span>lee2008</span><span>$</span><span>difdemshare</span><span> </span><span>>=</span><span> </span><span>0</span><span>,</span><span>1</span><span>,</span><span>0</span><span>)</span><span>
</span><span># Predict with local polynomial logit of degree 4</span><span>
</span><span>logit.a</span><span> </span><span>&lt;-</span><span> </span><span>glm</span><span>(</span><span>formula</span><span> </span><span>=</span><span> </span><span>demsharenext</span><span> </span><span>~</span><span> </span><span>poly</span><span>(</span><span>difdemshare</span><span>,</span><span> </span><span>degree</span><span> </span><span>=</span><span> </span><span>4</span><span>)</span><span> </span><span>+</span><span>
</span><span>poly</span><span>(</span><span>difdemshare</span><span>,</span><span> </span><span>degree</span><span> </span><span>=</span><span> </span><span>4</span><span>)</span><span> </span><span>*</span><span> </span><span>d</span><span>,</span><span>
</span><span>family</span><span> </span><span>=</span><span> </span><span>binomial</span><span>(</span><span>link</span><span> </span><span>=</span><span> </span><span>&quot;logit&quot;</span><span>),</span><span>
</span><span>data</span><span> </span><span>=</span><span> </span><span>lee2008</span><span>)</span><span>
</span><span>lee2008</span><span>$</span><span>demsharenexthat</span><span>&lt;-</span><span>predict</span><span>(</span><span>logit.a</span><span>,</span><span> </span><span>lee2008</span><span>,</span><span> </span><span>type</span><span> </span><span>=</span><span> </span><span>&quot;response&quot;</span><span>)</span><span>
</span><span># Create local average by 0.005 interval of the running variable (share)</span><span>
</span><span>breaks</span><span> </span><span>&lt;-</span><span> </span><span>round</span><span>(</span><span>seq</span><span>(</span><span>-1</span><span>,</span><span> </span><span>1</span><span>,</span><span> </span><span>by</span><span> </span><span>=</span><span> </span><span>0.005</span><span>),</span><span> </span><span>3</span><span>)</span><span>
</span><span>lee2008</span><span>$</span><span>i</span><span>005</span><span>&lt;-</span><span>as.numeric</span><span>(</span><span>as.character</span><span>(</span><span>cut</span><span>(</span><span>lee2008</span><span>$</span><span>difdemshare</span><span>,</span><span>
</span><span>breaks</span><span> </span><span>=</span><span> </span><span>breaks</span><span>,</span><span>
</span><span>labels</span><span> </span><span>=</span><span> </span><span>head</span><span>(</span><span>breaks</span><span>,</span><span> </span><span>-1</span><span>),</span><span>
</span><span>right</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>)))</span><span>
</span><span>m_next</span><span>&lt;-</span><span>tapply</span><span>(</span><span>lee2008</span><span>$</span><span>demsharenext</span><span>,</span><span>lee2008</span><span>$</span><span>i</span><span>005</span><span>,</span><span>mean</span><span>)</span><span>
</span><span>m_next</span><span>&lt;-</span><span>data.frame</span><span>(</span><span>i</span><span>005</span><span>=</span><span>rownames</span><span>(</span><span>m_next</span><span>),</span><span> </span><span>m_next</span><span>=</span><span>m_next</span><span>)</span><span>
</span><span>mp_next</span><span>&lt;-</span><span>tapply</span><span>(</span><span>lee2008</span><span>$</span><span>demsharenexthat</span><span>,</span><span>lee2008</span><span>$</span><span>i</span><span>005</span><span>,</span><span>mean</span><span>)</span><span>
</span><span>mp_next</span><span>&lt;-</span><span>data.frame</span><span>(</span><span>i</span><span>005</span><span>=</span><span>rownames</span><span>(</span><span>mp_next</span><span>),</span><span> </span><span>mp_next</span><span>=</span><span>mp_next</span><span>)</span><span>
</span><span>panel.a</span><span>&lt;-</span><span>merge</span><span>(</span><span>m_next</span><span>,</span><span>mp_next</span><span>,</span><span>by</span><span>=</span><span>c</span><span>(</span><span>&quot;i005&quot;</span><span>),</span><span> </span><span>all</span><span>=</span><span>T</span><span>)</span><span>
</span><span>panel.a</span><span>$</span><span>i</span><span>005</span><span>&lt;-</span><span>as.numeric</span><span>(</span><span>as.character</span><span>(</span><span>panel.a</span><span>$</span><span>i</span><span>005</span><span>))</span><span>
</span><span># Plot panel (a) MHE</span><span>
</span><span>panel.a</span><span> </span><span>&lt;-</span><span> </span><span>panel.a</span><span>[</span><span>which</span><span>(</span><span>panel.a</span><span>$</span><span>i</span><span>005</span><span> </span><span>></span><span> </span><span>-0.251</span><span> </span><span>&amp;</span><span> </span><span>panel.a</span><span>$</span><span>i</span><span>005</span><span> </span><span></span><span> </span><span>0.251</span><span>),</span><span> </span><span>]</span><span>
</span><span>plot.a</span><span> </span><span>&lt;-</span><span> </span><span>ggplot</span><span>(</span><span>data</span><span> </span><span>=</span><span> </span><span>panel.a</span><span>,</span><span> </span><span>aes</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>i</span><span>005</span><span>))</span><span> </span><span>+</span><span>
</span><span>geom_point</span><span>(</span><span>aes</span><span>(</span><span>y</span><span> </span><span>=</span><span> </span><span>m_next</span><span>))</span><span> </span><span>+</span><span>
</span><span>geom_line</span><span>(</span><span>aes</span><span>(</span><span>y</span><span> </span><span>=</span><span> </span><span>mp_next</span><span>,</span><span> </span><span>group</span><span> </span><span>=</span><span> </span><span>i</span><span>005</span><span> </span><span>>=</span><span> </span><span>0</span><span>))</span><span> </span><span>+</span><span>
</span><span>geom_vline</span><span>(</span><span>xintercept</span><span> </span><span>=</span><span> </span><span>0</span><span>,</span><span> </span><span>linetype</span><span> </span><span>=</span><span> </span><span>'longdash'</span><span>)</span><span> </span><span>+</span><span>
</span><span>xlab</span><span>(</span><span>'Democratic Vote Share Margin of Victory, Election t'</span><span>)</span><span> </span><span>+</span><span>
</span><span>ylab</span><span>(</span><span>'Democrat Vote Share, Election t+1'</span><span>)</span><span> </span><span>+</span><span>
</span><span>theme_bw</span><span>()</span><span>
</span><span>plot.a</span><span>
</span></code></pre>
</div>
</div>
<p><img align="middle" src="https://i0.wp.com/ignaciomsarmiento.github.io/assets/images/ratest/unnamed-chunk-1-1.png?w=450&ssl=1" data-recalc-dims="1"> </p>
<p>One check used by practitioners to assess the credibility of the RD designs relies on graphical depiction of the conditional mean of the baseline covariates . Figure 2 plots this for the Democrat vote share in . A simple visual inspection would lead the researcher to conclude that there are no discontinuities at the cutoff for these baseline covariates.</p>
<div>
<div>
<pre><code><span> </span><span># Predict with local polynomial logit of degree 4</span><span>
</span><span>logit.b</span><span> </span><span>&lt;-</span><span> </span><span>glm</span><span>(</span><span>formula</span><span> </span><span>=</span><span> </span><span>demshareprev</span><span> </span><span>~</span><span> </span><span>poly</span><span>(</span><span>difdemshare</span><span>,</span><span> </span><span>degree</span><span> </span><span>=</span><span> </span><span>4</span><span>)</span><span> </span><span>+</span><span>
</span><span>poly</span><span>(</span><span>difdemshare</span><span>,</span><span> </span><span>degree</span><span> </span><span>=</span><span> </span><span>4</span><span>)</span><span> </span><span>*</span><span> </span><span>d</span><span>,</span><span>
</span><span>family</span><span> </span><span>=</span><span> </span><span>binomial</span><span>(</span><span>link</span><span> </span><span>=</span><span> </span><span>&quot;logit&quot;</span><span>),</span><span>
</span><span>data</span><span> </span><span>=</span><span> </span><span>lee2008</span><span>)</span><span>
</span><span>lee2008</span><span>$</span><span>demshareprevhat</span><span>&lt;-</span><span>predict</span><span>(</span><span>logit.b</span><span>,</span><span> </span><span>lee2008</span><span>,</span><span> </span><span>type</span><span> </span><span>=</span><span> </span><span>&quot;response&quot;</span><span>)</span><span>
</span><span># Create local average by 0.005 interval of the running variable (share)</span><span>
</span><span>breaks</span><span> </span><span>&lt;-</span><span> </span><span>round</span><span>(</span><span>seq</span><span>(</span><span>-1</span><span>,</span><span> </span><span>1</span><span>,</span><span> </span><span>by</span><span> </span><span>=</span><span> </span><span>0.005</span><span>),</span><span> </span><span>3</span><span>)</span><span>
</span><span>lee2008</span><span>$</span><span>i</span><span>005</span><span>&lt;-</span><span>as.numeric</span><span>(</span><span>as.character</span><span>(</span><span>cut</span><span>(</span><span>lee2008</span><span>$</span><span>difdemshare</span><span>,</span><span>
</span><span>breaks</span><span> </span><span>=</span><span> </span><span>breaks</span><span>,</span><span>
</span><span>labels</span><span> </span><span>=</span><span> </span><span>head</span><span>(</span><span>breaks</span><span>,</span><span> </span><span>-1</span><span>),</span><span>
</span><span>right</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>)))</span><span>
</span><span>m_next</span><span>&lt;-</span><span>tapply</span><span>(</span><span>lee2008</span><span>$</span><span>demshareprev</span><span>,</span><span>lee2008</span><span>$</span><span>i</span><span>005</span><span>,</span><span>mean</span><span>)</span><span>
</span><span>m_next</span><span>&lt;-</span><span>data.frame</span><span>(</span><span>i</span><span>005</span><span>=</span><span>rownames</span><span>(</span><span>m_next</span><span>),</span><span> </span><span>m_next</span><span>=</span><span>m_next</span><span>)</span><span>
</span><span>mp_next</span><span>&lt;-</span><span>tapply</span><span>(</span><span>lee2008</span><span>$</span><span>demshareprevhat</span><span>,</span><span>lee2008</span><span>$</span><span>i</span><span>005</span><span>,</span><span>mean</span><span>)</span><span>
</span><span>mp_next</span><span>&lt;-</span><span>data.frame</span><span>(</span><span>i</span><span>005</span><span>=</span><span>rownames</span><span>(</span><span>mp_next</span><span>),</span><span> </span><span>mp_next</span><span>=</span><span>mp_next</span><span>)</span><span>
</span><span>panel.b</span><span>&lt;-</span><span>merge</span><span>(</span><span>m_next</span><span>,</span><span>mp_next</span><span>,</span><span>by</span><span>=</span><span>c</span><span>(</span><span>&quot;i005&quot;</span><span>),</span><span> </span><span>all</span><span>=</span><span>T</span><span>)</span><span>
</span><span>panel.b</span><span>$</span><span>i</span><span>005</span><span>&lt;-</span><span>as.numeric</span><span>(</span><span>as.character</span><span>(</span><span>panel.b</span><span>$</span><span>i</span><span>005</span><span>))</span><span>
</span><span># Plot panel (b) MHE</span><span>
</span><span>panel.b</span><span> </span><span>&lt;-</span><span> </span><span>panel.b</span><span>[</span><span>which</span><span>(</span><span>panel.b</span><span>$</span><span>i</span><span>005</span><span> </span><span>></span><span> </span><span>-0.251</span><span> </span><span>&amp;</span><span> </span><span>panel.b</span><span>$</span><span>i</span><span>005</span><span> </span><span></span><span> </span><span>0.251</span><span>),</span><span> </span><span>]</span><span>
</span><span>plot.b</span><span> </span><span>&lt;-</span><span> </span><span>ggplot</span><span>(</span><span>data</span><span> </span><span>=</span><span> </span><span>panel.b</span><span>,</span><span> </span><span>aes</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>i</span><span>005</span><span>))</span><span> </span><span>+</span><span>
</span><span>geom_point</span><span>(</span><span>aes</span><span>(</span><span>y</span><span> </span><span>=</span><span> </span><span>m_next</span><span>))</span><span> </span><span>+</span><span>
</span><span>geom_line</span><span>(</span><span>aes</span><span>(</span><span>y</span><span> </span><span>=</span><span> </span><span>mp_next</span><span>,</span><span> </span><span>group</span><span> </span><span>=</span><span> </span><span>i</span><span>005</span><span> </span><span>>=</span><span> </span><span>0</span><span>))</span><span> </span><span>+</span><span>
</span><span>geom_vline</span><span>(</span><span>xintercept</span><span> </span><span>=</span><span> </span><span>0</span><span>,</span><span> </span><span>linetype</span><span> </span><span>=</span><span> </span><span>'longdash'</span><span>)</span><span> </span><span>+</span><span>
</span><span>xlab</span><span>(</span><span>'Democratic Vote Share Margin of Victory, Election t'</span><span>)</span><span> </span><span>+</span><span>
</span><span>ylab</span><span>(</span><span>'Democrat Vote Share, Election t-1'</span><span>)</span><span> </span><span>+</span><span>
</span><span>theme_bw</span><span>()</span><span>
</span><span>plot.b</span><span>
</span></code></pre>
</div>
</div>
<p><img align="middle" src="https://i2.wp.com/ignaciomsarmiento.github.io/assets/images/ratest/unnamed-chunk-2-1.png?w=450&ssl=1" data-recalc-dims="1"> </p>
<p>This package however, implements Canay and Kamat (2017) in the function . The following code performs the test for the continuity of the named in the data set at the threshold. The function requires the name of the baseline covariate to be tested, the running variable , the data set name. We also specify a natural number that will define the q closest values of the order statistics of the running variable () to the right and to the left of the cutoff. As default, the function uses the Cram’er-von Mises test . The function is available for a concise summary of the result.</p>
<div>
<div>
<pre><code><span> </span><span># Lee2008</span><span>
</span><span>set.seed</span><span>(</span><span>101</span><span>)</span><span>
</span><span>permtest</span><span>&lt;-</span><span>RDperm</span><span>(</span><span>W</span><span>=</span><span>&quot;demshareprev&quot;</span><span>,</span><span> </span><span>z</span><span>=</span><span>&quot;difdemshare&quot;</span><span>,</span><span>data</span><span>=</span><span>lee2008</span><span>,</span><span>q_type</span><span>=</span><span>51</span><span>)</span><span>
</span><span>summary</span><span>(</span><span>permtest</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code>#>
#> **********************************************************
#> **       RD Distribution Test using permutations        **
#> **********************************************************
#> Running Variable: difdemshare
#> Cutoff: 0
#> q: Defined by User
#> Test Statistic: CvM
#> Number of Permutations: 499
#> Number of Obs: 6558
#>
#> **********************************************************
#> H0: 'Continuity of the baseline covariates at the cutoff'
#> **********************************************************
#>
#> Estimates:
#>               T(Sn)  Pr(>|z|)  q
#> demshareprev  0.03   0.01      51  **
#> ---
#> Signif. codes:   0.01 '***' 0.05 '**' 0.1 '*'
</code></pre>
</div>
</div>
<p>The function reports the vaule of the test statistics (), the <em>p</em>-value and the number of q closest values used. This is particularly relevant when the user chooses any of the `rule of thumb’ methods for <em>q</em>. The function allows for multiple baseline covariates as well, in which case it will return the join test. The following code shows how to do this</p>
<div>
<div>
<pre><code><span>permtest_rot</span><span>&lt;-</span><span>RDperm</span><span>(</span><span>W</span><span>=</span><span>c</span><span>(</span><span>&quot;demshareprev&quot;</span><span>,</span><span>&quot;demwinprev&quot;</span><span>,</span><span> </span><span>&quot;demofficeexp&quot;</span><span>),</span><span>
</span><span>z</span><span>=</span><span>&quot;difdemshare&quot;</span><span>,</span><span>data</span><span>=</span><span>lee2008</span><span>,</span><span>q_type</span><span>=</span><span>'rot'</span><span>,</span><span> </span><span>n.perm</span><span>=</span><span>600</span><span>)</span><span>
</span><span>summary</span><span>(</span><span>permtest_rot</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code>#>
#> **********************************************************
#> **       RD Distribution Test using permutations        **
#> **********************************************************
#> Running Variable: difdemshare
#> Cutoff: 0
#> q: Rule of Thumb
#> Test Statistic: CvM
#> Number of Permutations: 600
#> Number of Obs: 6558
#>
#> **********************************************************
#> H0: 'Continuity of the baseline covariates at the cutoff'
#> **********************************************************
#>
#> Estimates:
#>               T(Sn)  Pr(>|z|)  q
#> demshareprev  0.08   0         32  ***
#> demwinprev    0.08   0         35  ***
#> demofficeexp  0.06   0.01      45  **
#> Joint.Test    0.11   0         32  ***
#> ---
#> Signif. codes:   0.01 '***' 0.05 '**' 0.1 '*'
</code></pre>
</div>
</div>
<p>A plot function is also available for objects of the class <code>RDperm</code>. It works as the base function, but it needs the specification of the desired baseline covariate to be plotted. The output can be a <code>ggplot</code> histogram (<code>hist</code>), CDF (<code>cdf</code>) or <code>both</code>. The default is <code>both</code>.</p>
<div>
<div>
<pre><code><span>plot</span><span>(</span><span>permtest</span><span>,</span><span>w</span><span>=</span><span>&quot;demshareprev&quot;</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<p><img align="middle" src="https://i2.wp.com/ignaciomsarmiento.github.io/assets/images/ratest/unnamed-chunk-6-1.png?w=450&ssl=1" data-recalc-dims="1"> </p>
<h1>Conclusions</h1>
<p>In this blog post we described the <code>RDperm</code> funcion on the <a rel="nofollow" href="https://cran.r-project.org/web/packages/RATest/index.html" target="_blank">RATest</a> package in <code>R</code>, which allows the practitioner to test the null hypothesis of continuity of the distribution of the baseline covariates in the RDD, as developed by Canay and Kamat (2017). Based on a result on induced order statistics, the <a rel="nofollow" href="https://cran.r-project.org/web/packages/RATest/index.html" target="_blank">RATest</a> package implements a permutation test based on the Cramér-von Mises test statistic.</p>
<p>The main functionalities of the package have been illustrated by applying them to the celebrated RDD of the U.S. House elections in Lee(2008)</p>
<h1>References</h1>
<p>Canay, Ivan A, and Vishal Kamat. 2017. “Approximate Permutation Tests and Induced Order Statistics in the Regression Discontinuity Design.” <em>The Review of Economic Studies</em> 85 (3). Oxford University Press: 1577–1608.</p>
<p>Hahn, Jinyong, Petra Todd, and Wilbert Van der Klaauw. 2001. “Identification and Estimation of Treatment Effects with a Regression-Discontinuity Design.” <em>Econometrica</em> 69 (1). Wiley Online Library: 201–9.</p>
<p>Koenker, Roger, and Zhijie Xiao. 2002. “Inference on the Quantile Regression Process.” <em>Econometrica</em> 70 (4). Wiley Online Library: 1583–1612.</p>
<p>Lee, David S. 2008. “Randomized Experiments from Non-Random Selection in Us House Elections.” <em>Journal of Econometrics</em> 142 (2). Elsevier: 675–97.</p>
<p>Portnoy, Stephen, and Roger Koenker. 1989. “Adaptive L-Estimation for Linear Models.” <em>The Annals of Statistics</em>. JSTOR, 362–81.</p>
<p>Silverman, Bernard W. 1986. <em>Density Estimation for Statistics and Data Analysis</em>. Vol. 26. CRC press.</p>
<p>[1] This has been highlighted by Canay and Kamat (2017). See Appendix E for a survey of the topic in leading journals from 2011 to 2015.</p>
<p>[2] To put it in a more compact way, we say individual ’s observed outcome,  is , whereas the identification assumption in Hahn et al (2001) requires that both </p>
<p>[3] See condition 2b in Lee (2008).</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://ignaciomsarmiento.github.io/2018/11/11/RDperm.html"> Ignacio Sarmiento Barbieri</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/sYTubUIV8hQ" height="1"></a></div>