Criminal in San Francisco: Data Trends in Criminal Activity
The skills the author demoed here can be learned through taking Data Science with Machine Learning bootcamp with NYC Data Science Academy.
Data shows crime is a pervasive issue in the United States. In Donald Trump's tenure in office, he has taken an aggressive stance towards crime, ordering Federal Judges to pursue the harshest possible punishments. The policy aims to be 'tough on crime' so as to decrease crime rates in the US. But since we can't curb crime altogether, we had better be able to prepare for it.
Investigating how criminal activity varies is an excellent start to understanding what causes it and how to respond to it. However, criminal activity is different by region, and it pays to look at crime statistics around you rather than just the country as a whole. I live in the San Francisco Bay area and I wanted to investigate the make up of crime in San Francisco by variables like type of incidents, time, and location.
Crime statistics have a variety of uses in different organizations: The San Francisco city government can use the data to investigate trends in crime by location and time. With this data, the city of SF could make informed decisions about future changes in SFPD routes, schedules, and big picture plans to reduce crime. Companies can use them when deciding where to place a new office or when to schedule deliveries.
At a micro level, an individual intending to purchase a home can investigate the criminal activity near potential homes and incorporate that into their decision making. Alternatively, a curious current citizen in SF like myself could see what neighborhoods have the highest level of criminal activity or what time of day incurs the most crime.
However, data alone is hard to glean information from. R Shiny provides clean, easy to use functionality that I harnessed to create an app that is intuitive for users of any background. The goal of the app is to provide dynamic visualizations to help describe the underlying data on criminal activity in SF. It filters the data by time, location, and type of incident and creates dynamic graphical displays of the data to easily observe trends. In the following I will show some examples of what the app can do and key insights that it has provided about SF crime reports.
The data used in this project comes from SF Open Data, a transparency initiative introduced in San Francisco in 2009 to promote innovation by making data that is collected and maintained by the city, publicly available. Data collected by the government is a great source of insights into many topics, including public health, the economy, transportation, and criminal activity.
The data itself consists of all incident reports filed by the SF police department as well as "by individuals through self-service online reporting for non-emergency cases" dating back to January 1st, 2018 (when SF made changes to it's reporting structure). As such, the incidents include both criminal activity and non-criminal incidents.
NOTE: Criminal activity and the relative safety of neighborhoods is not simply a geographical issue. There are more complicated processes working behind the scenes that create geospatial distinctions in crime rates. For example, poorer neighborhoods tend to have higher crime, which sounds intuitive: if someone is having trouble putting food on the table for their family, they are more likely to resort to criminal means to do so.
But the issue goes deeper: schools in poorer neighborhoods tend to have less funding, higher drop out rates, and less experienced instructors, creating what has been termed the "school to prison pipeline." The goal of this project was not to investigate these structural processes, but it is important to note that they exist and should be considered in any informed decisions on this topic.
The below maps show arson incidents and juvenile offenses clustered into groups. The first incident, arson, shows the more common dispersion of incident reports in San Francisco, with the highest concentration in downtown SF (Along market street and in the Tenderloin and Mission districts) and a lower concentration of reports in other areas of the city. Notably, juvenile offenses have almost an opposite dispersion, with an abnormally high concentration in the Taraval district.
A little investigatory google search revealed that the area where those incidents occurred was at the Edgewood Center for Children and Families, a nonprofit organization that provides behavioral health services to the community, with its focus mainly on providing services for children. Knowing that potentially troubled children are brought to this location for help better explains this phenomenon.
Next, we can see below that filtering for drug offenses reveals that the Tenderloin district accounts for far more incidents than the other districts (even though it is geographically the smallest). The Tenderloin is notorious for it's nightlife and seedy characteristics, however I did not expect to find such high reports of drug offenses in this part of the city. In the Park district, there is a well known street intersection (Haight-Ashbury) known for it's hippie culture and promotion of drug use, but the Park district does not even rank among the top three in the below graph.
It is true that Haight-Ashbury's reputation for hippie culture now predominantly exists historically. The area remains active and bustling, but by now more commonly with tourists visiting shops that profit from the area's reputation. Thus, perhaps it is not so surprising that Haight-Ashbury does not incur as much drug-related criminal activity as other districts.
Below is a graph of all incident reports by day of the week. Overall, we can see that criminal activity is the highest on Fridays and lowest on Sundays. This seems pretty intuitive, given that people tend to go out on Fridays and stay home on Sundays. In general though the differences are rather small by day.
Next, let's take a look at an incident that doesn't follow the overall pattern:
Here we see that robberies are the most common on Sundays. This graph is almost the opposite of what we found the overall trend to be. Robberies are mainly defined as theft of a victim by force. In comparison, burglaries refer to theft while trespassing on a property. The below graph shows the amount of burglaries by day of the week:
The burglary graph is approximately the inverse of the robbery graph. This is a rather striking difference and would be an area for further investigation to determine what causes these differences.
In the next graph we can see that overall, incidents are most likely to occur in the middle of the day or in the evening.
Below, when we filter by liquor law violations we see that much fewer incidents occur during the morning, and much more occur at night. Further investigation within the Shiny app shows that weekends are also much more common for liquor law violations.
This is pretty intuitive given that most people go out drinking in the evenings on weekends. On the other hand, if you sort by civil sidewalk complaints, far more occur during the morning (presumably as people head off to work), and so few occur at night we can't even see it in the graph.
Lastly, let's take a look at a time line of incident reports of burglaries. The below image shows the daily frequency of burglary reports over approximately 2 years. Though it varies, there seems to a general trend towards fewer daily burglary reports over time. This is an interesting find that requires a more vigorous analysis to test if a significant downward trend exists.
An alternative explanation could be that police officers have begun using the "burglary" incident category less frequently, instead opting to categorize an incident as "larceny theft". The main difference between these two categories is that burglaries refer to theft from buildings, while larceny theft refers to theft from vehicles. However, a portion of theft from buildings are categorized under larceny theft. (This information can be investigated under the data tab within the app, where it shows sub-categories and incident descriptions.) Below is the same graph for "larceny theft" :
In the above we do see an increase in larceny theft reports around the same time that the decrease in burglary incidents occur.
The shiny app I created also offers a tab for directly comparing incidents. In the below graph we can see the reports of motor vehicle theft compared with reports of recovered vehicles by neighborhood. The first thing that stands out is that vehicles are more commonly recovered outside of San Francisco. Additionally, most neighborhoods report more vehicle thefts than vehicles recovered, with the exception of the Tenderloin district. Here we see relatively few vehicle thefts reported, and more vehicles recovered.
Investigating how criminal activity varies provides valuable insights for the government, for companies, and for individuals to make informed decisions. Experienced police officers may have a good sense about what parts of the city experience higher crime, but having the data to back up that intuition can make the difference between implementing a useful change or an unneeded change.
Many more interesting observations can be made using the app, which can be found here: https://bbotzheim.shinyapps.io/SF_incident_reports/
It is my goal to further develop this app by adding San Francisco's historical data prior to 2018 when changes were made to the reporting structure. This data dates all the way back to 2003 and could be provide more trends over time.
Further developing the functionality in the app, such as being able to pick and choose multiple incidents, or filter by day of week and time of day could also provide useful insights.