Wednesday, May 25, 2011

Chicago Crime

As a former resident of Chicago I was curious to how much crime happened in the period between  Feb. 18, 2011 and May 15, 2011 and where crimes occurred.  Of course this analysis could be done on EveryBlock, but that is just too easy.  I wanted to do it in Mathematica, incase I want to do any type of advanced analysis later.

The GIS information for the city of Chicago can be found here.  The data must then be unzipped and converted to an XML format, which can be done with shp2text.  The data that is necessary to for this analysis is provided in the downloadable zip file found below.

The first step to the analysis is to extract the GIS data of the city.  To extract the x and y coordinates that make up the polygons of the city of Chicago, the following command was used:


The data used here were of Chicago Police Distracts and historic neighborhoods of Chicago.

The next step was to access the EveryBlock API and gather the crime data.  The API is free to access, you only need to register for a key to use it.  A quirky characteristic about this API is the limited data that is provided.  In the request command I have requested all crimes from January 1st, 2010 but the API will only provide crimes uploaded from the last 24 hours from EveryBlock.  The command to access and isolate the crime data is:


The odd thing about this project is the coordinate disparity.  The Chicago GIS data is provided in a NAD83 transformation rather than just latitudes and longitudes.  This transformation gives x and y coordinates in units of feet rather than degrees and minutes.  To convert the latitude and longitude data gathered from the EveryBlock API this Mathematica command was used:


Now let's get to some pretty pictures and results.  For the period between Feb. 18th, 2011 to May 15th, 2011, the crime distribution in Chicago looked like this:


A count of crime incidents can be performed since we are doing this in Mathematica.  The number of crime incidents in each neighborhood are listed in the table below:


The same analysis can be done with Chicago Police Districts.  CPD publishes monthly crime statistics for each district, I have compiled this information for the month of January 2011 to add a bit more color to the crime map.  In the crime map below, more red the color the higher the incidents of crime in the district.


And the accompanying crime incidents for each district is:


The datafiles used in this blog is provided here.