knitr::opts_chunk$set(echo = TRUE)

library(ggplot2)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyr)
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v tibble  3.0.4     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.0
## v purrr   0.3.4
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(knitr)

#reading in merged Advanced Mathematics  File -- with only the columns needed

setwd("C:/Users/BlaiseSevier/Desktop/R Work")

fileAM <- "Advanced Mathematics.csv"

getwd()
## [1] "C:/Users/BlaiseSevier/Desktop/R Work"
AM.sch <- read.csv(fileAM)

### How to set your working directory 
## In quotation marks, ("C: /Users/BlaiseSevier/Desktop/R Work")

setwd("C:/Users/BlaiseSevier/Desktop/R Work")

els.k12 <- 5296851
nonel.k12 <- 45625438


#Total Number of Students in HS
tot_enrol_hs <- 14183488
#Total Number of Non-Els in HS
non.el.hs <- 13108063
#Total Number of LEP in HS 
tot_lep_hs <- 1075425 

CRDC Survey Information

For more information about the school form see: https://www2.ed.gov/about/offices/list/ocr/docs/2017-18-crdc-school-form.pdf.

TOT_MATHENR_ADVM_M Students Enrolled in Advanced Mathematics: Calculated Male Total TOT_MATHENR_ADVM_F Students Enrolled in Advanced Mathematics: Calculated Female Total SCH_MATHENR_ADVM_LEP_M Students Enrolled in Advanced Mathematics: LEP Male SCH_MATHENR_ADVM_LEP_F Students Enrolled in Advanced Mathematics: LEP Female

Change Code from 0s to 9s

#Code to change the -9s to 0s

AM.sch[AM.sch==-9]<-0

Advanced Mathematics

Non-English Learner Male Students Enrolled in Advanced Mathematics Courses

#Computes the total number of a non-English Learner male students in Advanced Mathematics courses

#dat$NonELM<- (dat$TOT_ENR_M - dat$TOT_LEPENR_M)

AM.sch$NonELM <- (AM.sch$TOT_MATHENR_ADVM_M - AM.sch$SCH_MATHENR_ADVM_LEP_M)

sum(AM.sch$NonELM)
## [1] 1089056
#There are 1,089,056 Non-English Learner Male Students Enrolled in Advanced Mathematics  

Non-English Learner Female Students in Advanced Mathematics

#Total female non-EL 
#dat$NonELF <-dat$TOT_ENR_F-dat$TOT_LEPENR_F

AM.sch$NonELF <- (AM.sch$TOT_MATHENR_ADVM_F - AM.sch$SCH_MATHENR_ADVM_LEP_F)
sum(AM.sch$NonELF)
## [1] 1179973
#There are 1,179,973 Non-English Learner Females Enrolled in Advanced Mathematics  courses.

Total Non ELs in Advanced Mathematics

#total non EL
#dat$NonEL<-dat$NonELF + dat$NonELM

AM.sch$NonEL <- AM.sch$NonELF + AM.sch$NonELM

non.el.AM <- sum(AM.sch$NonEL)
non.el.AM
## [1] 2269029
#There are  2,269,029 Non-English Learners Enrolled in Advanced Mathematics 

English Learners in Advanced Mathematics

English Learner Males in Advanced Mathematics

#Total Lep Male in Advanced Mathematics 

#dat$ELMGT <- dat$SCH_GTENR_LEP_M

AM.sch$ELM.AM <- AM.sch$SCH_MATHENR_ADVM_LEP_M

sum(AM.sch$SCH_MATHENR_ADVM_LEP_M)
## [1] 33936
sum(AM.sch$ELM.AM)
## [1] 33936
## There is 33,936 English Learner Males in Advanced Mathematics  

English Learner Females in Advanced Mathematics

#Total LEP Female in GT
#dat$ELFGT <- dat$SCH_GTENR_LEP_F

AM.sch$ELF.AM <- AM.sch$SCH_MATHENR_ADVM_LEP_F

sum(AM.sch$ELF.AM)
## [1] 30459
## There are 30,459 EL Females in Advanced Mathematics Classes 

Total English Learners in Advanced Mathematics

#dat$ELEnrol <- dat$TOT_LEPENR_M + dat$TOT_LEPENR_F

AM.sch$ELEnrolAM<- AM.sch$ELM.AM + AM.sch$ELF.AM

els.AM <- sum(AM.sch$ELEnrolAM)

sum(els.AM)
## [1] 64395
## There is 64,395 English learners in Advanced Mathematics   

Percentage of ELs and Non ELs in Advanced Mathematics Courses

## Percentage of English Learners in Advanced Math in Population of ELs in High School 

round(els.AM/tot_lep_hs*100,2)
## [1] 5.99
## Percentage of English Learners in Advanced Math in Population of

round(els.AM/els.k12*100,2)
## [1] 1.22
# Percentage of Non-ELs in Advanced Math in Population of non-ELs in High School 

round(non.el.AM/non.el.hs*100,2)
## [1] 17.31
round(non.el.AM/nonel.k12*100,2)
## [1] 4.97