These updated data from April 13 have fixed two prior issues: one was the persistence of a pregnant state through life…in other words pregnancy not being reset after birth resulting in increasing Crude Birth Rate. The second was the deterministic rather than stochastic assignment of PTB resulting in only those exceeding a threshold value on stress ever being eligible for preterm birth. Narjes has fixed each of these. So these results pick up from CBR and PTB and continue on to look at STI’s, stillbirth, DM, etc.
library(dplyr)
library(DBI)
library(ggplot2)
con <- dbConnect(RSQLite::SQLite(), 'DATA/abm1.sqlite')
dbListTables(con)
## [1] "abm_m1" "abm_m2" "abm_m3" "abm_m4"
## [5] "sqlite_stat1" "sqlite_stat4"
# abm_m4 is the current round of results
‘GestationalAge’ is coded like this:
a3 <- tbl(con, 'abm_m4') %>%
filter(Generation %in% c(1,2,3,4,5)) %>%
mutate(Pregnant = ifelse(GestationalAge == 100, 0, 1)) %>%
group_by(Age, Race, SocialClass) %>%
summarize(CBR = mean(Pregnant)) %>%
collect()
# CBR by race
g <- ggplot(a3, aes(x = Age, y = CBR, group = Race, color = Race))
g + geom_smooth() + scale_x_continuous(limits = c(13,50)) +
scale_y_continuous(limits = c(0, .15)) +
ggtitle('Crude birth rate by race')
# CBR by class
g <- ggplot(a3, aes(x = Age, y = CBR, group = SocialClass, color = SocialClass))
g + geom_smooth() + scale_x_continuous(limits = c(13,50)) +
scale_y_continuous(limits = c(0, .15)) +
ggtitle('Crude birth rate by SES')
a3b <- tbl(con, 'abm_m4') %>%
filter(Generation %in% c(1,2,3,4,5),
Parity %in% c(0,1,2,3,4)) %>%
mutate(Pregnant = ifelse(GestationalAge == 100, 0, 1)) %>%
group_by(Age, Race, Parity) %>%
summarize(CBR = mean(Pregnant)) %>%
collect()
# CBR by Parity (stratify on Race)
g <- ggplot(a3b, aes(x = Age, y = CBR, group = factor(Parity), color = factor(Parity)))
g + geom_smooth() + facet_grid(.~Race) +
scale_x_continuous(limits = c(13,50)) +
scale_y_continuous(limits = c(0, .15)) +
ggtitle('Crude birth rate by parity')
a4 <- tbl(con, 'abm_m4') %>%
filter(Generation %in% c(1,2,3,4,5),
GestationalAge != 100) %>%
mutate(PTB = ifelse(GestationalAge == 36, 1, 0)) %>%
group_by(Race, SocialClass, Age) %>%
summarise(PTBr = mean(PTB, na.rm = T)) %>%
collect()
g <- ggplot(a4, aes(x = Age, y = PTBr, group = Race, color = Race))
g + geom_smooth() + ggtitle('%PTB by Age and Race')
g <- ggplot(a4, aes(x = Age, y = PTBr, group = SocialClass, color = SocialClass))
g + geom_smooth() + ggtitle('%PTB by Age and SES')
RSQLite::initExtension(con) # this extensions allows stdev, median queries in SQLite
a4.1 <- tbl(con, 'abm_m4') %>%
filter(Generation %in% c(1,2,3,4,5),
GestationalAge != 100) %>%
mutate(PTB = ifelse(GestationalAge == 36, 1, 0)) %>%
select(PTB, AverageStressScore, LQ, Race, SocialClass) %>%
collect()
g <- ggplot(a4.1, aes(x = factor(PTB), y = AverageStressScore, fill = factor(PTB)))
g + geom_boxplot(width = 0.5) +
facet_grid(~Race) +
theme_bw() +
ggtitle('Stress score by PTB & Race')
g + geom_boxplot(width = 0.5) +
facet_grid(~SocialClass) +
theme_bw() +
ggtitle('Stress score by PTB & Social Class')
Here I got confused…Is there an indicator for whether a child agent was herself born preterm? I think the GestationalAge variable represents the outcome of a mother-agents pregnancy rather than a child-agents own history.
a5 <- tbl(con, 'abm_m4') %>%
filter(Generation %in% c(1,2,3,4,5),
PregnancyOutcome != 'NotPregnant') %>%
group_by(Race, SocialClass) %>%
mutate(PTB = ifelse(GestationalAge == 36, 1, 0),
SB = ifelse(PregnancyOutcome == 'StillBirth', 1, 0),
ShortIPI = ifelse(IPI == 'ShortIPI', 1, 0)) %>%
summarize(PTBr = mean(PTB, na.rm = T),
SBr = mean(SB, na.rm = T),
IPIr = mean(ShortIPI, na.rm = T)) %>%
collect()
library(kableExtra)
knitr::kable(a5, digits = c(2,3,2)) %>%
kable_styling(bootstrap_options = c("striped", "hover"))
| Race | SocialClass | PTBr | SBr | IPIr |
|---|---|---|---|---|
| Black | Low | 0.21 | 0.01 | 0.143 |
| Black | Middle | 0.16 | 0.01 | 0.113 |
| Black | Upper | 0.10 | 0.01 | 0.104 |
| White | Low | 0.18 | 0.00 | 0.133 |
| White | Middle | 0.14 | 0.00 | 0.127 |
| White | Upper | 0.11 | 0.00 | 0.128 |
a6 <- tbl(con, 'abm_m4') %>%
filter(Generation %in% c(1,2,3,4,5)) %>%
group_by(Race, SocialClass, Age) %>%
summarize(STIr = mean(STI, na.rm = T)) %>%
collect()
g <- ggplot(a6, aes(x = Age, y = STIr, group = Race, color = Race))
g + geom_smooth() + facet_grid(.~SocialClass) +
scale_x_continuous(limits = c(13,50)) +
ggtitle('STI rate by race, class, age')