CRIMES IN BOSTON ANALYSIS

Arya Andhika

2019-07-22

Take A Look the Data Type of “Crime in Boston” Data"

## 'data.frame':    319073 obs. of  17 variables:
##  $ INCIDENT_NUMBER    : Factor w/ 282517 levels "142052550","I010370257-00",..: 282517 282516 282515 282514 282513 282512 282511 282510 282509 282508 ...
##  $ OFFENSE_CODE       : int  619 1402 3410 3114 3114 3820 724 3301 301 3301 ...
##  $ OFFENSE_CODE_GROUP : Factor w/ 67 levels "Aggravated Assault",..: 35 64 63 33 33 44 5 65 59 65 ...
##  $ OFFENSE_DESCRIPTION: Factor w/ 244 levels "A&B HANDS, FEET, ETC.  - MED. ATTENTION REQ.",..: 130 231 223 124 124 165 22 232 207 232 ...
##  $ DISTRICT           : Factor w/ 13 levels "","A1","A15",..: 9 7 10 10 6 7 5 5 8 7 ...
##  $ REPORTING_AREA     : int  808 347 151 272 421 398 330 584 177 364 ...
##  $ SHOOTING           : Factor w/ 2 levels "","Y": 1 1 1 1 1 1 1 1 1 1 ...
##  $ OCCURRED_ON_DATE   : Factor w/ 233229 levels "2015-06-15 00:00:00",..: 232988 230467 233216 233228 233226 233227 233229 233224 233225 233222 ...
##  $ YEAR               : int  2018 2018 2018 2018 2018 2018 2018 2018 2018 2018 ...
##  $ MONTH              : int  9 8 9 9 9 9 9 9 9 9 ...
##  $ DAY_OF_WEEK        : Factor w/ 7 levels "Friday","Monday",..: 4 6 2 2 2 2 2 2 2 2 ...
##  $ HOUR               : int  13 0 19 21 21 21 21 20 20 20 ...
##  $ UCR_PART           : Factor w/ 5 levels "","Other","Part One",..: 3 5 4 4 4 4 3 4 3 4 ...
##  $ STREET             : Factor w/ 4658 levels ""," ALBANY ST ",..: 2537 2075 786 3067 1242 4075 3100 2461 2742 2505 ...
##  $ Lat                : num  42.4 42.3 42.3 42.3 42.3 ...
##  $ Long               : num  -71.1 -71.1 -71.1 -71.1 -71.1 ...
##  $ Location           : Factor w/ 18194 levels "(-1.00000000, -1.00000000)",..: 15616 6832 13472 11292 2034 4673 6752 10012 10748 5513 ...

Change the Data Type of “OFFENSE_CODE” and “REPORTING_AREA” into Factor (Repeated)

Take A Look the Summary of “Crime in Boston” Data"

##  INCIDENT_NUMBER     OFFENSE_CODE   
##  Length:319073      3006   : 18783  
##  Class :character   3115   : 18754  
##  Mode  :character   3831   : 16323  
##                     1402   : 15154  
##                     802    : 14799  
##                     3301   : 13099  
##                     (Other):222161  
##                        OFFENSE_CODE_GROUP
##  Motor Vehicle Accident Response: 37132  
##  Larceny                        : 25935  
##  Medical Assistance             : 23540  
##  Investigate Person             : 18750  
##  Other                          : 18075  
##  Drug Violation                 : 16548  
##  (Other)                        :179093  
##                             OFFENSE_DESCRIPTION    DISTRICT    
##  SICK/INJURED/MEDICAL - PERSON        : 18783   B2     :49945  
##  INVESTIGATE PERSON                   : 18754   C11    :42530  
##  M/V - LEAVING SCENE - PROPERTY DAMAGE: 16323   D4     :41915  
##  VANDALISM                            : 15154   A1     :35717  
##  ASSAULT SIMPLE - BATTERY             : 14791   B3     :35442  
##  VERBAL DISPUTE                       : 13099   C6     :23460  
##  (Other)                              :222169   (Other):90064  
##  REPORTING_AREA   SHOOTING   OCCURRED_ON_DATE                   YEAR     
##  111    :  2372    :318054   Min.   :2015-06-15 00:00:00   Min.   :2015  
##  186    :  2016   Y:  1019   1st Qu.:2016-04-12 00:43:15   1st Qu.:2016  
##  329    :  1878              Median :2017-01-28 03:11:00   Median :2017  
##  117    :  1832              Mean   :2017-01-25 11:08:33   Mean   :2017  
##  143    :  1775              3rd Qu.:2017-11-05 18:14:00   3rd Qu.:2017  
##  (Other):288950              Max.   :2018-09-03 21:25:00   Max.   :2018  
##  NA's   : 20250              NA's   :3                                   
##      MONTH          DAY_OF_WEEK         HOUR             UCR_PART     
##  Min.   : 1.00   Friday   :48495   Min.   : 0.00             :    90  
##  1st Qu.: 4.00   Monday   :45679   1st Qu.: 9.00   Other     :  1232  
##  Median : 7.00   Saturday :44818   Median :14.00   Part One  : 61629  
##  Mean   : 6.61   Sunday   :40313   Mean   :13.12   Part Three:158553  
##  3rd Qu.: 9.00   Thursday :46656   3rd Qu.:18.00   Part Two  : 97569  
##  Max.   :12.00   Tuesday  :46383   Max.   :23.00                      
##                  Wednesday:46729                                      
##             STREET            Lat             Long       
##  WASHINGTON ST : 14194   Min.   :-1.00   Min.   :-71.18  
##                : 10871   1st Qu.:42.30   1st Qu.:-71.10  
##  BLUE HILL AVE :  7794   Median :42.33   Median :-71.08  
##  BOYLSTON ST   :  7221   Mean   :42.21   Mean   :-70.91  
##  DORCHESTER AVE:  5149   3rd Qu.:42.35   3rd Qu.:-71.06  
##  TREMONT ST    :  4796   Max.   :42.40   Max.   : -1.00  
##  (Other)       :269048   NA's   :19999   NA's   :19999   
##                         Location     
##  (0.00000000, 0.00000000)   : 19999  
##  (42.34862382, -71.08277637):  1243  
##  (42.36183857, -71.05976489):  1208  
##  (42.28482577, -71.09137369):  1121  
##  (42.32866284, -71.08563401):  1042  
##  (42.25621592, -71.12401947):   898  
##  (Other)                    :293562

Replace Missing Values in “SHOOTING” with “N”

Remove unused levels

##Simple Exploratory Data Analysis

Take a glimpse look at Crime Boston Data to find pattern or interesting findings

Correlation between Day of Week and the Time when Crimes Occur

On the weekday, Crimes in Boston happen during the same period. But interesting thing happen at weekend, there is some shifting of time occured, from 6AM-12PM into 12AM to 6AM.

Take a look the most occured Offense Type, let’s say they occur more than 10k Cases

##                       OFFENSE_TYPE  Freq
## 44 Motor Vehicle Accident Response 30350
## 35                         Larceny 25032
## 41              Medical Assistance 22326
## 31              Investigate Person 17958
## 47                           Other 17009
## 62                  Simple Assault 14829
## 64                       Vandalism 14826
## 16                  Drug Violation 14371
## 65                 Verbal Disputes 12942
## 63                           Towed 10712
## 33            Investigate Property 10566
## 36      Larceny From Motor Vehicle 10226

We would like to take out Other since it may consists of few Offense Types

Location Analysis