knitr::opts_chunk$set(echo = TRUE)
#load packages
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(pastecs)
##
## Attaching package: 'pastecs'
##
## The following objects are masked from 'package:dplyr':
##
## first, last
##
## The following object is masked from 'package:tidyr':
##
## extract
library(readxl)
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
district <- read_excel("district.xls")
model1 <- lm(DAGC4X21R~DPFVTOTK+DPETECOP+DPSTTOSA,data=district)
summary(model1)
##
## Call:
## lm(formula = DAGC4X21R ~ DPFVTOTK + DPETECOP + DPSTTOSA, data = district)
##
## Residuals:
## Min 1Q Median 3Q Max
## -95.131 -1.181 2.285 5.007 12.955
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.079e+02 4.369e+00 24.684 < 2e-16 ***
## DPFVTOTK 1.019e-07 2.625e-07 0.388 0.698
## DPETECOP -1.489e-01 1.898e-02 -7.847 1.03e-14 ***
## DPSTTOSA -9.310e-05 7.660e-05 -1.215 0.224
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 12.45 on 1067 degrees of freedom
## (136 observations deleted due to missingness)
## Multiple R-squared: 0.05695, Adjusted R-squared: 0.0543
## F-statistic: 21.48 on 3 and 1067 DF, p-value: 1.64e-13
## DAGC4X21R "DPFVTOTK", "DPETECOP", "DPSTTOSA")]
## graduation rate, property wealth, % economically disadvantaged, and average teacher salary.
##Adjusted r squared is .05 which means the model accounts for 5% of the variance in weight.
##P-value well below 0.05. As a group, the predictors do better than nothing. So the model is real, just weak.
##The variable % economically disadvantaged students is significant
##The two variables: property wealth and average teacher salary are not significant
##Estimates or Beta Coefficient's:
##For every 1 point increase in economically disadvantaged students, graduation rates drop by about -1.489e-01 or 0.15 points.
##Districts with more low-income students tend to have somewhat lower graduation rates, even after accounting for property wealth and teacher pay. This ##shows a connection, not proof that one causes the other.
plot(model1,which=1)

##The plot shows linearity is only partly met:
##The red line is mostly flat near zero and is slighly tilting downward