Our dataset

library(readxl)
dataset <- read_excel("C:\\College Stuff\\Project dataset3.xls")
df2 <- read_excel("C:\\College Stuff\\police_blotter_data2.xlsx")
print(dataset)
## # A tibble: 39 × 6
##    Neighborhood Mean Incidents repor…¹ `Average rent ($)` Distance to Campus (…²
##    <chr>                         <dbl>              <dbl>                  <dbl>
##  1 Central Bus…                  300.                1966                    3.3
##  2 Bluff                          56.2               1840                    2.2
##  3 Strip Distr…                   45.6               1961                    3.7
##  4 Crawford-Ro…                   57                 1840                    2.3
##  5 Bedford Dwe…                   25                 1840                    2  
##  6 Middle Hill                    36.4               1840                    2.1
##  7 Terrace Vil…                   15                 1786                    1.1
##  8 North Oakla…                   42.2               1751                    0.4
##  9 West Oakland                   22.6               1786                    0.8
## 10 Central Oak…                   37.8               1751                    0.5
## # ℹ 29 more rows
## # ℹ abbreviated names: ¹​`Mean Incidents reported`,
## #   ²​`Distance to Campus (Miles)`
## # ℹ 2 more variables: `Rentable Property` <dbl>, Population <dbl>

Elizabeth O’Connell Code

#df2 <- police_blotter_data2
print(df2)
## # A tibble: 39 × 8
##    Neighborhood         Population `9/23-10/23` August  July  June   May Average
##    <chr>                     <dbl>        <dbl>  <dbl> <dbl> <dbl> <dbl>   <dbl>
##  1 Central Business Ce…       5477          307    261   307   327   299   300. 
##  2 East Liberty               6187          105     76    94    83   102    92  
##  3 Shadyside                 15317           87     71    80    88    92    83.6
##  4 Squirrel Hill South       15317           60     64    70    77   103    74.8
##  5 Lincoln-Lemington-B…       3636           68     66    65    69    67    67  
##  6 Bloomfield                 8665           82     60    60    67    56    65  
##  7 Homewood South             2260           63     53    76    52    65    61.8
##  8 Crawford-Roberts           2293           69     45    65    49    57    57  
##  9 Homewood North             2617           69     56    55    57    45    56.4
## 10 Bluff                      5882           66     62    53    44    56    56.2
## # ℹ 29 more rows
par(mar=c(11,3.6,1,0))
barplot(df2$Average, main="Reported Crime Incidents", ylab="Mean Number of Reported Crime Incidents", names.arg = df2$Neighborhood, las=2, cex.lab=0.7, cex.axis=0.8)

df3 <- df2
rate <- df3$Average/df3$Population
par(mar=c(11,3.6,1,0))
barplot(rate, main="Crime Rate", ylab="Rate of Reported Crime Incidents",names.arg = df3$Neighborhood, las=2, cex.lab=0.7, cex.axis = 0.5)

data = matrix(c(df3$Neighborhood, rate), ncol=2)
colnames(data) <- c('Neighborhood', 'Crime Rate')
rownames(data) <- c(1:39)
data = as.table(data)
data
##    Neighborhood             Crime Rate         
## 1  Central Business Center  0.0548110279350009 
## 2  East Liberty             0.0148698884758364 
## 3  Shadyside                0.00545798785662989
## 4  Squirrel Hill South      0.0048834628190899 
## 5  Lincoln-Lemington-Belmar 0.0184268426842684 
## 6  Bloomfield               0.00750144258511252
## 7  Homewood South           0.0273451327433628 
## 8  Crawford-Roberts         0.0248582642825992 
## 9  Homewood North           0.0215513947267864 
## 10 Bluff                    0.00955457327439646
## 11 Hazelwood                0.0139367446644382 
## 12 Strip District           0.0247154471544715 
## 13 North Oakland            0.00394724534655318
## 14 East Hills               0.0144536652835408 
## 15 Highland Park            0.00635124298315958
## 16 Central Oakland          0.00647814910025707
## 17 Squirrel Hill North      0.00313157673204815
## 18 Middle Hill              0.0207171314741036 
## 19 Greenfield               0.00490290593582151
## 20 Garfield                 0.00883886906395828
## 21 Larimer                  0.0207119741100324 
## 22 Central Lawrencevilla    0.00614406779661017
## 23 Point Breeze North       0.0126760563380282 
## 24 Bedford Dwellings        0.018037518037518  
## 25 South Oakland            0.00750976269149895
## 26 Lower Lawrenceville      0.00923892464975388
## 27 West Oakland             0.00891870560378848
## 28 Point Breeze             0.0037397157816006 
## 29 Homewood West            0.0264797507788162 
## 30 Upper Lawrenceville      0.00693400167084378
## 31 Upper Hill               0.00917005223447475
## 32 Terrace Village          0.00646551724137931
## 33 Stanton Heights          0.00316241246894059
## 34 Friendship               0.00682628629648497
## 35 Morningside              0.00362853628536285
## 36 Polish Hill              0.00766028309741882
## 37 Glen Hazel               0.00940819423368741
## 38 Regent Square            0.00494335736354274
## 39 Swisshelm Park           0.00298730395817774
df4 <- dataset
model3 <- lm(df4$'Average rent ($)'~df4$'Distance to Campus (Miles)')
summary(model3)
## 
## Call:
## lm(formula = df4$"Average rent ($)" ~ df4$"Distance to Campus (Miles)")
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -595.8 -198.9    6.2  243.4  441.3 
## 
## Coefficients:
##                                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                       1916.94     118.21  16.216   <2e-16 ***
## df4$"Distance to Campus (Miles)"   -68.75      39.39  -1.746   0.0892 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 296.4 on 37 degrees of freedom
## Multiple R-squared:  0.07608,    Adjusted R-squared:  0.05111 
## F-statistic: 3.047 on 1 and 37 DF,  p-value: 0.08919
plot(df4$'Distance to Campus (Miles)',df4$'Average rent ($)', main="Linear Regression of Distance vs Average Rent", xlab="Distance to Campus (miles)", ylab="Average Rent ($)")
lines(df4$'Distance to Campus (Miles)', predict(model3))

