Project Introduction
One of the biggest challenges individuals face is tackling the problem of crime. While a plethora of measures have been put in place to address this issue, crime rates continue to rise and run rampant throughout major cities. As such, many individuals want to know whether or not there is a relationship between cities with a population of around 250k or greater and their total crime rates.
Problem Statement
Does the relationship between cities with a population of around 250k or greater have an effect on the total crime rates? We want to solve this problem because we are curious whether or not there is a correlation between highly populated cities and the amount of crime they receive. As a result, we want to find out if that is due to the population amount or rather a different motivator.
Project Objective
Our objectives are to find out whether cities throughout the United States with a population of around 250k or greater experience large rates of total crime and what other causes could possibly contribute to the increasing crime rates. In addition, our goal is to create a model that represents crime in high population areas.
Descriptive Statistics and Visual Analysis
Load the packages
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.3
library(readxl)
library(ggpubr)
## Warning: package 'ggpubr' was built under R version 4.3.3
library(gclus)
## Warning: package 'gclus' was built under R version 4.3.3
## Loading required package: cluster
theme_set(theme_pubr())
Load and Clean the Data
crime_data <- read.csv("crime_250_plus.csv")
crime_data <- na.omit(crime_data) # data cleaning
summary(crime_data)
## states cities population total_crime
## Length:96 Length:96 Min. : 216350 Min. :1381
## Class :character Class :character 1st Qu.: 265622 1st Qu.:2964
## Mode :character Mode :character Median : 394230 Median :4216
## Mean : 668221 Mean :4333
## 3rd Qu.: 676932 3rd Qu.:5473
## Max. :8804190 Max. :8735
## tot_violent_crime tot_prop_crim
## Min. : 61.21 Min. :1316
## 1st Qu.: 415.58 1st Qu.:2474
## Median : 649.07 Median :3546
## Mean : 726.72 Mean :3583
## 3rd Qu.: 947.87 3rd Qu.:4443
## Max. :2082.29 Max. :7366
Linear Regression for Population vs. Total Crime
lmtotal_crime = lm(population~total_crime, data = crime_data)
summary(lmtotal_crime)
##
## Call:
## lm(formula = population ~ total_crime, data = crime_data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -598962 -413312 -248697 71280 8010065
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 900810.93 282095.45 3.193 0.00191 **
## total_crime -53.68 60.62 -0.885 0.37816
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1008000 on 94 degrees of freedom
## Multiple R-squared: 0.008272, Adjusted R-squared: -0.002278
## F-statistic: 0.7841 on 1 and 94 DF, p-value: 0.3782
Population vs. Total Crime Graph
graph_total_crime <- ggplot() +
geom_point(data = crime_data, aes(x = population, y = total_crime), color = "black") +
geom_smooth(method = "lm", se=FALSE, aes(x = crime_data$population, y = crime_data$total_crime), color = "turquoise4") +
labs(x = "Population", y = "Total Crime Rates", title = "Population vs Total Crime Rate")
graph_total_crime
## `geom_smooth()` using formula = 'y ~ x'

Interpretation: There is no clear correlation. The dataset contains these outliers:
NYC (pop. = 8.8m)
LA (pop. = 3.9m)
Chicago (pop. = 2.7m)
Houston (pop. = 2.3m)
The graph is skewed to the right
Correlation
New Data Set
crime_df = subset(crime_data, select = c(population,total_crime))
crime_df
## population total_crime
## 1 248431 6217.02
## 2 296188 6640.04
## 3 249355 2589.08
## 4 242090 1483.75
## 5 249273 5037.85
## 6 492268 2592.49
## 7 1608139 4443.20
## 8 251840 2338.38
## 9 1532323 6082.78
## 10 353400 2997.74
## 11 381154 4618.34
## 12 271109 1738.79
## 13 236368 2343.80
## 14 526371 4447.63
## 15 276115 1381.31
## 16 471397 3357.25
## 17 3898747 3332.52
## 18 424915 7328.29
## 19 328023 3589.38
## 20 499997 3654.02
## 21 217259 5189.66
## 22 1386932 2220.67
## 23 881255 6917.40
## 24 1013240 2861.02
## 25 335699 2596.67
## 26 216350 1592.79
## 27 309566 5109.09
## 28 368018 3630.53
## 29 472958 3765.25
## 30 706616 4360.93
## 31 693972 5104.96
## 32 238260 2422.14
## 33 894638 4168.73
## 34 463009 4750.89
## 35 283982 6206.38
## 36 263712 5029.35
## 37 384360 2218.24
## 38 481343 5727.52
## 39 242941 3901.36
## 40 990384 3053.77
## 41 225677 2741.97
## 42 2746388 4381.65
## 43 266259 3572.46
## 44 870788 5775.23
## 45 217277 5102.70
## 46 391084 6583.50
## 47 322332 4145.73
## 48 684362 4769.99
## 49 227403 6693.84
## 50 397447 5375.57
## 51 613217 6997.68
## 52 682903 2758.22
## 53 670792 6726.82
## 54 418971 5768.18
## 55 306696 4262.86
## 56 484948 6309.55
## 57 310284 8188.31
## 58 449388 4527.49
## 59 299285 2025.17
## 60 627244 3567.87
## 61 242537 3405.26
## 62 248531 3766.53
## 63 267906 2330.67
## 64 283673 3316.84
## 65 561375 8734.98
## 66 256169 4930.34
## 67 8804190 1987.49
## 71 309317 5997.00
## 72 372624 6538.45
## 73 905748 4501.80
## 75 648260 4552.50
## 76 404868 6532.01
## 77 649408 6239.99
## 78 1603797 4037.27
## 79 305932 3815.23
## 80 652765 8357.07
## 81 674942 4966.50
## 82 397377 3721.91
## 83 971949 3612.23
## 84 329256 4285.11
## 85 1304379 3985.95
## 86 688667 2203.25
## 87 873069 3792.83
## 88 236243 3355.44
## 89 2304580 5252.08
## 90 242062 2775.73
## 91 260669 2832.71
## 92 290413 1892.14
## 93 1434625 5565.95
## 94 240119 2699.50
## 95 245190 4308.09
## 96 454353 2083.40
## 97 721365 5911.99
## 98 217066 7881.01
## 99 255850 3040.46
## 100 595168 5441.99
Correlation
corr <- cor(crime_df)
corr
## population total_crime
## population 1.00000000 -0.09095179
## total_crime -0.09095179 1.00000000
Building the Regression Model
model <- lm(total_crime ~ population, data = crime_df)
summary(model)
##
## Call:
## lm(formula = total_crime ~ population, data = crime_df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3012.1 -1363.0 -127.6 1216.2 4385.5
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.436e+03 2.095e+02 21.171 <2e-16 ***
## population -1.541e-04 1.740e-04 -0.885 0.378
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1708 on 94 degrees of freedom
## Multiple R-squared: 0.008272, Adjusted R-squared: -0.002278
## F-statistic: 0.7841 on 1 and 94 DF, p-value: 0.3782
Testing the Assumptions
Testing if Residuals Are Normally Distributed
plot(model, 2) #Q-Q residuals

