## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 7,
  fig.height = 4.5,
  warning = FALSE,
  message = FALSE
)
set.seed(27)

## ----install, eval = FALSE----------------------------------------------------
#  install.packages("LRErdd")

## ----load---------------------------------------------------------------------
library(LRErdd)

## ----data---------------------------------------------------------------------
data(grants)
dim(grants)
head(grants[, c("S", "Z", "A", "W", "dropout", "sex", "hsgrade")])

## ----create-------------------------------------------------------------------
# Covariates of interest
cov <- c("HSTech", "hsgrade", "Y2005")

rdo <- RegressionDiscontinuityClass$new(
  data       = grants,
  forcing    = "S",
  threshold  = 15000,
  Z1S1       = "lower",
  covariates = cov
)

## ----fullprint----------------------------------------------------------------
rdo$full_print()

## ----summarystats-------------------------------------------------------------
rdo$summary_statistics_mean()

## ----bandwidth----------------------------------------------------------------
rdo$bandwidth_selection(
  typerange   = "percentage",
  range_value = 25,
  num_it      = 100,
  plot        = TRUE
)

## ----distplot-----------------------------------------------------------------
rdo$distribution_plot(
  typerange   = "percentage",
  range_value = 25,
  num_it      = 100,
  covariate   = "sex",
  typecov     = "binary"
)

## ----summarybw----------------------------------------------------------------
rdo$summary_bandwidth(buffers = c(500, 1000, 1500), num_it = 200)

## ----sharpfep-----------------------------------------------------------------
rdo$causal_effect(
  method      = "Sharp FEP",
  buffers     = c(500, 1000, 1500),
  num_it      = 100,
  outcome     = "dropout",
  typeoutcome = "binary",
  plot        = TRUE
)

## ----sharpneyman--------------------------------------------------------------
rdo$causal_effect(
  method      = "Sharp Neyman",
  buffers     = c(500, 1000, 1500),
  num_it      = 100,
  outcome     = "dropout",
  typeoutcome = "binary",
  cin         = 0.05,
  plot        = TRUE
)

## ----fuzzyneyman--------------------------------------------------------------
rdo$causal_effect(
  method      = "Fuzzy Neyman",
  buffers     = c(500, 1000, 1500),
  num_it      = 100,
  outcome     = "dropout",
  typeoutcome = "binary",
  treatm_cov  = "W",
  plot        = TRUE
)

## ----fuzzyfep-----------------------------------------------------------------
rdo$causal_effect(
  method       = "Fuzzy FEP",
  buffers      = c(500, 1000, 1500),
  num_it       = 100,
  outcome      = "dropout",
  typeoutcome  = "binary",
  sided        = "twosided",
  treatm_cov   = "W",
  num_it_fuzzy = 5,
  plot         = TRUE
)

## ----shiny, eval = FALSE------------------------------------------------------
#  open_LRErdd_framework()

## ----session------------------------------------------------------------------
sessionInfo()

