# LRErdd
Regression Discontinuity as Local Randomized Experiments

We present the R LRErdd package with a case study. The package includes a set of functions for the design and analysis of Regression Discontinuity Designs as local randomized experiments within the potential outcome approach as formalized in Li et al (2015). 

A sub-set of functions implements the design phase of the study where focus is on the selection of suitable subpopulations for which we can draw valid causal inference. 
These functions provide summary statistics of pre-and post-treatment variables by treatment status, and select suitable subpopulations around the threshold where pre-treatment variables are well balanced between treatment using randomization-based tests with adjustment for multiplicities. Functions for a visual inspection of the results are also provided. 

Finally the LRErdd package includes a set of functions for drawing inference on causal effects for the selected subpopulations using randomization-based modes of inference. Specifically the Fisher Exact $p-$value and Neyman approaches are implemented for the analysis of both sharp and fuzzy RD designs. We illustrate our approach in a study concerning the effects of University grants on student dropout.
                                                   
Li F, Mattei A, Mealli F (2015). Bayesian inference for regression discontinuity designs with application to the evaluation of Italian university grants. The Annals of Applied Statistics, 9(4), 1906-1931. https://doi.org/10.1214/15-AOAS809

## Practical example

In the next two sections we will explain functionalities of the package in a coding version and in a friendly-user application. 

### User-friendly application

In this case, the only steps that you have to follow are the next ones:

```r
# Install from CRAN
install.packages("LRErdd")

library(LRErdd)
open_LRErdd_framework()
```

### Coding example

In the case of coding example, first we need to create a new RegressionDiscontinuityClass giving the required variables. 

```r

   library(LRErdd)

   # Load the dataset included in the package
   data(grants)
   fitx <- grants
   
   # Selection of the covariates of interest
   cov <- c("HSTech", "hsgrade","Y2005")
   
   # Create a RegressionDiscontinuityClass with the required information
   rdo <- RegressionDiscontinuityClass$new(data = fitx, forcing = "S", 
                                      threshold = 15000, Z1S1 = "lower", 
                                      covariates = cov)
   # Summary of the class
   rdo$full_print()

   # Summary of statistics
   rdo$summary_statistics_mean()
   
   # Selection of the bandwith
   rdo$bandwidth_selection(typerange = "percentage", range_value = 25, num_it = 50, plot = TRUE)
   
   # Distribution pre and post matching
   rdo$distribution_plot(typerange = "percentage", range_value = 25, num_it = 50, covariate = "sex", typecov = "binary")
   
   # Summary of bandwidths
   rdo$summary_bandwidth(buffers = c(100, 500, 1000), num_it = 1000)
   
   # Causal effect with the four methods: sharp FEP, sharp Neyman, Fuzzy Neyman and Fuzzy FEP
   rdo$causal_effect(method = 'Sharp FEP', buffers = c(100, 500, 1000), num_it = 50, outcome = "dropout", typeoutcome = "binary", plot = TRUE)
   
   rdo$causal_effect(method = 'Sharp Neyman', buffers = c(100, 500, 1000), num_it = 50, outcome = "dropout", typeoutcome = "binary",sided = "onesided", cin = 0.05, plot = TRUE)
   
   rdo$causal_effect(method = 'Fuzzy Neyman', buffers = c(100, 500, 1000), num_it = 50, outcome = "dropout", typeoutcome = "binary", treatm_cov = "W", plot = TRUE)
   
   rdo$causal_effect(method = 'Fuzzy FEP', buffers = c(100, 500, 1000), num_it = 50, outcome = "dropout", typeoutcome = "binary",sided = "twosided", cin = 0.95, treatm_cov = "W", num_it_fuzzy = 5, plot = TRUE)
   
```

