#Use the realtor data to answer the following questions.
realtor_data1 <- readr::read_csv('realtor_data.csv')
## Rows: 296 Columns: 11
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): Home Type, Address, City, State
## dbl (7): Zip, Listing Price, Baths, Beds, SQFT, Year Built, Airbnb Cash on Cash
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#Q.1 Present summary statistics for all the numeric variables (min, max, mean, median)
summary(realtor_data1)
## Home Type Address City State
## Length:296 Length:296 Length:296 Length:296
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## Zip Listing Price Baths Beds
## Min. :61820 Min. : 77100 Min. :0.000 Min. :1.000
## 1st Qu.:61821 1st Qu.:120000 1st Qu.:1.000 1st Qu.:3.000
## Median :61821 Median :172350 Median :2.000 Median :3.000
## Mean :61821 Mean :225782 Mean :1.969 Mean :3.176
## 3rd Qu.:61822 3rd Qu.:285675 3rd Qu.:3.000 3rd Qu.:4.000
## Max. :61822 Max. :989000 Max. :6.000 Max. :4.000
## NA's :2
## SQFT Year Built Airbnb Cash on Cash
## Min. : 704 Min. :1855 Min. :-1.126
## 1st Qu.:1322 1st Qu.:1960 1st Qu.: 2.284
## Median :1704 Median :1985 Median : 5.056
## Mean :2003 Mean :1979 Mean : 7.372
## 3rd Qu.:2396 3rd Qu.:2004 3rd Qu.:12.357
## Max. :7040 Max. :2017 Max. :25.179
## NA's :2 NA's :23
#Q.2 How many listings are there for each type of home?
table(realtor_data1$`Home Type`)
##
## Condo/Coop Single Family Residential Townhouse
## 39 246 11
#Q.3 How many 1,2, 3, and 4 bedroom listings are there in each zipcode?
a <- aggregate(realtor_data1$Beds, by=list(realtor_data1$Zip) ,
FUN=function(x) table(factor(x,levels = c (1,2,3,4))))
print(a)
## Group.1 x.1 x.2 x.3 x.4
## 1 61820 1 17 24 8
## 2 61821 0 16 66 24
## 3 61822 0 16 53 71
#Q.4 What are the average listing prices by zipcode? (use aggregate function)
aggregate(realtor_data1$`Listing Price`, list(realtor_data1$Zip), mean, na.rm=T)
#Q.5 What are the variance of listing prices by zipcode?
aggregate(realtor_data1$`Listing Price`, by=list(realtor_data1$Zip), FUN=var, na.rm=TRUE)
#Q.6 Present histograms of listing price for Zipcode 61822
hist(realtor_data1$`Listing Price`[realtor_data1$Zip==61822],
breaks=100,
main='histograms of listing price for Zipcode 61822',
xlab = 'Price',
ylab = 'Number of houses',
xlim= c(0,970000),
ylim= c(0,10)
)
#Q.7 Discuss the skewness of listing price in Zipcode 61822
library(e1071)
skewness(realtor_data1$`Listing Price`[realtor_data1$Zip==61822])
## [1] 1.020006
#Q.8 Present boxplot of listing price for Zipcode 61822
boxplot(realtor_data1$`Listing Price`[realtor_data1$Zip==61822],
main = 'Boxplot of listing price for Zipcode 61822',
ylab='price')
#Q.9 Present scatter plot for two variables, and summarize what information you can learn from the plot
options(scipen = 1000)
plot(x= realtor_data1$SQFT,
y=realtor_data1$`Listing Price`,
main="Listing Price by SQFT",
xlab='SQFT',
ylab='Listing Price',
xlim=c(0,7000),
ylim=c(0,800000))
#Q.10 Use linear regression to find out which factors are strong predictors of “Airbnb cash on cash “
m1<-lm(realtor_data1$'Airbnb Cash on Cash' ~ realtor_data1$Zip+realtor_data1$'Listing Price'+realtor_data1$Baths+realtor_data1$Beds+realtor_data1$SQFT, data=realtor_data1)
summary(m1)
##
## Call:
## lm(formula = realtor_data1$"Airbnb Cash on Cash" ~ realtor_data1$Zip +
## realtor_data1$"Listing Price" + realtor_data1$Baths + realtor_data1$Beds +
## realtor_data1$SQFT, data = realtor_data1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -9.0068 -4.0450 -0.0981 3.2102 13.3366
##
## Coefficients:
## Estimate Std. Error t value
## (Intercept) 50276.419570545 25015.365622316 2.010
## realtor_data1$Zip -0.813092329 0.404646219 -2.009
## realtor_data1$"Listing Price" -0.000024138 0.000003676 -6.566
## realtor_data1$Baths -0.341703189 0.262777095 -1.300
## realtor_data1$Beds 1.458090487 0.472478404 3.086
## realtor_data1$SQFT -0.000576223 0.000566953 -1.016
## Pr(>|t|)
## (Intercept) 0.04539 *
## realtor_data1$Zip 0.04543 *
## realtor_data1$"Listing Price" 0.000000000242 ***
## realtor_data1$Baths 0.19452
## realtor_data1$Beds 0.00223 **
## realtor_data1$SQFT 0.31032
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.67 on 287 degrees of freedom
## (3 observations deleted due to missingness)
## Multiple R-squared: 0.452, Adjusted R-squared: 0.4424
## F-statistic: 47.34 on 5 and 287 DF, p-value: < 0.00000000000000022
As the listing price increases, Airbnb’s cash flow decreases, as seen by the negative listing price coefficient. This makes sense because higher-priced properties will also have higher closing costs and other related charges, such as cleaning and taxes. The Listing Price shows significant predictive capability and has a negative link with Airbnb Cash on Cash. The impact of other factors, such as sqft, bed, and bath, is less significant than that of the listing price.