I was looking at the labor participation rate in the US with the help of the FRED datasets PAYEMS and POPTOTUSA647NWDB. As you may expect, labor participation goes up and down through recessions and booms. In the figure, I'd like to indicate the local maxima.
My first approach is to visually select date cut-offs between the maxima and determine the maximum value between them
date_breaks <-
ymd(c(
19680101,
19750101,
19810101,
19920101,
20020101,
20100101,
20210101,
20300101
))
maxes <-
jobspop %>%
mutate(periods = cut(date, breaks = date_breaks)) %>%
group_by(periods) %>%
slice_max(workingpop, n = 1) %>%
ungroup() %>%
drop_na()
Although this approach works, it depends on me to select the correct cut-off dates. Are there better ways to detect local maxima automatically?
--edit-- This question was flagged because it seemed similar to others. My data is significantly more noisy than the example data in the proposed similar questions.
Reference - example dataframe
> jobspop
# A tibble: 756 x 4
date PAYEMS POPTOTUSA647NWDB workingpop
<date> <dbl> <dbl> <dbl>
1 1960-01-01 54274000 180671000 0.300
2 1960-02-01 54513000 180671000 0.302
3 1960-03-01 54454000 180671000 0.301
4 1960-04-01 54813000 180671000 0.303
5 1960-05-01 54475000 180671000 0.302
6 1960-06-01 54348000 180671000 0.301
7 1960-07-01 54306000 180671000 0.301
Complete code: https://github.com/robhanssen/econ-analysis/blob/main/scripts/jobs_report.r