## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
library(streetlamp)

## ----count-mean---------------------------------------------------------------
sim <- lamp_simulate(n_areas = 40, n_months = 36, design = "continuous",
                     effect = -0.2, base_rate = 30, seed = 5)
fit <- lamp_elasticity(sim, "affected_crime", lags = 0:3, method = "fe")
fit
lamp_effect_summary(fit)

## ----common-factors-----------------------------------------------------------
legacy_fe <- lamp_elasticity(sim, "crime_total", lags = 0:1, family = "ols_log")
pooled <- lamp_elasticity(sim, "crime_total", lags = 0:1, method = "cce_pooled")
mg <- lamp_elasticity(sim, "crime_total", lags = 0:1, method = "cce_mg")
rbind(fe = lamp_effect_summary(legacy_fe),
      cce_pooled = lamp_effect_summary(pooled),
      cce_mg = lamp_effect_summary(mg))

## ----allocation---------------------------------------------------------------
allocation <- lamp_allocation(sim, crime_lags = 1:3)
allocation$diagnostics$interpretation

## ----conversion---------------------------------------------------------------
lamp_crimes_prevented(fit, sim)

