Importing Datasets

library(readxl)
file_path <- "dataset.xlsx"
dataset <- read_excel(file_path)

Summary of the two datasets

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

Boxplot to visualize

plot(rentable, average, xlab = "# of Rentable Properties", ylab = "Average Rent", main = "Visualization of # of Rentable Properties vs Average Rent")

### T-test

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.

Linear Regression

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.

pearson correlation coefficient

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")

Linear Regression Plot

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)