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(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
library(MASS)
##
## Attaching package: 'MASS'
##
## The following object is masked from 'package:dplyr':
##
## select
district<-read_excel("district (2).xls")
sat_model<-lm(DA0CSA21R~DPSTURNR+DPETECOP+DPFRAALLK+DPSTKIDR+DPSTADFP+DA0AT21R+DPFEAINSK,data = district)
summary(sat_model)
##
## Call:
## lm(formula = DA0CSA21R ~ DPSTURNR + DPETECOP + DPFRAALLK + DPSTKIDR +
## DPSTADFP + DA0AT21R + DPFEAINSK, data = district)
##
## Residuals:
## Min 1Q Median 3Q Max
## -984.95 -11.96 116.68 213.20 854.10
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.284e+03 5.248e+02 -2.446 0.014611 *
## DPSTURNR -1.459e+00 1.335e+00 -1.093 0.274645
## DPETECOP -2.184e+00 6.530e-01 -3.344 0.000860 ***
## DPFRAALLK 2.417e-03 2.200e-03 1.099 0.272105
## DPSTKIDR 3.683e+01 6.408e+00 5.747 1.23e-08 ***
## DPSTADFP 5.785e+00 1.514e+00 3.821 0.000142 ***
## DA0AT21R 1.868e+01 5.016e+00 3.724 0.000208 ***
## DPFEAINSK -2.063e-02 1.337e-02 -1.543 0.123245
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 359.6 on 932 degrees of freedom
## (267 observations deleted due to missingness)
## Multiple R-squared: 0.1469, Adjusted R-squared: 0.1405
## F-statistic: 22.93 on 7 and 932 DF, p-value: < 2.2e-16
plot(sat_model,which=1)
This model is not linear by visual inspection
vif(sat_model)
## DPSTURNR DPETECOP DPFRAALLK DPSTKIDR DPSTADFP DA0AT21R DPFEAINSK
## 1.081331 1.286410 1.538036 2.065974 1.104564 1.245286 2.508829
plot(sat_model,which=3)
bptest(sat_model)
##
## studentized Breusch-Pagan test
##
## data: sat_model
## BP = 121.2, df = 7, p-value < 2.2e-16
This model is not considered homoskedastic per bptest
durbinWatsonTest(sat_model)
## lag Autocorrelation D-W Statistic p-value
## 1 0.08549661 1.828651 0.018
## Alternative hypothesis: rho != 0
The model’s errors are not independent per the Durbinwatson test
plot(sat_model,which=2)
district_model_asinh <- lm(
asinh(DA0CSA21R) ~ asinh(DPSTURNR) +
asinh(DPETECOP) +
asinh(DPFRAALLK) +
asinh(DPSTKIDR) +
asinh(DPSTADFP) +
asinh(DA0AT21R) +
asinh(DPFEAINSK),
data = district)
plot(district_model_asinh, which = 1)
sat_model_rlm<-rlm(DA0CSA21R~DPSTURNR+DPETECOP+DPFRAALLK+DPSTKIDR+DPSTADFP+DA0AT21R+DPFEAINSK,data = district)
durbinWatsonTest(sat_model_rlm)
## lag Autocorrelation D-W Statistic p-value
## 1 0.232166 1.535663 0
## Alternative hypothesis: rho != 0
district_model_log <- lm(
log(DA0CSA21R) ~ DPSTURNR +
DPETECOP +
DPFRAALLK +
DPSTKIDR +
DPSTADFP +
DA0AT21R +
DPFEAINSK,
data = district,
na.action = na.omit
)
## Warning in log(DA0CSA21R): NaNs produced
plot(district_model_log, which = 3)
bptest(district_model_log)
##
## studentized Breusch-Pagan test
##
## data: district_model_log
## BP = 36.556, df = 7, p-value = 5.692e-06
raintest(sat_model)
##
## Rainbow test
##
## data: sat_model
## Rain = 1.0179, df1 = 470, df2 = 462, p-value = 0.424
mean(district$DA0CSA21R, na.rm = TRUE)
## [1] 823.8942
sd(district$DA0CSA21R, na.rm = TRUE)
## [1] 388.0253
min(district$DA0CSA21R, na.rm = TRUE)
## [1] -1
sum(district$DA0CSA21R == -1, na.rm = TRUE)
## [1] 165
mean(district$DA0CSA21R[district$DA0CSA21R != -1], na.rm = TRUE)
## [1] 998.391
sd(district$DA0CSA21R[district$DA0CSA21R != -1], na.rm = TRUE)
## [1] 88.54424
min(district$DA0CSA21R[district$DA0CSA21R != -1], na.rm = TRUE)
## [1] 762
max(district$DA0CSA21R[district$DA0CSA21R != -1], na.rm = TRUE)
## [1] 1344
median(district$DA0CSA21R[district$DA0CSA21R != -1], na.rm = TRUE)
## [1] 997
SAT average scores
mean(district$DPSTURNR, na.rm = TRUE)
## [1] 21.50517
sd(district$DPSTURNR, na.rm = TRUE)
## [1] 10.96977
min(district$DPSTURNR, na.rm = TRUE)
## [1] 0
max(district$DPSTURNR, na.rm = TRUE)
## [1] 100
median(district$DPSTURNR, na.rm = TRUE)
## [1] 19.5
Teacher turnover rate
mean(district$DPETECOP, na.rm = TRUE)
## [1] 60.75046
sd(district$DPETECOP, na.rm = TRUE)
## [1] 21.71866
min(district$DPETECOP, na.rm = TRUE)
## [1] 0
max(district$DPETECOP, na.rm = TRUE)
## [1] 100
median(district$DPETECOP, na.rm = TRUE)
## [1] 61.9
% of Economically disadvantaged
mean(district$DPFRAALLK, na.rm = TRUE)
## [1] 16364.95
sd(district$DPFRAALLK, na.rm = TRUE)
## [1] 8828.796
min(district$DPFRAALLK, na.rm = TRUE)
## [1] 8923
max(district$DPFRAALLK, na.rm = TRUE)
## [1] 214078
median(district$DPFRAALLK, na.rm = TRUE)
## [1] 14653
total operating and other rev. per pupil
mean(district$DPSTKIDR, na.rm = TRUE)
## [1] 12.55831
sd(district$DPSTKIDR, na.rm = TRUE)
## [1] 3.025855
min(district$DPSTKIDR, na.rm = TRUE)
## [1] -2
max(district$DPSTKIDR, na.rm = TRUE)
## [1] 37.3
sum(district$DPSTKIDR == -2, na.rm = TRUE)
## [1] 4
mean(district$DPSTKIDR[district$DPSTKIDR != -2], na.rm = TRUE)
## [1] 12.60683
sd(district$DPSTKIDR[district$DPSTKIDR != -2], na.rm = TRUE)
## [1] 2.911515
min(district$DPSTKIDR[district$DPSTKIDR != -2], na.rm = TRUE)
## [1] 0.1
max(district$DPSTKIDR[district$DPSTKIDR != -2], na.rm = TRUE)
## [1] 37.3
median(district$DPSTKIDR[district$DPSTKIDR != -2], na.rm = TRUE)
## [1] 12.75
students per teacher
mean(district$DPSTADFP, na.rm = TRUE)
## [1] 20.85748
sd(district$DPSTADFP, na.rm = TRUE)
## [1] 9.093495
min(district$DPSTADFP, na.rm = TRUE)
## [1] 0
max(district$DPSTADFP, na.rm = TRUE)
## [1] 78.7
median(district$DPSTADFP, na.rm = TRUE)
## [1] 20.9
teachers with advanced degrees
mean(district$DA0AT21R, na.rm = TRUE)
## [1] 94.75719
sd(district$DA0AT21R, na.rm = TRUE)
## [1] 4.865725
min(district$DA0AT21R, na.rm = TRUE)
## [1] -1
max(district$DA0AT21R, na.rm = TRUE)
## [1] 100
sum(district$DA0AT21R == -1, na.rm = TRUE)
## [1] 2
mean(district$DA0AT21R[district$DA0AT21R != -1], na.rm = TRUE)
## [1] 94.91665
sd(district$DA0AT21R[district$DA0AT21R != -1], na.rm = TRUE)
## [1] 2.899464
min(district$DA0AT21R[district$DA0AT21R != -1], na.rm = TRUE)
## [1] 64.2
max(district$DA0AT21R[district$DA0AT21R != -1], na.rm = TRUE)
## [1] 100
median(district$DA0AT21R[district$DA0AT21R != -1], na.rm = TRUE)
## [1] 95.4
attendance rate
mean(district$DPFEAINSK, na.rm = TRUE)
## [1] 7073.853
sd(district$DPFEAINSK, na.rm = TRUE)
## [1] 2257.571
min(district$DPFEAINSK, na.rm = TRUE)
## [1] 3122
max(district$DPFEAINSK, na.rm = TRUE)
## [1] 54954
median(district$DPFEAINSK, na.rm = TRUE)
## [1] 6702
instructional expenditures per pupil
summary(sat_model)
##
## Call:
## lm(formula = DA0CSA21R ~ DPSTURNR + DPETECOP + DPFRAALLK + DPSTKIDR +
## DPSTADFP + DA0AT21R + DPFEAINSK, data = district)
##
## Residuals:
## Min 1Q Median 3Q Max
## -984.95 -11.96 116.68 213.20 854.10
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.284e+03 5.248e+02 -2.446 0.014611 *
## DPSTURNR -1.459e+00 1.335e+00 -1.093 0.274645
## DPETECOP -2.184e+00 6.530e-01 -3.344 0.000860 ***
## DPFRAALLK 2.417e-03 2.200e-03 1.099 0.272105
## DPSTKIDR 3.683e+01 6.408e+00 5.747 1.23e-08 ***
## DPSTADFP 5.785e+00 1.514e+00 3.821 0.000142 ***
## DA0AT21R 1.868e+01 5.016e+00 3.724 0.000208 ***
## DPFEAINSK -2.063e-02 1.337e-02 -1.543 0.123245
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 359.6 on 932 degrees of freedom
## (267 observations deleted due to missingness)
## Multiple R-squared: 0.1469, Adjusted R-squared: 0.1405
## F-statistic: 22.93 on 7 and 932 DF, p-value: < 2.2e-16