San Francisco: Trends in Criminal Activity

Brenna Botzheim
Posted on Oct 30, 2019

Introduction

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.

Data

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.

Analysis

Location

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.

Time

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.

Comparing Incidents

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.

Summary

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.

About Author

Brenna Botzheim

Brenna Botzheim

Brenna Botzheim is an associate EOV Analyst at StormGeo. Brenna holds a Bachelors degree from San Francisco State University where she studied sociology and mathematics. In her spare time, Brenna continues to develop her skills in statistical data...
View all posts by Brenna Botzheim >

Leave a Comment

No comments found.

View Posts by Categories


Our Recent Popular Posts


View Posts by Tags

#python #trainwithnycdsa 2019 airbnb Alex Baransky alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus API Application artist aws beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Best Data Science Bootcamp 2020 Best Ranked Big Data Book Launch Book-Signing bootcamp Bootcamp Alumni Bootcamp Prep Bundles California Cancer Research capstone Career Career Day citibike clustering Coding Course Demo Course Report D3.js data Data Analyst data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization Deep Learning Demo Day Discount dplyr employer networking feature engineering Finance Financial Data Science Flask gbm Get Hired ggplot2 googleVis Hadoop higgs boson Hiring hiring partner events Hiring Partners Industry Experts Instructor Blog Instructor Interview Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter lasso regression Lead Data Scienctist Lead Data Scientist leaflet linear regression Logistic Regression machine learning Maps matplotlib Medical Research Meet the team meetup Networking neural network Neural networks New Courses nlp NYC NYC Data Science nyc data science academy NYC Open Data NYCDSA NYCDSA Alumni Online Online Bootcamp Online Training Open Data painter pandas Part-time Portfolio Development prediction Prework Programming PwC python python machine learning python scrapy python web scraping python webscraping Python Workshop R R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest Ranking recommendation recommendation system regression Remote remote data science bootcamp Scrapy scrapy visualization seaborn Selenium sentiment analysis Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau team TensorFlow Testimonial tf-idf Top Data Science Bootcamp twitter visualization web scraping Weekend Course What to expect word cloud word2vec XGBoost yelp