We can assume residuals are normally distributed because all the points fall approximately on the line.
Testing for Measurement Error in the Independent Variable
plot(model, 1) #Residuals vs Fitted

Because there does not seem to be a pattern in the residual plot, we can assume there is no measurement error in the independent variable.
Testing Whether the Relationship Between the Independent and
Dependent Variables is Linear
corr
## population total_crime
## population 1.00000000 -0.09095179
## total_crime -0.09095179 1.00000000
Because r = -0.091, we can assume that there is a linear relationship.
Estimated Regression Equation
summary(model)
##
## Call:
## lm(formula = total_crime ~ population, data = crime_df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3012.1 -1363.0 -127.6 1216.2 4385.5
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.436e+03 2.095e+02 21.171 <2e-16 ***
## population -1.541e-04 1.740e-04 -0.885 0.378
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1708 on 94 degrees of freedom
## Multiple R-squared: 0.008272, Adjusted R-squared: -0.002278
## F-statistic: 0.7841 on 1 and 94 DF, p-value: 0.3782
Regression Equation: Total Crime = b0 + b1*population
Regression Equation: ŷ = 4435.972 - 0.0002*x
Where:
ŷ = Total Crime Rate
b0 = Intercept, 4435.972
b1 = -0.0002
x = Population
Results
summary(model)
##
## Call:
## lm(formula = total_crime ~ population, data = crime_df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3012.1 -1363.0 -127.6 1216.2 4385.5
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.436e+03 2.095e+02 21.171 <2e-16 ***
## population -1.541e-04 1.740e-04 -0.885 0.378
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1708 on 94 degrees of freedom
## Multiple R-squared: 0.008272, Adjusted R-squared: -0.002278
## F-statistic: 0.7841 on 1 and 94 DF, p-value: 0.3782
Coefficient Interpretation
b0 = 4435.972
The average total crime rate in cities with a population of 250,000
b1 = -0.0002
The average total crime rate in cities with a population of 250k or greater is expected to decrease by -0.0002 for each additional person
Interpretation and Conclusion
summary(model)
##
## Call:
## lm(formula = total_crime ~ population, data = crime_df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3012.1 -1363.0 -127.6 1216.2 4385.5
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.436e+03 2.095e+02 21.171 <2e-16 ***
## population -1.541e-04 1.740e-04 -0.885 0.378
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1708 on 94 degrees of freedom
## Multiple R-squared: 0.008272, Adjusted R-squared: -0.002278
## F-statistic: 0.7841 on 1 and 94 DF, p-value: 0.3782
Interpretation
With r² = 0.0083 or 0.83%, we can state that the regression relationship is very weak. The dataset contains 0.83% of variability in total crime rate, meaning little to no correlation can be found between cities with a population of 250k or greater and total crime rate
Conclusion
Because the p-value = 0.38 and is greater than alpha = 0.05, we can conclude that there is not enough statistical evidence to claim a correlation between cities with a population of around 250k or greater and total crime rates. The model is not significant.
Recommendations
While there is no clear correlation between population sizes of around 250k or greater and total crime rate, there should still be enhanced security measures put in place by local governments to tackle crime in highly populated areas in order to provide communities with an increased sense of safety and security.
Law enforcement should use data visualization software to create a crime mapping program that provides insight into the specific crime type and its patterns within various cities throughout the United States.
For populations in the millions, we should invest more in community policy initiatives and standardized crime prevention programs in order to reduce crime rates, foster positive living environments, and promote happy residents.