Skip to content
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

growth_rate() gives hard error in corner cases #605

Open
dajmcdon opened this issue Feb 11, 2025 · 0 comments
Open

growth_rate() gives hard error in corner cases #605

dajmcdon opened this issue Feb 11, 2025 · 0 comments

Comments

@dajmcdon
Copy link
Contributor

The problem seems to be "constant zero" which should probably just be caught. Suggest we return the same result as with all 1's.

library(epiprocess)
#> Loading required package: epidatasets
#> Registered S3 method overwritten by 'tsibble':
#>   method               from 
#>   as_tibble.grouped_df dplyr
#> 
#> Attaching package: 'epiprocess'
#> The following object is masked from 'package:stats':
#> 
#>     filter

am_samoa <- covid_case_death_rates %>% 
  filter(geo_value == "as")
growth_rate(am_samoa$death_rate)
#> Error in stats::approx(x, g, x0): need at least two non-NA values to interpolate

am_samoa
#> An `epi_df` object, 366 x 4 with metadata:
#> * geo_type  = state
#> * time_type = day
#> * as_of     = 2023-03-10
#> 
#> # A tibble: 366 × 4
#>    geo_value time_value case_rate death_rate
#>  * <chr>     <date>         <dbl>      <dbl>
#>  1 as        2020-12-31         0          0
#>  2 as        2021-01-01         0          0
#>  3 as        2021-01-02         0          0
#>  4 as        2021-01-03         0          0
#>  5 as        2021-01-04         0          0
#>  6 as        2021-01-05         0          0
#>  7 as        2021-01-06         0          0
#>  8 as        2021-01-07         0          0
#>  9 as        2021-01-08         0          0
#> 10 as        2021-01-09         0          0
#> # ℹ 356 more rows
all(am_samoa$death_rate == 0)
#> [1] TRUE

# works
growth_rate(rep(1, 100))
#>   [1]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
#>  [26]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
#>  [51]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
#>  [76]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 NA

Created on 2025-02-11 with reprex v2.1.1

dajmcdon added a commit to cmu-delphi/epipredict that referenced this issue Feb 11, 2025
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

1 participant