knitr::opts_chunk$set(echo = TRUE)
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)
district<-read_excel("district.xls")
sped <- district %>% select(DISTNAME, DPETSPEP, DPFPASPEP)
summary(sped)
##       DISTNAME       DPETSPEP       DPFPASPEP     
##  Length   :1207   Min.   : 0.00   Min.   : 0.000  
##  N.unique :1196   1st Qu.: 9.90   1st Qu.: 5.800  
##  N.blank  :   0   Median :12.10   Median : 8.900  
##  Min.nchar:   7   Mean   :12.27   Mean   : 9.711  
##  Max.nchar:  50   3rd Qu.:14.20   3rd Qu.:12.500  
##                   Max.   :51.70   Max.   :49.000  
##                                   NAs    :5
# DPFPASPEP has 5 NAs
sped_cleaned<-sped %>% filter(DPFPASPEP>0)
count(sped_cleaned) # 1201 are remaining as DPFPASPEP reflected a 0 for minimum. This means there was an obs that reported a 0. With filter(DPFPASPEP>0) any value 0 or below would be filtered out.
## # A tibble: 1 × 1
##       n
##   <int>
## 1  1201
ggplot(sped_cleaned, aes(x=DPFPASPEP, y=DPETSPEP)) + geom_point()

# positive correlation
cor(sped_cleaned$DPFPASPEP, sped_cleaned$DPETSPEP)
## [1] 0.371033
# [1] 0.371033 affirms positive correlation from Q6
# A weak positive relationship exists between DPETSPEP and DPFPASPEP. Generally, the lower the percentage of students, the less the district spends.