{r} install.packages("dplyr") install.packages("ggplot2") library(tidyverse) mel <- read.csv("data/Melbourne_housing_FULL.csv") mel
{r} #Base r idx = mel$Suburb %in% c("Brunswick","Craigieburn","Hawthorn") mel.sub = mel[idx,] mel.sub$Suburb = factor(mel.sub$Suburb, levels = c("Brunswick","Craigieburn","Hawthorn")) mel.sub
{r} mel |> filter(Suburb %in% c("Brunswick","Craigieburn","Hawthorn")) |> group_by(Suburb) |> summarize(Mean_price = mean(Price, na.rm = T))
```{r}
mel.sub$Price = mel.sub$Price/1000
lm1 = lm(mel.sub$Price ~ mel.sub$BuildingArea) summary(lm1)
#1.4a Fit a multiple linear regression model with "Suburb", Briefly describe how to interpret the regression coefficients returned by lm, create an appropriate visualisation{r}
lm2 = lm(mel.sub$Price ~ mel.sub$BuildingArea + mel.sub$Suburb)
summary(lm2)
ggplot(mel.sub, aes(x = BuildingArea, y = Price, color = Suburb)) + geompoint() + geomsmooth(method = "lm", se = FALSE) + theme_minimal() + labs(title = "Price vs Building Area by Suburb", x = "Building Area", y = "Price in 000s") ```
{r} lm3 = lm(mel.sub$Price ~ mel.sub$BuildingArea + mel.sub$Suburb + mel.sub$Car) summary(lm3) # based on the further distance from the median to 0, I conclude that the model has gone worse with a new predictor.