Skip to content

Commit

Permalink
Merge pull request #45 from dss-hmi/master
Browse files Browse the repository at this point in the history
update dev branch
  • Loading branch information
mmmmtoasty19 authored Jun 8, 2020
2 parents 332c970 + 82755a7 commit 16ea355
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 41 deletions.
50 changes: 42 additions & 8 deletions analysis/florida-suicide-10_24/fl-suicide-10_24.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ ggplot2::theme_set(

# ---- load-data ---------------------------------------------------------------
# data prepared by "./manipulation/9-aggregator.R" combining population estimates and suicide counts

ds_population_suicide <- readr::read_csv(path_file_input)
ds_population_suicide_2 <- readr::read_rds("./data-unshared/derived/9-population-suicide-2.rds")


# map of florida counties
florida_counties_map <- ggplot2::map_data("county") %>%
Expand All @@ -58,9 +61,9 @@ florida_counties_map <- ggplot2::map_data("county") %>%
, ~stringr::str_replace_all(
.
,c(
"de soto" = "desoto"
,"st johns" ="saint johns"
,"st lucie" = "saint lucie"
"de soto" = "Desoto"
,"st johns" ="Saint Johns"
,"st lucie" = "Saint Lucie"
)
)
) %>% tibble::as_tibble()
Expand Down Expand Up @@ -310,16 +313,48 @@ g3
# Can we see the spike in mortality at 13-14 years of age?
# For that we need to view by year mortality event?

d4 <- ds_suicide_by_age %>%
# d4 <- ds_suicide_by_age %>%

d4 <- ds_population_suicide_2 %>%
mutate(age = as.integer(age)) %>%
filter(age %in% c(10:40)) %>%
filter(age %in% c(10:85)) %>%
filter(year %in% 2006:2018) %>%
group_by(year, age) %>%
summarize(
n_suicide = sum(count, na.rm = T)
n_suicide = sum(n_suicides, na.rm = T)
) %>%
ungroup()
d4 %>% glimpse()



g4 <- d4 %>%
ggplot(aes(x = age, y = n_suicide))+
geom_smooth(method = "lm", se= F, size = 1,color = "salmon")+
geom_smooth(method = "loess", se= F, size = 1,color = "cyan3")+
ggpmisc::stat_poly_eq(
formula = y ~ + x
,aes(label = paste(..eq.label.., ..rr.label.., sep = "~~~"))
,parse = TRUE, color = "salmon"
# , vjust = 7
)+
geom_boxplot(aes( group = age), fill = NA)+
scale_x_continuous(breaks = seq(10,85,5))+
# scale_y_continuous(breaks = seq(0,100,10))+
geom_vline(xintercept = 24.5, size = 4, alpha = .1)+
geom_vline(xintercept = 17.5, size = 1, linetype = "dashed", color = "grey80")+
theme(
panel.grid.minor = element_blank()
)+
labs(
title = "Suicide events among person of the same age (2006-2018)"
,x = "Age in years", y = "Count of suicides (all causes)"
)
g4

# ---- q1b-4 --------------
g4 <- d4 %>%
dplyr::filter(age %in% 10:40) %>%
ggplot(aes(x = age, y = n_suicide))+
geom_smooth(method = "lm", se= F, size = 1,color = "salmon")+
geom_smooth(method = "loess", se= F, size = 1,color = "cyan3")+
Expand All @@ -342,8 +377,7 @@ g4 <- d4 %>%
,x = "Age in years", y = "Count of suicides (all causes)"
)
g4

# ---- q1b-4 -------------------------------------
# ---- q1b-5 -------------------------------------
# among 10-24 the increase across age is very linear

g5 <- d4 %>%
Expand Down
4 changes: 3 additions & 1 deletion analysis/florida-suicide-10_24/fl-suicide-10_24.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ We see a marked spike in deaths during the 17 to 18 transition.
It appears the majority of deaths in 10-14 groups could be attributed to 13 and 14 year olds.
There appears to be a plateau following the age 25 for the next 15 years, which makes theoretical sence: after the turmoils of coming out of age and young adulthood, there life acquires a more stable character.

Also note, that when examining the trends within the `10-24` age group, the relationship bewtween the age and the suicide mortality is very well summarized by a linear model ($R^2 = .85$)
```{r q1b-4, echo=TRUE, fig.height=7, fig.width=10, out.width = "900px", message=FALSE, results='show',cache=TRUE}
```
Also note, that when examining the trends within the `10-24` age group, the relationship bewtween the age and the suicide mortality is very well summarized by a linear model ($R^2 = .85$)
```{r q1b-5, echo=TRUE, fig.height=7, fig.width=10, out.width = "900px", message=FALSE, results='show',cache=TRUE}
```

# Q2 - Yearly Breakdowns

Expand Down
110 changes: 78 additions & 32 deletions manipulation/9-aggregator-2.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ds_suicide <- ds_suicide %>%
)


# --- join-data
# ---- join-data ---------------

ds0 <- ds_population %>%
left_join(ds_suicide, by = c("year"
Expand All @@ -62,6 +62,49 @@ ds0 <- ds_population %>%
,gender = forcats::as_factor(gender)
)

ds0 %>% readr::write_rds("./data-unshared/derived/9-population-suicide-2.rds", compress = "gz")


# ----- test-data ----------------
# boxplot with years as obs for each age bin
ds0 %>% glimpse()
d4 <- ds0 %>%
mutate(age = as.integer(age)) %>%
filter(age %in% c(10:85)) %>%
filter(year %in% 2006:2018) %>%
group_by(year, age) %>%
summarize(
n_suicide = sum(n_suicides, na.rm = T)
) %>%
ungroup()
d4 %>% glimpse()



g4 <- d4 %>%
ggplot(aes(x = age, y = n_suicide))+
geom_smooth(method = "lm", se= F, size = 1,color = "salmon")+
geom_smooth(method = "loess", se= F, size = 1,color = "cyan3")+
ggpmisc::stat_poly_eq(
formula = y ~ + x
,aes(label = paste(..eq.label.., ..rr.label.., sep = "~~~"))
,parse = TRUE, color = "salmon"
# , vjust = 7
)+
geom_boxplot(aes( group = age), fill = NA)+
scale_x_continuous(breaks = seq(10,85,5))+
# scale_y_continuous(breaks = seq(0,100,10))+
geom_vline(xintercept = 24.5, size = 4, alpha = .1)+
geom_vline(xintercept = 17.5, size = 1, linetype = "dashed", color = "grey80")+
theme(
panel.grid.minor = element_blank()
)+
labs(
title = "Suicide events among person of the same age (2006-2018)"
,x = "Age in years", y = "Count of suicides (all causes)"
)
g4

# ---- compute-rate-function ----

compute_rate <- function(
Expand Down Expand Up @@ -103,40 +146,43 @@ compute_rate <- function(
ds_example <- ds0 %>% compute_rate(grouping_frame = c("county", "year"))
ds_example_w <- ds0 %>% compute_rate(grouping_frame = c("county", "year"), wide = TRUE)

# ---- save-to-disk ---------

# ---- store-data ----

ls_grouping_frame <- list(
c("county","year" )
,c("county","year","gender" )
,c("county","year" ,"race_ethnicity" )
,c("county","year" ,"age")
,c("county","year","gender","race_ethnicity" )
,c("county","year" ,"race_ethnicity","age")
,c("county","year","gender" ,"age")
,c("county","year","gender","race_ethnicity","age")
,c( "year" )
,c( "year","gender" )
,c( "year" ,"race_ethnicity" )
,c( "year" ,"age")
,c( "year","gender","race_ethnicity" )
,c( "year" ,"race_ethnicity","age")
,c( "year","gender" ,"age")
,c( "year","gender","race_ethnicity","age")
)



#loop through all combos of grouping frame to store data

for(i in seq_along(ls_grouping_frame)){
path_to_folder <- "./data-unshared/derived/rate/"
frame_i <- ls_grouping_frame[[i]]
file_name <- paste0(path_to_folder, paste0(frame_i, collapse = "-"),".rds")
d_computed <- ds0 %>% compute_rate(grouping_frame = frame_i)

d_computed %>% readr::write_rds(file_name, compress = "gz")
}
# ---- store-data ----
#
# ls_grouping_frame <- list(
# c("county","year" )
# ,c("county","year","gender" )
# ,c("county","year" ,"race_ethnicity" )
# ,c("county","year" ,"age")
# ,c("county","year","gender","race_ethnicity" )
# ,c("county","year" ,"race_ethnicity","age")
# ,c("county","year","gender" ,"age")
# ,c("county","year","gender","race_ethnicity","age")
# ,c( "year" )
# ,c( "year","gender" )
# ,c( "year" ,"race_ethnicity" )
# ,c( "year" ,"age")
# ,c( "year","gender","race_ethnicity" )
# ,c( "year" ,"race_ethnicity","age")
# ,c( "year","gender" ,"age")
# ,c( "year","gender","race_ethnicity","age")
# )
#
#
#
# #loop through all combos of grouping frame to store data
#
# for(i in seq_along(ls_grouping_frame)){
# path_to_folder <- "./data-unshared/derived/rate/"
# frame_i <- ls_grouping_frame[[i]]
# file_name <- paste0(path_to_folder, paste0(frame_i, collapse = "-"),".rds")
# d_computed <- ds0 %>% compute_rate(grouping_frame = frame_i)
#
# d_computed %>% readr::write_rds(file_name, compress = "gz")
# }


# store youth data
Expand Down

0 comments on commit 16ea355

Please sign in to comment.