dss-hmi / suicide-prevention-2019

Projects evaluates change in suicide morbidity and mortality rates among youth (10-24) in relationship to the GLS suicide prevention program in selected Florida counties.
GNU General Public License v2.0
0 stars 1 forks source link

Graph 1a Highlight Slopes #8

Open mmmmtoasty19 opened 4 years ago

mmmmtoasty19 commented 4 years ago

@andkov any idea how we can pull the slope out of the geom_smooth, or generate our own slope. If we have that data then highlighting is easy. I have spent about 2 hours trying to figure this one out and I keep struggling

mmmmtoasty19 commented 4 years ago

Please see my newest commit, I have a solution, but its not the prettiest.

andkov commented 4 years ago

sorry, @mmmmtoasty19 , for not replying fast enough. You have found the solution I would recommend

  mutate(model = purrr::map(data, age_model)) %>% 
  unnest(data) %>% 
  mutate(slope = purrr::map(model,`[`, "coefficients")
         ,slope = purrr::map(slope, unlist)
         ,slope = as.numeric(purrr::map(slope,2))) %>% 
  ungroup ()

I don't think there is an easier way to get a slope. Besides, this is a more transparent solution, as it captures these estimates. Also think about other parameters that might be useful in classifying the trajectory of individual groups, such as the total amount of change in the observed period of time. A slope may be just the easiest way of quantify change, we may need to develop a more nuanced measure and in that case, creating a separate data frame that captures these features of a group is the way to go.