wdd | R Documentation |
Estimates the weighted displacement difference test from Wheeler & Ratcliffe, A simple weighted displacement difference test to evaluate place based crime interventions, Crime Science
wdd( control, treated, disp_control = c(0, 0), disp_treated = c(0, 0), time_weights = c(1, 1), area_weights = c(1, 1, 1, 1), alpha = 0.1, silent = FALSE )
control |
vector with counts in pre,post for control area |
treated |
vector with counts in pre,post for treated area |
disp_control |
vector with counts in pre,post for displacement control area (default |
disp_treated |
vector with counts in pre,post for displacement treated area (default |
time_weights |
vector with weights for time periods for pre/post (default |
area_weights |
vector with weights for different sized areas, order is c(control,treated,disp_control,disp_treated) (default |
alpha |
scaler alpha level for confidence interval (default |
silent |
boolean set to TRUE if you do not want anything printed out (default FALSE) |
The wdd (weighted displacement difference) test is an extensions to differences-in-differences when observed count data pre/post in treated control areas. The test statistic (ignoring displacement areas and weights) is:
WDD = Δ T - Δ Ct
where Δ T = T1 - T0, the post time period count minus the pre time period count for the treated areas. And ditto for the control areas, Ct. The variance is calculated as:
T1 + T0 + Ct1 + Ct0
that is this test uses the normal approximation to the Poisson distribution to calculate the standard error for the WDD. So beware if using very tiny counts – this approximation is less likely to be applicable (or count data that is Poisson, e.g. very overdispersed).
This function also incorporates weights for different examples, such as differing pre/post time periods (e.g. 2 years in pre and 1 year in post), or different area sizes (e.g. a one square mile area vs a two square mile area). The subsequent test statistic can then be interpreted as changes per unit time or changes per unit area (e.g. density) or both per time and density.
A length 9 vector with names:
Est_Local
and SE_Local
, the WDD and its standard error for the local estimates
Est_Displace
and SE_Displace
, the WDD and its standard error for the displacement areas
Est_Total
and SE_Total
, the WDD and its standard error for the combined local/displacement areas
Z
, the Z-score for the total estimate
and the lower and upper confidence intervals, LowCI
and HighCI
, for whatever alpha level you specified for the total estimate.
Wheeler, A. P., & Ratcliffe, J. H. (2018). A simple weighted displacement difference test to evaluate place based crime interventions. Crime Science, 7(1), 1-9.
wdd_harm()
for aggregating multiple WDD tests into one metric (e.g. based on crime harm weights)
e_test()
for checking the difference in two Poisson means
# No weights and no displacement cont <- c(20,20); treat <- c(20,10) wdd(cont,treat) # With Displacement stats disptreat <- c(30,20); dispcont <- c(30,30) wdd(cont,treat,dispcont,disptreat) # With different time periods for pre/post wdd(cont,treat,time_weights=c(2,1)) # With different area sizes wdd(cont,treat,dispcont,disptreat,area_weights=c(2,1.5,3,3.2)) # You can technically use this even without pre (so just normal based approximation) # just put in 0's for the pre data (so does not factor into variance) res_test <- wdd(c(0,20),c(0,10)) twotail_p <- pnorm(res_test['Z'])*2 print(twotail_p) #~0.068 # e-test is very similar e_test(20,10) #~0.069
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.