Skip to content

This repository includes the code and data utilized for research to analyze associations between incidents of reported firearms violence and the distance to built environment features, accounting for neighborhood socio-economic status. The code leverages street networks to compare reported crime data with the outputs from a Monte Carlo Simulatio…

Notifications You must be signed in to change notification settings

RANDCorporation/Quantifying-Built-Environment-Influence

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quantifying the Attractive and Repellent Influence of Built Environment on Firearms Violence

This is a guide for use of the code created for the manuscript "Accounting for Socio-economic Context in Quantifying the Attractive and Repellent Influence of Built Environment on Firearms Violence in Multiple Cities", which appears in The Journal of Quantitative Criminology.

Principal Investigators:

Principal Programmers:

Data Sources for Street Network and Embedded Built Environment & Firearms Incident Locations

Street Network

Built Environment & Firearms Data

Setup required

Use package_versions.txt as a reference for the package versions we used. One should create a virtual python environment, and in the desired command line, source activate the environment file with the command, with virtualenv standing in from the file name:

source activate <virtualenv>

Code Flow

Figure 1 Workflow of code

Building the networks

  • The add_points_to_networks.py script requires the build environment, as well as raw crime data, both in .csv formats, to output a citywide network in a pickle file.

Usage

Analyzing the networks

  • The est_obs_parallel.py script requires the city network, to generate:

    • The shot counts plots, in the format {‘city name’}_shot_counts.pdf

    • The observed portion of cross-k plots, in the format {‘city name’}_shot_counts.pdf

    • The piecewise regression plots, in the format {‘city name’}

    • The observed distance matrices, in the format {‘city name’}_distances_observed.csv

    • The observed shot count values, in the format {‘city name’}_shot_counts_observed.csv

    • The observed cross k values, in the format {‘city name’}_cross_k_observed.csv

  • The run_obs file is a bash script that deploys est_obs_parallel in a parallel fashion, taking the city name or prefix as input. Note that est_obs_parallel can be run locally, but this architecture allowed us to leverage multiple cores on a Parallel-GNU enabled Linux machine. The syntax is flexible, and one can choose the unit of parallelization.

  • For the four cities, with prefixes LA, DET, PGH, NOLA, the syntax is:

parallel 'python est_obs_parallel.py {1}'  ::: "la" "det" "pgh" "nola"

Figure 2 Examples of output piecewise regression plot of Firearms Incident Density (left) and regression results (right)

Running the simulations

  • The sim_run_parallel_read.py file takes as inputs: feature name, iterations, distance range, buffer, ses bounds, breakpoint sensitivity, and a boolean to plot or save results.

Some sample inputs:

  • features = [‘Convenience Store’] iterations = 10
  • distancerange = 1000
  • buffer = 300
  • ses_lowerbound = 0.0
  • ses_upperbound = 5.0
  • breakpoint_sensitivity = 5 save = True
  • plots = True

The script outputs cross-k simulated results in the format:

{city name}_{feature name} _{scenario id}_cross_k_simulated_results.csv.

The run_sim_final file is a bash script that deploys sim_run_parallel_read in a parallel fashion, taking the simulation pickle file as well as the inputs above as input. Like run_obs, this file is designed to run on a Parallel-GNU enabled Linux machine. The syntax is flexible, and one can choose the unit parallelization.

An example of the syntax is:

parallel 'python sim_run_parallel_read.py "Public pool" 5 1000 300 0 5 5 True'

The call above would call the scenario files 1-10, for the Public Pool feature, with 5 iterations, 1000 ft distance range, 300ft buffer, breakpoint sensitivity of 5, and the saving and plotting options activated.

Comparing the simulations to observed

The consolidate.py script takes as input:

  • the cross-k results from the simulated networks and the cross-k results from the observed city networks

and outputs:

  • the overlapping plots, named in the format: {city name}_{feature name}_cross_k_observed_v_simulated.pdf

Figure 3 Example output from consolidate.py for Transit Stations. This image illustrates that observed firearms incidents (Black line) is greater than simulated (Blue band)

Visualization

Features

The file feature_viz takes as input a city name, and iterates through the list of features, to plot the degree to which a feature fits into the categories of Attractor, Neutral and Repellant over distance.

The output is a png plot named with the convention: {city name}_degreeviz.png

Figure 4 Example output from feature_viz for features in Pittsburgh. This image quantifies the difference between the observed Cross-K function values and the mean of simulated Cross-K function values. If the difference is positive, the feature is attractive.

SES

The file ses_viz takes as inputs the city name and SES thresholds, to define High SES and Low SES and plots, for each feature, histograms of counts within each category and overall.

The output plots are named with the convention: {city name}_feature name_hist.png

Figure 5 Example output from ses_viz for Liquor Licenses in Detroit. This image illustrates the number of features that are located in different percentiles of socio-economic status.

Auxiliary

The co_location file takes as inputs the name of a city, and 2 features, to calculate the observed distances between each combination of instances of the 2 features in a city.

Feedback

Code critique is welcome. Please send an email to lmuggy@rand.org.

Copyright (©) 2022 The RAND Corporation

About

This repository includes the code and data utilized for research to analyze associations between incidents of reported firearms violence and the distance to built environment features, accounting for neighborhood socio-economic status. The code leverages street networks to compare reported crime data with the outputs from a Monte Carlo Simulatio…

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published