Unifies shift_border, cutoff2polygon, assign_treated in one function to carry out a myriad of placebo checks at once. The output is either a data.frame (with or without geometry of the respective placeboline) or a coefplot. Requires operations data.frame that contains all desired operations (columns shift.x, shift.y, scale, angle, orientation.1, orientation.2, endpoint.1, endpoint.2), if you don't need a certain operation just use default values (e.g. 0 for angle and 1 for scale), but the column has to be there.

create_placebos(
  data,
  cutoff,
  formula,
  operations,
  bw_dist,
  coefplot = FALSE,
  geometry = FALSE
)

Arguments

data

sf data.frame that contains all units of observation

cutoff

initial RD cutoff as an sj object

formula

provide the formula you want to use for OLS, omit the treatetment dummy (if you want a univariate regression just on "treated", then provide y ~ 1 as formula)

operations

container that has all the information in it on how to change the border for each placeboregression

bw_dist

what is the distance for the bandwith (in CRS units, thus ideally metres)

coefplot

provide coefplot instead of a data.frame

geometry

set to TRUE if you want to plot all the lines of the used placebo borders

Value

either a coefplot or data.frame containing results of placebo regressions

Examples

points_samp.sf <- sf::st_sample(polygon_full, 100) # create points
# make it an sf object bc st_sample only created the geometry list-column (sfc):
points_samp.sf <- sf::st_sf(points_samp.sf)
# add a unique ID to each observation:
points_samp.sf$id <- 1:nrow(points_samp.sf)
points_samp.sf$treated <- assign_treated(points_samp.sf, polygon_treated, id = "id")
#> Warning: attribute variables are assumed to be spatially constant throughout all geometries
operations.df <- data.frame(operation = c("shift"),
                            shift.x = c(0),
                            shift.y = c(0),
                            scale = 1,
                            angle = 0,
                            orientation.1 = c("west"),
                            orientation.2 = c("west"),
                            endpoint.1 = c(.8),
                            endpoint.2 = c(.2))
create_placebos(data = points_samp.sf, cutoff = cut_off,
formula = id ~ 1, operations = operations.df, bw_dist = 3000)
#> Simple feature collection with 1 feature and 0 fields
#> Geometry type: MULTILINESTRING
#> Dimension:     XY
#> Bounding box:  xmin: 366034.5 ymin: 1673763 xmax: 400561.6 ymax: 1734272
#> Projected CRS: WGS 84 / UTM zone 43N
#>                       border_sfc
#> 1 MULTILINESTRING ((366034.5 ...
#> Warning: attribute variables are assumed to be spatially constant throughout all geometries
#> [1] "HERE"
#>   id estimate std.error statistic   p.value rd.estimate     const       HC0
#> 1  1 8.966667  14.53169  0.617042 0.5471117    34.49697 0.6695952 0.6263489
#>         HC1       HC2       HC3 HC4 operation shift.x shift.y scale angle
#> 1 0.6205987 0.5747843 0.6113464  NA     shift       0       0     1     0
#>   orientation.1 orientation.2 endpoint.1 endpoint.2
#> 1          west          west        0.8        0.2