library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.2.1     ✔ readr     2.2.0
## ✔ forcats   1.0.1     ✔ stringr   1.6.0
## ✔ ggplot2   4.0.3     ✔ tibble    3.3.1
## ✔ lubridate 1.9.5     ✔ tidyr     1.3.2
## ✔ purrr     1.2.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(readxl)
library(MASS)
## 
## Attaching package: 'MASS'
## 
## The following object is masked from 'package:dplyr':
## 
##     select
library(lmtest)
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## 
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
library(car)
## Loading required package: carData
## 
## Attaching package: 'car'
## 
## The following object is masked from 'package:dplyr':
## 
##     recode
## 
## The following object is masked from 'package:purrr':
## 
##     some
stadium <- read.csv("us_sportsvenues1909_2027.csv")

stadium_clean <- drop_na(stadium)
stadium_model1 <- lm(publiccost2020~totalcost2020+stadium+year+pubpct100, data=stadium_clean)
plot(stadium_model1,which=1)

#Testing Linerarity

This model is not linear by visual comparison.

publicost2020_log <- lm(publiccost2020~log(totalcost2020)+(stadium)+year+pubpct100, data=stadium_clean)
plot(publicost2020_log,which=1)

This models shows a better linear fit then my previous one.

durbinWatsonTest(stadium_model1)
##  lag Autocorrelation D-W Statistic p-value
##    1       0.1566004      1.580683   0.004
##  Alternative hypothesis: rho != 0

The model’s errors are not independent per Durbinwatson test (p value not > than .o5)

plot(stadium_model1, which=3)

bptest(stadium_model1)
## 
##  studentized Breusch-Pagan test
## 
## data:  stadium_model1
## BP = 142.67, df = 4, p-value < 2.2e-16

Model not homoscedastic because P value is less than .05

plot(publicost2020_log,which=3)

bptest(publicost2020_log)
## 
##  studentized Breusch-Pagan test
## 
## data:  publicost2020_log
## BP = 30.762, df = 4, p-value = 3.424e-06

Stuggleing to fix homocedasticty.

plot(stadium_model1,which=2)

shapiro.test(stadium_model1$residuals)
## 
##  Shapiro-Wilk normality test
## 
## data:  stadium_model1$residuals
## W = 0.84369, p-value = 2.791e-13

Visually the dots mostly fall on the line and P value is below .05.

vif(stadium_model1)
## totalcost2020       stadium          year     pubpct100 
##      1.568289      1.144997      1.498741      1.102885

Data has no multicolinearity