Preliminary function, styling with e.g. kable and kableExtra has to be done by the user individually.
You could also just use the package of your choice to print out columns of the output from spatialrd
.
printspatialrd(SpatialRDoutput)
output file from the spatialrd
function
A table with results from the spatialrd
function
points_samp.sf <- sf::st_sample(polygon_full, 1000) # 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)
# assign treatment:
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
# first we define a variable for the number of "treated" and control
NTr <- length(points_samp.sf$id[points_samp.sf$treated == 1])
NCo <- length(points_samp.sf$id[points_samp.sf$treated == 0])
# the treated areas get a 10 percentage point higher literacy rate
points_samp.sf$education[points_samp.sf$treated == 1] <- 0.7
points_samp.sf$education[points_samp.sf$treated == 0] <- 0.6
# and we add some noise, otherwise we would obtain regression coeffictions with no standard errors
points_samp.sf$education[points_samp.sf$treated == 1] <- rnorm(NTr, mean = 0, sd = .1) +
points_samp.sf$education[points_samp.sf$treated == 1]
points_samp.sf$education[points_samp.sf$treated == 0] <- rnorm(NCo, mean = 0, sd = .1) +
points_samp.sf$education[points_samp.sf$treated == 0]
# create distance to cutoff
points_samp.sf$dist2cutoff <- as.numeric(sf::st_distance(points_samp.sf, cut_off))
points_samp.sf$distrunning <- points_samp.sf$dist2cutoff
# give the non-treated one's a negative score
points_samp.sf$distrunning[points_samp.sf$treated == 0] <- -1 *
points_samp.sf$distrunning[points_samp.sf$treated == 0]
# create borderpoints
borderpoints.sf <- discretise_border(cutoff = cut_off, n = 10)
borderpoints.sf$id <- 1:nrow(borderpoints.sf)
# finally, carry out estimation alongside the boundary:
results <- spatialrd(y = "education", data = points_samp.sf, cutoff.points = borderpoints.sf,
treated = "treated", minobs = 20, spatial.object = FALSE)
printspatialrd(results)
#> Point Estimate SE_Conv SE_Rob p_Conv p_Rob Ntr Nco bw_l bw_r CI_Conv_l
#> 1 1 0.05 0.040 0.050 0.140 0.340 115.0 84.0 17.80 17.80 -0.020
#> 2 2 0.13 0.060 0.070 0.020 0.040 91.0 25.0 12.90 12.90 0.020
#> 3 3 0.17 0.070 0.080 0.010 0.030 42.0 30.0 9.70 9.70 0.040
#> 4 4 0.27 0.130 0.140 0.030 0.040 35.0 56.0 10.40 10.40 0.020
#> 5 5 0.05 0.070 0.090 0.540 0.700 61.0 33.0 11.10 11.10 -0.100
#> 6 6 0.16 0.040 0.040 0.000 0.000 34.0 57.0 10.90 10.90 0.090
#> 7 7 0.09 0.070 0.090 0.220 0.400 59.0 58.0 12.30 12.30 -0.050
#> 8 8 0.09 0.080 0.100 0.270 0.320 83.0 36.0 12.50 12.50 -0.070
#> 9 9 0.05 0.050 0.060 0.260 0.480 262.0 86.0 21.10 21.10 -0.040
#> 10 10 0.14 0.050 0.060 0.000 0.010 173.0 71.0 20.50 20.50 0.050
#> 11 Mean 0.12 0.066 0.078 0.149 0.236 95.5 53.6 13.92 13.92 -0.006
#> CI_Conv_u CI_Rob_l CI_Rob_u
#> 1 0.130 -0.050 0.130
#> 2 0.240 0.000 0.270
#> 3 0.310 0.020 0.340
#> 4 0.520 0.010 0.580
#> 5 0.190 -0.140 0.200
#> 6 0.230 0.090 0.250
#> 7 0.230 -0.100 0.250
#> 8 0.240 -0.090 0.280
#> 9 0.140 -0.070 0.150
#> 10 0.230 0.040 0.260
#> 11 0.246 -0.029 0.271