## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment  = "#>",
  fig.width  = 7,
  fig.height = 4
)

## ----eval = FALSE-------------------------------------------------------------
# # CRAN
# install.packages("rdstagger")
# 
# # GitHub (development)
# remotes::install_github("causalfragility-lab/rdstagger")

## -----------------------------------------------------------------------------
library(rdstagger)

set.seed(42)
sim <- sim_rdstagger(
  n               = 400,
  nperiods        = 8,
  n_cohorts       = 3,
  cutoff          = 0,
  bw              = 1,
  network_density = 0.08,
  true_direct     = 0.30,
  true_spill      = 0.10,
  outcome_type    = "continuous"
)

head(sim$data)
sim$true_params

## -----------------------------------------------------------------------------
res <- rdstagger_attgt(
  data    = sim$data,
  yname   = "y",
  xname   = "x",
  cutoff  = 0,
  gname   = "g",
  tname   = "period",
  idname  = "id",
  network = sim$network,
  bw      = 1.5,
  boot    = FALSE        # set TRUE for inference
)

print(res)

## -----------------------------------------------------------------------------
pt <- rdstagger_pretest(res, method = "both")
print(pt)

## -----------------------------------------------------------------------------
agg <- rdstagger_agg(res, type = "dynamic")
print(agg)
plot(agg)

## -----------------------------------------------------------------------------
agg_group <- rdstagger_agg(res, type = "group")
print(agg_group)

## -----------------------------------------------------------------------------
if (!is.null(res$spillgt)) {
  head(res$spillgt)
}

## ----eval = FALSE-------------------------------------------------------------
# bw_sel <- rdstagger_bw(
#   data   = sim$data,
#   yname  = "y",
#   xname  = "x",
#   cutoff = 0,
#   gname  = "g",
#   tname  = "period"
# )
# bw_sel$bw_common