df6 <- dataset
model6 <- lm(df6$'Mean Incidents reported'~df6$'Distance to Campus (Miles)')
plot(df6$`Distance to Campus (Miles)`, df6$`Mean Incidents reported`, main="Linear Regression of Distance vs Average Rent", xlab="Distance to Campus (miles)", ylab="Average Rent ($)")
lines(df6$`Distance to Campus (Miles)`, predict(model6))

summary(model6)
## 
## Call:
## lm(formula = df6$"Mean Incidents reported" ~ df6$"Distance to Campus (Miles)")
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -39.520 -25.553  -9.884  12.661 257.594 
## 
## Coefficients:
##                                  Estimate Std. Error t value Pr(>|t|)  
## (Intercept)                       40.4522    19.3619   2.089   0.0436 *
## df6$"Distance to Campus (Miles)"   0.6527     6.4514   0.101   0.9200  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 48.54 on 37 degrees of freedom
## Multiple R-squared:  0.0002765,  Adjusted R-squared:  -0.02674 
## F-statistic: 0.01023 on 1 and 37 DF,  p-value: 0.92
df7 <- df6[-c(1),]
model7 <- lm(df7$'Mean Incidents reported'~df7$'Distance to Campus (Miles)')
plot(df7$`Distance to Campus (Miles)`, df7$`Mean Incidents reported`, main="Linear Regression of Distance vs Average Rent", xlab="Distance to Campus (miles)", ylab="Average Rent ($)")
lines(df7$`Distance to Campus (Miles)`, predict(model7))

summary(model7)
## 
## Call:
## lm(formula = df7$"Mean Incidents reported" ~ df7$"Distance to Campus (Miles)")
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -28.40 -17.52  -2.94  17.01  56.09 
## 
## Coefficients:
##                                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                        40.751      9.093   4.482 7.24e-05 ***
## df7$"Distance to Campus (Miles)"   -1.936      3.038  -0.637    0.528    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 22.8 on 36 degrees of freedom
## Multiple R-squared:  0.01115,    Adjusted R-squared:  -0.01632 
## F-statistic: 0.406 on 1 and 36 DF,  p-value: 0.5281

Zachery Lehning Code

library(readxl)
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.2
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.3.2
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(broom)
## Warning: package 'broom' was built under R version 4.3.2
library(ggpubr)
## Warning: package 'ggpubr' was built under R version 4.3.2
ds <- dataset
summary(ds)
##  Neighborhood       Mean Incidents reported Average rent ($)
##  Length:39          Min.   :  4.00          Min.   :1020    
##  Class :character   1st Qu.: 16.80          1st Qu.:1565    
##  Mode  :character   Median : 32.20          Median :1793    
##                     Mean   : 42.25          Mean   :1728    
##                     3rd Qu.: 55.20          3rd Qu.:1930    
##                     Max.   :300.20          Max.   :2066    
##  Distance to Campus (Miles) Rentable Property   Population   
##  Min.   :0.400              Min.   :  41      Min.   :  642  
##  1st Qu.:2.050              1st Qu.: 410      1st Qu.: 1904  
##  Median :2.600              Median : 819      Median : 2892  
##  Mean   :2.749              Mean   :1162      Mean   : 4307  
##  3rd Qu.:3.750              3rd Qu.:1409      3rd Qu.: 5656  
##  Max.   :5.200              Max.   :6070      Max.   :15317
plot(x=ds$'Distance to Campus (Miles)', y=ds$'Rentable Property', main="Distance vs. Properties", xlab="Distance", ylab="Properties")

