Skip to content

epi_slide behavior when not all data is available #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jacobbien opened this issue Nov 2, 2021 · 2 comments
Closed

epi_slide behavior when not all data is available #21

jacobbien opened this issue Nov 2, 2021 · 2 comments

Comments

@jacobbien
Copy link
Contributor

It would be nice for the user to have control over how sliding should operate when not all of the data is available (and for the documentation to describe what happens in this case). E.g., for the first 6 days present in an epi_tibble, should a 7-day rolling average return NA or return an average of the days that are available? It appears to currently do the latter. For example, see the first example in the slide vignette:

x %>%
  group_by(geo_value) %>%
  epi_slide(slide_fun = ~ Mean(.x$cases), n = 7) %>%
  head(10)

## # A tibble: 10 × 4
##    geo_value time_value cases slide_value
##    <chr>     <date>     <dbl>       <dbl>
##  1 ca        2020-06-01  2360       2360 
##  2 ca        2020-06-02  2372       2366 
##  3 ca        2020-06-03  2214       2315.
##  4 ca        2020-06-04  3011       2489.
##  5 ca        2020-06-05  3025       2596.
##  6 ca        2020-06-06  3046       2671.
##  7 ca        2020-06-07  2404       2633.
##  8 ca        2020-06-08  2385       2637.
##  9 ca        2020-06-09  2700       2684.
## 10 ca        2020-06-10  3208       2826.
@ryantibs
Copy link
Member

Thanks @jacobbien, good point. This would just be a matter of setting complete = TRUE (versus complete = FALSE, the default) in the call to the underlying slide function from slider, see documentation here.

And this could just be passed through the additional arguments ... in epi_slide(). See here for confirmation that those additional arguments get passed right to the underlying slide function.

So this is all functional already, but we should document it, and also probably demo it in the vignette.

Also, should we make the treatment here uniform across other slide utilities in the epitools package? For example, pct_change() is to report NA when the window isn't big enough (this is implemented on the side of the function that gets slid, itself, rather than through complete = TRUE; see here).

@ryantibs
Copy link
Member

Addressed in my commits on top of #28. There is an explicit complete flag in the call to epi_slide().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants