-
Notifications
You must be signed in to change notification settings - Fork 0
/
prep_opportunity_score.R
100 lines (94 loc) · 3.01 KB
/
prep_opportunity_score.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
library(edbuildmapr)
library(edbuildr)
library(educationdata)
library(tidyr)
library(dplyr)
library(ggplot2)
library(ggpubr)
library(readr)
df <- get_education_data(level = 'school-districts',
source = 'ccd',
topic = 'directory',
#subtopic = list('agency_type'),
filters = list(fips = 18,
year = 2021
),
add_labels = TRUE) |>
filter(
agency_type == "Regular local school district"
) |>
select(
leaid, lea_name, state_leaid, enrollment, urban_centric_locale, enrollment
)
#View(df)
df2 <- get_education_data(level = 'school-districts',
source = 'ccd',
topic = 'enrollment',
subtopic = list('race'),
filters = list(fips = 18,
year = 2021,
grade = 99
),
add_labels = TRUE) |>
select(leaid, race, enrollment) |>
pivot_wider(id_cols = leaid, names_from = race, values_from = enrollment) |>
mutate(urm_pct = 1 - (White / Total)) |>
select(leaid, urm_pct)
#View(df2)
districts_df <- left_join(df, df2, by = "leaid") |>
filter(leaid != 1800009) |>
select(leaid, lea_name, enrollment, urban_centric_locale, urm_pct) |>
arrange(leaid)
#View(districts_df)
total_rows <- nrow(districts_df)
split_rows <- total_rows %/% 3
df1 <- districts_df[1:split_rows, ]
df2 <- districts_df[(split_rows+1):(split_rows*2), ]
df3 <- districts_df[(split_rows*2+1):total_rows, ]
row.names(df1) <- NULL
row.names(df2) <- NULL
row.names(df3) <- NULL
write_csv(df1, file = "data/aj.csv")
write_csv(df2, file = "data/akaash.csv")
write_csv(df3, file = "data/maxim.csv")
#frl_frame <- masterpull(data_year = "2018", data_type = "geo") |>
# filter(State == "Indiana") |>
# select("leaid" = "NCESID", "frl_pct" = "FRL_rate")
#districts_df <- left_join(districts_df, frl_frame, by = "leaid")
#scatter_plot <- ggscatter(
# districts_df,
# "urm_pct",
# "frl_pct",
# size = "enrollment",
# color = "urban_centric_locale",
# add = "reg.line",
# add.params = list(color = "blue", fill = "lightgray"),
# conf.int = TRUE) +
# stat_cor(method = "pearson") +
# theme_pubr()
#scatter_plot
#scatter_plot2 <- ggboxplot(
# districts_df,
# "urban_centric_locale",
# "frl_pct",
# size = "enrollment",
# color = "urban_centric_locale",
# add = "reg.line",
# add.params = list(color = "blue", fill = "lightgray"),
# conf.int = TRUE) +
# stat_cor(method = "pearson") +
# theme_pubr()
# scatter_plot2
#
# scatter_plot3 <- ggboxplot(
# districts_df,
# "urban_centric_locale",
# "urm_pct",
# size = "enrollment",
# color = "urban_centric_locale",
# add = "reg.line",
# add.params = list(color = "blue", fill = "lightgray"),
# conf.int = TRUE) +
# stat_cor(method = "pearson") +
# theme_pubr()
# scatter_plot3