model <- lm(ds$'Distance to Campus (Miles)' ~ ds$'Rentable Property')
print(model)
## 
## Call:
## lm(formula = ds$"Distance to Campus (Miles)" ~ ds$"Rentable Property")
## 
## Coefficients:
##            (Intercept)  ds$"Rentable Property"  
##              3.1966255              -0.0003856
predict(model)
##         1         2         3         4         5         6         7         8 
## 2.5107059 3.1029333 3.0821128 2.8272545 2.9309714 2.9564187 2.6329299 2.1714089 
##         9        10        11        12        13        14        15        16 
## 3.0335317 2.3557088 2.8758357 3.0516532 3.0790283 2.9776248 2.6737998 2.8260978 
##        17        18        19        20        21        22        23        24 
## 1.9431546 0.8562475 3.0416285 2.7917826 2.9872639 2.6113383 2.8106752 2.1316957 
##        25        26        27        28        29        30        31        32 
## 3.0354595 2.8388215 3.0504965 2.7836857 2.8808480 2.9086087 2.9244168 2.9996020 
##        33        34        35        36        37        38        39 
## 2.5847343 1.6208224 2.7038738 3.1808174 3.1087168 3.1519000 3.1653948
plot(ds$'Rentable Property', ds$'Distance to Campus (Miles)', xlab="Rentable Properties", ylab="Distance to Campus", main="Number of Properties vs. Distance Regression")
abline(model)

summary(model)
## 
## Call:
## lm(formula = ds$"Distance to Campus (Miles)" ~ ds$"Rentable Property")
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.2335 -0.8797  0.2495  0.7687  2.2914 
## 
## Coefficients:
##                          Estimate Std. Error t value Pr(>|t|)    
## (Intercept)             3.1966255  0.2551428  12.529 7.03e-15 ***
## ds$"Rentable Property" -0.0003856  0.0001530  -2.519   0.0162 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.143 on 37 degrees of freedom
## Multiple R-squared:  0.1464, Adjusted R-squared:  0.1234 
## F-statistic: 6.347 on 1 and 37 DF,  p-value: 0.0162
par(mar=c(11,4,1,0))
barplot(ds$'Distance to Campus (Miles)', main="Distance to Campus", ylab="Distance (Miles)", names.arg=ds$'Neighborhood', las=2, cex.names=0.7)

## Jiayi Huang Code

rentable <- dataset$`Rentable Property`
average <- dataset$`Average rent ($)`
summary(rentable)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##      41     410     819    1162    1409    6070
summary(average)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    1020    1565    1793    1728    1930    2066
plot(rentable, average, xlab = "# of Rentable Properties", ylab = "Average Rent", main = "Visualization of # of Rentable Properties vs Average Rent")

t_test <- t.test(rentable, average)
print(t_test)
## 
##  Welch Two Sample t-test
## 
## data:  rentable and average
## t = -2.8312, df = 42.775, p-value = 0.00704
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -969.6750 -162.8378
## sample estimates:
## mean of x mean of y 
##  1161.692  1727.949

since p-value is less than 0.05, we can reject the null hypothesis.

regression <- lm(rentable ~ average)
summary(regression)
## 
## Call:
## lm(formula = rentable ~ average)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1014.4  -763.6  -301.8   217.0  4868.8 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)
## (Intercept)  420.9302  1141.3678   0.369    0.714
## average        0.4287     0.6508   0.659    0.514
## 
## Residual standard error: 1221 on 37 degrees of freedom
## Multiple R-squared:  0.01159,    Adjusted R-squared:  -0.01512 
## F-statistic: 0.4339 on 1 and 37 DF,  p-value: 0.5141

p-value is greater than 0.05 this time. adjusted r-squared is negative, could mean it is not a good fit.

cor.test(rentable, average, method = "pearson")
## 
##  Pearson's product-moment correlation
## 
## data:  rentable and average
## t = 0.65874, df = 37, p-value = 0.5141
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.2151591  0.4092805
## sample estimates:
##       cor 
## 0.1076671

correlation is low

distance <- dataset$`Distance to Campus (Miles)`
property <- dataset$`Rentable Property`

summary(distance)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   0.400   2.050   2.600   2.749   3.750   5.200
summary(property)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##      41     410     819    1162    1409    6070
plot(distance, property, xlab = "distance to campus", ylab = "number of property", main = "distance vs # of property")

plot(rentable, average, main = "Linear Regression(# of Rentable Property vs Average Rent)", xlab = "Number of Rentable", ylab = "Average Rent")
abline(regression)

reg <- lm(distance ~ property)
summary(reg)
## 
## Call:
## lm(formula = distance ~ property)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.2335 -0.8797  0.2495  0.7687  2.2914 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  3.1966255  0.2551428  12.529 7.03e-15 ***
## property    -0.0003856  0.0001530  -2.519   0.0162 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.143 on 37 degrees of freedom
## Multiple R-squared:  0.1464, Adjusted R-squared:  0.1234 
## F-statistic: 6.347 on 1 and 37 DF,  p-value: 0.0162
plot(property, distance, main = "regression", xlab = "preperty", ylab = "distance")
abline(reg)

neighborhood <- dataset$Neighborhood
par(mar=c(11, 4, 1, 0))
barplot(average, names.arg = neighborhood, main = "Average Rent by Neighborhood", xlab = "Neighborhood", ylab = "Average Rent", las=2, cex.names=0.7)