library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.2 ✔ tibble 3.3.0
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.1
## ✔ purrr 1.1.0
## ── 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(tidyverse)
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
library(readxl)
district<-read_excel("district.xls")
district_data<-district
example_model<-lm(DA0GR21N~DPSTADFP,data=district_data)
summary(example_model)
##
## Call:
## lm(formula = DA0GR21N ~ DPSTADFP, data = district_data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1609.1 -306.5 -149.9 -2.1 11204.9
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -162.851 68.346 -2.383 0.0174 *
## DPSTADFP 23.430 2.995 7.823 1.22e-14 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 848.8 on 1077 degrees of freedom
## (128 observations deleted due to missingness)
## Multiple R-squared: 0.05377, Adjusted R-squared: 0.05289
## F-statistic: 61.2 on 1 and 1077 DF, p-value: 1.225e-14
for lines 25-30, i used dependent variable student graduate count and independent variable as teachers with advanced degrees. the adjusted R squared is .052 which translates to 5.2% this regression explains 5.2% of the data. 5.2% of the student graduate count can be “explained” teachers with advanced degrees. The p-value is very small at 1.225e-14 which is statistically significant and null hypothesis can be rejected.
district_multiple<-lm(DA0GR21N~DPSTADFP+DPSTTOSA+DPSTKIDR+DPSTVOFP,data=district_data)
summary(district_multiple)
##
## Call:
## lm(formula = DA0GR21N ~ DPSTADFP + DPSTTOSA + DPSTKIDR + DPSTVOFP,
## data = district_data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1317.1 -309.5 -99.9 94.6 10633.3
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -3.000e+03 2.798e+02 -10.721 < 2e-16 ***
## DPSTADFP 8.336e+00 2.985e+00 2.793 0.005323 **
## DPSTTOSA 5.267e-02 5.372e-03 9.804 < 2e-16 ***
## DPSTKIDR 3.974e+01 9.543e+00 4.165 3.37e-05 ***
## DPSTVOFP -2.313e+01 6.147e+00 -3.762 0.000178 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 780.8 on 1073 degrees of freedom
## (129 observations deleted due to missingness)
## Multiple R-squared: 0.2022, Adjusted R-squared: 0.1993
## F-statistic: 68.01 on 4 and 1073 DF, p-value: < 2.2e-16
#for lines 32-36, i used mulitple independent variables and ran an lm and summary on them. The variables are all significant as all the p values for each variable are under 0.05 (teacher advanced degree, teacher salary, teacher technical eduation, number of students per teacher). The overall p-value of all the variables is at 2.2e-16 very small under .05 and is significant. The R squared has increased from 19% to 20%.
#the beta/coeffiencts for each variable are all very small. #when teachers with advanced degrees goes up by “1”, student gradatue count goes up by 8.336e %.
plot(district_multiple,which=1)
# i would say that this model meets the assumption of linearity as most
of the dots are near the red line (that is also almost straight). if
needed, i could preform a log transformation to see if more of the dots
would be closer to the line.