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

cfr_rolling() fails when cumulative case number is 0 #97

Closed
Bisaloo opened this issue Oct 30, 2023 · 2 comments
Closed

cfr_rolling() fails when cumulative case number is 0 #97

Bisaloo opened this issue Oct 30, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@Bisaloo
Copy link
Member

Bisaloo commented Oct 30, 2023

This can arise in situation like this one:

library(cfr)

data("covid_data")
df_covid_uk <- covid_data[covid_data$country == "United Kingdom", ]

res <- cfr_rolling(
  data = df_covid_uk
)
#> Error in (function (x, n, p = 0.5, alternative = c("two.sided", "less", : 'n' must be a positive integer >= 'x'

df_covid_uk <- df_covid_uk |>
  subset(cumsum(cases) > 0)

res <- cfr_rolling(
  data = df_covid_uk
)
head(res)
#>   severity_mean severity_low severity_high
#> 1           1.0   0.02500000     1.0000000
#> 2           1.0   0.02500000     1.0000000
#> 3           1.0   0.02500000     1.0000000
#> 4           1.0   0.15811388     1.0000000
#> 5           0.1   0.01234853     0.3169827
#> 6           0.1   0.01234853     0.3169827

Created on 2023-10-30 with reprex v2.0.2

@pratikunterwegs pratikunterwegs self-assigned this Oct 30, 2023
@pratikunterwegs pratikunterwegs added the bug Something isn't working label Oct 30, 2023
@pratikunterwegs
Copy link
Collaborator

pratikunterwegs commented Oct 30, 2023

Thanks for noticing this - I'm proposing to fix this using the same logic as cfr_time_varying(), which works on this data out of the box. The fix would only run the binomial test for dates where deaths < cases AND cases > 0; estimates for all other dates would be NA.

@pratikunterwegs
Copy link
Collaborator

Fixed in #98

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants