-
Notifications
You must be signed in to change notification settings - Fork 2
/
sinasc_census_explore.R
150 lines (123 loc) · 5.14 KB
/
sinasc_census_explore.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
source("_fns.R")
library(dplyr)
library(ggplot2)
library(ggthemes)
load("data/artifacts/muni_census_ga.Rdata")
##
##---------------------------------------------------------
ggplot(filter(brthwt_inc, n >= 10 & !is.na(mean_bwt)), aes(mean_inc, mean_bwt)) +
geom_point(alpha = 0.5) +
geom_smooth() +
geom_abline(slope = 0, intercept = log10(2500), linetype = 2, alpha = 0.7) +
scale_x_continuous(trans = "log10", breaks = c(100, 300, 800, 2000)) +
facet_wrap(~ year) +
theme_bw() +
labs(
title = "Mean birthweight vs. mean income for each municipality by census year",
x = "Mean monthly income (R$)",
y = "Mean birth weight (g)")
# ggplot(filter(brthwt_inc, n >= 100), aes(prop_4mw, prop_low_bwt)) +
# geom_point(alpha = 0.5) +
# geom_smooth() +
# facet_wrap(~ year) +
# theme_bw()
##
##---------------------------------------------------------
ggplot(brthwt_inc_ga, aes(mean_inc, mean_bwt)) +
geom_point(alpha = 0.15) +
geom_smooth(method = "loess", span = 1, se = FALSE) +
geom_abline(slope = 0, intercept = log10(2500), linetype = 2, alpha = 0.7) +
scale_x_continuous(trans = "log10", breaks = c(100, 300, 800, 2000)) +
scale_y_continuous(trans = "log10", breaks = c(500, 1000, 1500, 2500, 4000)) +
facet_grid(year ~ gest_weeks) +
theme_bw() +
labs(
title = "Mean birthweight vs. mean income for each municipality by gestational age at birth and census year",
x = "Mean monthly income (R$)",
y = "Mean birth weight (g)")
## just 2010 and no "Less than 22 weeks"
ggplot(filter(brthwt_inc_ga, gest_weeks != "Less than 22 weeks" & year == 2010),
aes(mean_inc, mean_bwt)) +
geom_point(alpha = 0.15) +
geom_smooth(method = "loess", span = 1, se = FALSE) +
geom_abline(slope = 0, intercept = log10(2500), linetype = 2, alpha = 0.7) +
scale_x_continuous(trans = "log10", breaks = c(100, 300, 800, 2000)) +
scale_y_continuous(trans = "log10", breaks = c(500, 1000, 1500, 2500, 4000)) +
facet_grid(~ gest_weeks) +
theme_bw() +
labs(
title = "Mean birthweight vs. mean income for each municipality by gestational age at birth",
x = "Mean monthly income (R$)",
y = "Mean birth weight (g)")
## z-scores
library(growthstandards)
levels(brthwt_inc_ga$gest_weeks)
tmp <- brthwt_inc_ga %>%
filter(! gest_weeks %in% c("Less than 22 weeks", "42 weeks and more") & year == 2010) %>%
mutate(gest_weeks2 = as.character(gest_weeks))
tmp$gest_weeks2 <- recode(tmp$gest_weeks2,
"22-27 weeks" = 24.5,
"28-31 weeks" = 29.5,
"32-36 weeks" = 34,
"37-41 weeks" = 39
)
tmp$z <- igb_wtkg2zscore(tmp$gest_weeks2 * 7, tmp$mean_bwt / 1000)
ggplot(tmp, aes(mean_inc, z)) +
geom_point(alpha = 0.15) +
geom_smooth(method = "loess", span = 1, se = FALSE) +
geom_abline(slope = 0, intercept = 0, linetype = 2, alpha = 0.7) +
scale_x_continuous(trans = "log10", breaks = c(100, 300, 800, 2000)) +
facet_grid(~ gest_weeks) +
theme_bw() +
labs(
# title = "Birth weight for gestational age z-score vs. mean income for each municipality by gestational age at birth and census year",
x = "Mean monthly income (R$)",
y = "Approximate birth weight for gestational age z-score")
# ggplot(brthwt_inc_ga, aes(prop_4mw, prop_low_bwt)) +
# geom_point(alpha = 0.5) +
# geom_smooth(method = "loess", se = FALSE) +
# facet_grid(year ~ gest_weeks) +
# theme_bw() +
# labs(
# title = "Poverty vs. low birth weight for every municipality / gestational age at birth combination",
# x = "Proportion with household income < 1/4 minimum wage",
# y = "Proportion with low birth weight (g)")
##
##---------------------------------------------------------
filter(ga_deliv_year_inc, !is.na(income_bin)) %>%
ggplot(aes(x = birth_year, y = perc)) +
geom_ribbon(aes(ymin = perc - 1.96 * pse, ymax = perc + 1.96 * pse, fill = deliv_type),
alpha = 0.3) +
geom_point(aes( color = deliv_type), show.legend = FALSE) +
geom_line(aes( color = deliv_type), show.legend = FALSE) +
facet_wrap(~ gest_weeks + income_bin, scales = "free_y") +
facet_grid(gest_weeks ~ income_bin, scales = "free_y") +
labs(
x = "Birth Year",
y = "Percent in group (delivery type and gestantional age) by year",
fill = "Delivery type") +
theme_bw() +
guides(fill = guide_legend(override.aes = list(alpha = 1))) +
scale_fill_tableau() +
scale_color_tableau()
# filter(brthwt_inc_ga, prop_low_bwt > 0.95 & prop_4mw < 0.05 & gest_weeks == "22-27 weeks")
# tmp <- filter(snsc, gest_weeks == "22-27 weeks" & birth_year == 2011 & m_muni_code == 410690)
# table(tmp$brthwt_g < 1800)
##
##---------------------------------------------------------
# brthwt_muni_deliv_year2 <- brthwt_muni_deliv_year %>%
# filter(birth_year %in% c(2001, 2011)) %>%
# mutate(year = birth_year - 1) %>%
# filter(!is.na(deliv_type) & n >= 100)
# brthwt_inc2 <- left_join(brthwt_muni_deliv_year2, muni_inc2, by = c(m_muni_code = "muni_code", year = "year"))
# ggplot(brthwt_inc2, aes(mean_inc, mean_bwt)) +
# geom_point(alpha = 0.5) +
# geom_smooth() +
# scale_x_log10() +
# facet_wrap(~ year) +
# theme_bw()
# ggplot(brthwt_inc2, aes(prop_4mw, prop_low_bwt)) +
# geom_point(alpha = 0.5) +
# geom_smooth() +
# facet_grid(deliv_type ~ year) +
# theme_bw()