library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.0     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.1     ✔ tibble    3.1.8
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.1     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the ]8;;http://conflicted.r-lib.org/conflicted package]8;; to force all conflicts to become errors
library(ggthemes)
## Warning: package 'ggthemes' was built under R version 4.2.3
library(ggrepel)
## Warning: package 'ggrepel' was built under R version 4.2.3
library(broom)
library(lindia)
## Warning: package 'lindia' was built under R version 4.2.3
library(car)
## Warning: package 'car' was built under R version 4.2.3
## Loading required package: carData
## Warning: package 'carData' was built under R version 4.2.3
## 
## Attaching package: 'car'
## 
## The following object is masked from 'package:dplyr':
## 
##     recode
## 
## The following object is masked from 'package:purrr':
## 
##     some
url <- "https://raw.githubusercontent.com/leontoddjohnson/i590/main/data/apartments/apartments.csv"

apts <- read_delim(url, delim = ',')
## Rows: 492 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (8): in_sf, beds, bath, price, year_built, sqft, price_per_sqft, elevation
## 
## ℹ 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.
# repeating the transformations
apts <- apts |>
  mutate(price_per_sqft_2 = price_per_sqft ^ 2,
         log_price = log(price),
         sqrt_sqft = sqrt(sqft))

Week 11 Dataset

# Explore the relationships between variables
pairs(apts[, c("year_built", "sqft", "elevation", "beds", "log_price")])

# Calculate correlation matrix
cor_matrix <- cor(apts[, c("year_built", "sqft", "elevation", "beds", "log_price")])
print(cor_matrix)
##             year_built       sqft  elevation        beds  log_price
## year_built  1.00000000 -0.0413914 -0.2089692 -0.07223557  0.2325606
## sqft       -0.04139140  1.0000000  0.1746025  0.78850393  0.7434016
## elevation  -0.20896922  0.1746025  1.0000000  0.33126732 -0.1478345
## beds       -0.07223557  0.7885039  0.3312673  1.00000000  0.5246238
## log_price   0.23256062  0.7434016 -0.1478345  0.52462381  1.0000000

Since the residuals scattered randomly around the zero line, we can safely assume that there’s a linear relationship between the response variable and each of these variables. Furthermore, the Q-Q plot shows that the error terms are evenly distributed.

Based on the above summary statistics, it is possible that our conclusions are more appropriate for some groups of the data and not others. For instance, ‘beds’ variable is not statistically significant because of its p-value of 0.677. Meanwhile, all the other variables have a very low p-value < 0.05 so the majority of the data is affecting the response variable.