Step 1: Install and load required libraries
Load the packages
library(ggplot2)
library(readxl)
library(ggpubr)
library(gclus)
## Loading required package: cluster
theme_set(theme_pubr())
Load data
crime_data <- read.csv("crime_250_plus.csv")
Clean the data
crime_data <- na.omit(crime_data)
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
Step 2: 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