# Question 1 & 2: Scatter Plot of Age vs. Price
ggplot(house_price, aes(x = Age_years, y = Price, color = Location)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE, color = "blue") +
labs(x = "Age of House (Years)", y = "Price", title = "Scatter Plot of Age vs. Price with Regression Line") +
theme_minimal() +
scale_color_manual(values = c("Rural" = "red", "Suburban" = "blue", "Urban" = "green"))
## `geom_smooth()` using formula = 'y ~ x'

# Question 3: Scatter Plot of Size vs. Price
ggplot(house_price, aes(x = Size_sqm, y = Price)) +
geom_point(size = 3, color = "darkblue") +
labs(x = "Size (sqm)", y = "Price", title = "Scatter Plot of Size vs. Price") +
geom_smooth(method = "lm", se = FALSE, color = "blue") +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

# Question 4: Bar Chart of Average Price by Location
summary_data <- house_price %>%
group_by(Location) %>%
summarize(Avg_Price = mean(Price))
ggplot(summary_data, aes(x = Location, y = Avg_Price, fill = Location)) +
geom_bar(stat = 'identity', color = "white") +
labs(x = "Location", y = "Average Price", title = "Average House Price by Location") +
theme_minimal()

# Question 5: Histogram of Price
ggplot(house_price, aes(x = Price)) +
geom_histogram(bins = 30, color = "white", fill = "skyblue", alpha = 0.7) +
labs(x = "Price", y = "Frequency", title = "Histogram of Price") +
theme_minimal()

# Question 6: Histogram with Density Plot for Size_sqm
ggplot(house_price, aes(x = Size_sqm, fill = "Size_sqm")) +
geom_histogram(alpha = 0.5, bins = 30, color = "white") +
geom_density(alpha = 0.7, fill = "blue") +
labs(x = "Size_sqm", y = "Density", title = "Histogram with Density Plot for Size_sqm") +
theme_minimal()

# Question 7: Bar Chart of Count of Houses by Condition
ggplot(house_price, aes(x = Condition, fill = Condition)) +
geom_bar() +
labs(x = "Condition", y = "Count of Houses", title = "Count of Houses by Condition") +
scale_fill_manual(values = c("red", "green", "blue", "yellow", "orange")) +
theme_minimal()

# Question 8: Scatter Plot of Size_sqm vs. Price by Location
ggplot(house_price, aes(x = Size_sqm, y = Price, color = Location)) +
geom_point() +
labs(x = "Size_sqm", y = "Price", title = "Scatter Plot of Size_sqm vs Price") +
facet_wrap(~Location, scales = "free") +
theme_minimal()

# Question 9: Linear Regression Model 1
model1 <- lm(Price ~ Size_sqm + Bedrooms + Bathrooms + Age_years, data = house_price)
summary(model1)
##
## Call:
## lm(formula = Price ~ Size_sqm + Bedrooms + Bathrooms + Age_years,
## data = house_price)
##
## Residuals:
## Min 1Q Median 3Q Max
## -301581 -115565 25725 107711 179611
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 360569.8 64385.3 5.600 2.07e-07 ***
## Size_sqm -296.1 194.7 -1.521 0.132
## Bedrooms 4627.6 9939.2 0.466 0.643
## Bathrooms 8155.2 16674.9 0.489 0.626
## Age_years -621.3 477.2 -1.302 0.196
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 130600 on 95 degrees of freedom
## Multiple R-squared: 0.04962, Adjusted R-squared: 0.0096
## F-statistic: 1.24 on 4 and 95 DF, p-value: 0.2993
# Question 10: Linear Regression Model 2
model2 <- lm(Price ~ Size_sqm + Bedrooms + Bathrooms + Age_years + Distance_to_city_center_km, data = house_price)
summary(model2)
##
## Call:
## lm(formula = Price ~ Size_sqm + Bedrooms + Bathrooms + Age_years +
## Distance_to_city_center_km, data = house_price)
##
## Residuals:
## Min 1Q Median 3Q Max
## -312746 -114538 34603 110559 183538
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 351412.4 66539.0 5.281 8.25e-07 ***
## Size_sqm -293.8 195.4 -1.504 0.136
## Bedrooms 3945.7 10044.3 0.393 0.695
## Bathrooms 7102.4 16833.3 0.422 0.674
## Age_years -679.5 489.4 -1.388 0.168
## Distance_to_city_center_km 586.7 1018.4 0.576 0.566
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 131000 on 94 degrees of freedom
## Multiple R-squared: 0.05296, Adjusted R-squared: 0.002586
## F-statistic: 1.051 on 5 and 94 DF, p-value: 0.3925
print("Given that the p-value is greater than 0.05, our alpha, we fail to reject the null hypothesis as we support")
## [1] "Given that the p-value is greater than 0.05, our alpha, we fail to reject the null hypothesis as we support"