wdd {ptools}R Documentation

Estimates the WDD Test

Description

Estimates the weighted displacement difference test from Wheeler & Ratcliffe, A simple weighted displacement difference test to evaluate place based crime interventions, Crime Science

Usage

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
)

Arguments

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 c(0,0))

disp_treated

vector with counts in pre,post for displacement treated area (default c(0,0))

time_weights

vector with weights for time periods for pre/post (default c(1,1))

area_weights

vector with weights for different sized areas, order is c(control,treated,disp_control,disp_treated) (default c(1,1,1,1))

alpha

scaler alpha level for confidence interval (default 0.1)

silent

boolean set to TRUE if you do not want anything printed out (default FALSE)

Details

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 = \Delta T - \Delta Ct

where \Delta T = T_1 - T_0, 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:

T_1 + T_0 + Ct_1 + Ct_0

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.

Value

A length 9 vector with names:

References

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.

See Also

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

Examples

# 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

[Package ptools version 2.0.0 Index]