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
hotline_data<-read_csv("hotline_data.csv")
## Rows: 2184 Columns: 11
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (5): State, Timeframe, Call Average Time to Answer, Text Average Time to...
## dbl (6): Number of Routed Calls, Call Answer Rate, Number of Routed Texts, T...
##
## ℹ 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.
hotline_clean <- na.omit(hotline_data)
hotline_model1<-lm(`Call Answer Rate`~`Number of Routed Calls`+`Number of Routed Texts`,data=hotline_clean)
#Testing Linearity
plot(hotline_model1,which=1)
This model is relatively linear by visual inspection.
#Testing Independence of Errors
durbinWatsonTest(hotline_model1)
## lag Autocorrelation D-W Statistic p-value
## 1 0.8516578 0.2906528 0
## Alternative hypothesis: rho != 0
The model’s errors are not independent per the Durbin Watson Test (p value < 0.05).
#Testing Homoscedasticity
plot(hotline_model1,which=3)
bptest(hotline_model1)
##
## studentized Breusch-Pagan test
##
## data: hotline_model1
## BP = 10.003, df = 2, p-value = 0.006729
The model is not homoscedastistic per the BP-test (p-value < 0.05).
#Testing Normality of Residuals
plot(hotline_model1,which=2)
Model is not normaly distributed based on visual inspection.
#Testing Multicolinarity
vif(hotline_model1)
## `Number of Routed Calls` `Number of Routed Texts`
## 4.007678 4.007678
The assumptions not met are Independence of Errors, Homoscedasticity, and Normality of Residuals.
#Mitigating Assumptions
hotline_model_log<-lm(log(`Call Answer Rate`)~log(`Number of Routed Calls`)+log(`Number of Routed Texts`),data=hotline_clean)
#Mitigating Linearity
plot(hotline_model_log,which=1)
Model was log-transformed to help with linearity. Based on visual
inspection, linearity appears to be reasonably met.
Mitigating Independence of Errors Not working for me.
#Mitigating Homoscedasticity
plot(hotline_model_log,which=3)
bptest(hotline_model_log)
##
## studentized Breusch-Pagan test
##
## data: hotline_model_log
## BP = 30.893, df = 2, p-value = 1.958e-07
A log transformation was used to reduce heteroscedascity in the mode, to no effect, the final result still has heteroscedascity per the BP-test (p-value < 0.05).
#Mitigating Normality of Residuals.
plot(hotline_model_log,which=2)
A log transformation was used to mitigate normality of residuals. The final result remains not normaly distributed based on visual inspection.