library(readxl)
district <- read_excel("district.xls")
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.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.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
#2. The dependent variable I'm choosing is DDH00A001S22R: % STAAR Test Scores of Hispanic students that approach grade level. The independent variables are expenditures for Bilingual/ESL education, % of ESL/Bilingual students, and % of ESL/Bilingual teachers.
#3. Create a linear model using the "lm()" command, save it to some object.
data_multiple <- lm(DDH00A001S22R~DPETBILP+DPSTBIFP+DPFPABILP,data = district)
#4. Call a "summary()" on your new model.
summary(data_multiple)
## 
## Call:
## lm(formula = DDH00A001S22R ~ DPETBILP + DPSTBIFP + DPFPABILP, 
##     data = district)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -74.914  -5.757   0.802   7.769  27.088 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 73.91439    0.47738 154.833  < 2e-16 ***
## DPETBILP    -0.22250    0.03451  -6.448 1.65e-10 ***
## DPSTBIFP     0.09047    0.07542   1.200    0.231    
## DPFPABILP    0.44518    0.34458   1.292    0.197    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 12.5 on 1193 degrees of freedom
##   (10 observations deleted due to missingness)
## Multiple R-squared:  0.04516,    Adjusted R-squared:  0.04276 
## F-statistic: 18.81 on 3 and 1193 DF,  p-value: 6.377e-12
#5. Interpret the model's r-squared and p-values. How much of the dependent variable does the overall model explain? What are the significant variables? What are the insignificant variables?
#The r-squared says that the model explains .04% of the data. The p-value results in 6.377e-12, so it is statistically significant. The significant variable are the Hispanic STAAR test scores variable and the % ESL/Bilingual students variable. The insignificant variables are the % ESL/Bilingual teachers variable and the expenditures for ESL/Bilingual education variable.
#6. Choose some significant independent variables. Interpret its Estimates (or Beta Coefficients). How do the independent variables individually affect the dependent variable?
#The only significant independent variable is the % of ESL/Bilingual students variable. The estimate is -0.22250 and it is saying that for every ESL/Bilingual student, STAAR Test Scores on Hispanic students decrease by 0.22. 
#7. Does the model you create meet or violate the assumption of linearity? Show your work with "plot(x, which=1)".
plot(data_multiple, which = 1)

The line of residuals vs fitted is not straight and the relationship between the variables is not linear.