-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlongitudinal.Rmd
67 lines (59 loc) · 1.61 KB
/
longitudinal.Rmd
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
---
title: Longitudinal(ish) model
---
```{r}
library(dplyr)
library(RSQLite)
library(ggplot2)
```
```{r cache=TRUE}
con <- dbConnect(drv = SQLite(), dbname = "./cleaned/disag.db")
dbListTables(con)
dfDisag <- dbGetQuery(con, "SELECT * FROM disag")
```
```{r cache=TRUE}
dfDisag <- dfDisag %>%
mutate(num_glp = as.numeric(num_glp)
, pct_glp = num_glp / num_tested
, SchoolYearInt = as.integer(substr(school_year, 1, 4)))
```
```{r}
dfLongAll <- dfDisag %>%
filter(subgroup == "ALL"
, type == "ALL"
, subject == "ALL"
, grade == 'ALL') %>%
select(school_code, school_year, grade_span, pct_glp) %>%
arrange(school_code, grade_span, school_year)
```
```{r}
dfVarianceAll <- dfLongAll %>%
filter(!is.na(pct_glp)) %>%
group_by(school_year) %>%
summarise(N = n()
, Mean = mean(pct_glp)
, Variance = var(pct_glp)) %>%
mutate(StdDev = sqrt(Variance))
```
```{r}
dfLongGrade <- dfDisag %>%
filter(subgroup == "ALL"
, type == "ALL"
, grade %in% c('03', '04', '05')
, subject == "EOG") %>%
select(school_code, SchoolYearInt, grade, pct_glp) %>%
mutate(grade = as.integer(grade)
, OriginYear = SchoolYearInt - (grade - 3)) %>%
arrange(school_code, OriginYear, grade) %>%
group_by(school_code, OriginYear) %>%
mutate(glp_diff = pct_glp - dplyr::lag(pct_glp)) %>%
filter(!is.na(glp_diff))
```
```{r}
dfVarianceGrade <- dfLongGrade %>%
group_by(SchoolYearInt) %>%
summarise(N = n()
, Mean = mean(glp_diff)
, Variance = var(glp_diff)) %>%
mutate(StdDev = sqrt(Variance))
```