library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.2.0 ✔ readr 2.1.6
## ✔ forcats 1.0.1 ✔ stringr 1.6.0
## ✔ ggplot2 4.0.2 ✔ tibble 3.3.1
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.2
## ✔ purrr 1.2.1
## ── 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)
TEA_Data<-read_excel("district.xls")
Distric_model<-lm(DZRVLOCP~DPETALLC+COMMTYPE,data =TEA_Data)
summary(Distric_model)
##
## Call:
## lm(formula = DZRVLOCP ~ DPETALLC + COMMTYPE, data = TEA_Data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -49.798 -13.695 -3.468 11.452 54.019
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.724e+00 1.452e+00 3.254 0.00117 **
## DPETALLC 1.332e-04 6.959e-05 1.914 0.05586 .
## COMMTYPEIndependent Town 3.528e+01 3.091e+00 11.414 < 2e-16 ***
## COMMTYPEMajor Suburban 4.332e+01 3.030e+00 14.295 < 2e-16 ***
## COMMTYPEMajor Urban 3.702e+01 8.124e+00 4.556 5.74e-06 ***
## COMMTYPENon-metropolitan Fast Growing 3.945e+01 4.020e+00 9.815 < 2e-16 ***
## COMMTYPENon-metropolitan Stable 3.651e+01 2.035e+00 17.940 < 2e-16 ***
## COMMTYPEOther Central City 3.719e+01 3.898e+00 9.540 < 2e-16 ***
## COMMTYPEOther Central City Suburban 3.827e+01 2.112e+00 18.117 < 2e-16 ***
## COMMTYPERural 3.885e+01 1.704e+00 22.799 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 19.49 on 1192 degrees of freedom
## (5 observations deleted due to missingness)
## Multiple R-squared: 0.3465, Adjusted R-squared: 0.3416
## F-statistic: 70.24 on 9 and 1192 DF, p-value: < 2.2e-16
Distric_model<-lm(DZRVLOCP~DPETALLC+COMMTYPE,data =TEA_Data)
Distric_model<-lm(DZRVLOCP~DPETALLC+COMMTYPE,data =TEA_Data)
plot(Distric_model,which=1)

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(Distric_model)
## lag Autocorrelation D-W Statistic p-value
## 1 0.2530837 1.493002 0
## Alternative hypothesis: rho != 0
library(tidyverse)
library(readxl)
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
bptest(Distric_model)
##
## studentized Breusch-Pagan test
##
## data: Distric_model
## BP = 118.25, df = 9, p-value < 2.2e-16
shapiro.test(Distric_model$residuals)
##
## Shapiro-Wilk normality test
##
## data: Distric_model$residuals
## W = 0.96612, p-value = 3.905e-16
plot(Distric_model,which=2)

kitchen_sink<-lm(DZRVLOCP~DPETALLC+COMMTYPE,data =TEA_Data)
vif(kitchen_sink)
## GVIF Df GVIF^(1/(2*Df))
## DPETALLC 2.3955 1 1.547740
## COMMTYPE 2.3955 8 1.056118
pastecs::stat.desc(TEA_Data$DZRVLOCP)
## nbr.val nbr.null nbr.na min max
## 1202.0000000 8.0000000 5.0000000 -6.2000000 97.6000000
## range sum median mean SE.mean
## 103.8000000 45584.3000000 35.3000000 37.9237105 0.6928507
## CI.mean.0.95 var std.dev coef.var
## 1.3593323 577.0105864 24.0210447 0.6334044