library(readxl)
district <- read_excel("district.xls")
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.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(pastecs)
##
## Attaching package: 'pastecs'
## The following objects are masked from 'package:dplyr':
##
## first, last
## The following object is masked from 'package:tidyr':
##
## extract
library(lmtest)
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
library(MASS)
##
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
##
## select
data_multiple <- lm(DA0CT21R ~ DA0AT21R + DPETECOP, data = district)
plot(data_multiple,which=1)
raintest(data_multiple)
##
## Rainbow test
##
## data: data_multiple
## Rain = 1.018, df1 = 541, df2 = 537, p-value = 0.418
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
durbinWatsonTest(data_multiple)
## lag Autocorrelation D-W Statistic p-value
## 1 0.02736478 1.941079 0.304
## Alternative hypothesis: rho != 0
plot(data_multiple,which=3)
bptest(data_multiple)
##
## studentized Breusch-Pagan test
##
## data: data_multiple
## BP = 59.993, df = 2, p-value = 9.388e-14
plot(data_multiple,which=2)
shapiro.test(data_multiple$residuals)
##
## Shapiro-Wilk normality test
##
## data: data_multiple$residuals
## W = 0.98053, p-value = 7.466e-11
vif(data_multiple)
## DA0AT21R DPETECOP
## 1.152022 1.152022
Explanation The model does meet the assumptions as the p-value of 0.418 is >0.05 which we can assume there is linearity of this model.The model does violate the homoscedasticity assumption. How to mitigate this wouls be to use a log transformation