library(tidyverse)
library(readxl)
library(ggplot2)
library(MASS)
library(lmtest)
library(car)

district <- read_excel("district.xls")
district_data <- lm(DA0CC23R ~ DPSTTOSA + DPSTKIDR + DPSTURNR + DPFPAREGP, data = district)
plot(district_data, which = 1)

This model is linear based on visual inspection.

durbinWatsonTest(district_data)
##  lag Autocorrelation D-W Statistic p-value
##    1      0.08886798      1.821967   0.006
##  Alternative hypothesis: rho != 0

The model’s errors are not independent per the Durbin-Watson test.

# Testing for homoscedasticity
plot(district_data, which = 3)

bptest(district_data)
## 
##  studentized Breusch-Pagan test
## 
## data:  district_data
## BP = 61.44, df = 4, p-value = 1.445e-12

The model as a p-value above 0.05, so this model is homoscedastic.

# Normality of errors
plot(district_data, which = 2)

The model is normal by visual inspection, because items are on the line.

# Check Variance Inflation Factors
vif(district_data)
##  DPSTTOSA  DPSTKIDR  DPSTURNR DPFPAREGP 
##  1.090832  1.091655  1.022546  1.075049

The model is without multicollinearity, because variance inflation factors are all under 10.


The assumption that the model did not meet would be the Durbin-Watson test. The model is not independent per the Durbin-Watson test.

model_log <- lm(sqrt(DA0CC23R) ~ sqrt(DPSTTOSA) + sqrt(DPSTKIDR) + sqrt(DPSTURNR) + sqrt(DPFPAREGP), data = district)
## Warning in sqrt(DA0CC23R): NaNs produced
plot(model_log)

Model was log-transformed to help with independence, but final results did not improve the model.

model_rlm <- rlm(DA0CC23R ~ DPSTTOSA + DPSTKIDR + DPSTURNR + DPFPAREGP, data = district)

summary(model_rlm)
## 
## Call: rlm(formula = DA0CC23R ~ DPSTTOSA + DPSTKIDR + DPSTURNR + DPFPAREGP, 
##     data = district)
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -59.2076 -10.2336  -0.7486   9.3301  59.2273 
## 
## Coefficients:
##             Value   Std. Error t value
## (Intercept) -3.1830  4.9856    -0.6385
## DPSTTOSA     0.0001  0.0001     1.2094
## DPSTKIDR     0.1416  0.0818     1.7312
## DPSTURNR    -0.3948  0.0484    -8.1528
## DPFPAREGP    0.7151  0.0594    12.0486
## 
## Residual standard error: 14.43 on 1065 degrees of freedom
##   (137 observations deleted due to missingness)

Robust linear model was used to transform the data, to no effect, the final results show minimal impact of influential outliers.