reconhub / incidence

☣:chart_with_upwards_trend::chart_with_downwards_trend:☣ Compute and visualise incidence
https://reconhub.github.io/incidence
Other
58 stars 13 forks source link

Use any week standard #110

Closed zkamvar closed 5 years ago

zkamvar commented 5 years ago

This update will fix #89 (which is the resurrection of #24) and fix #67

Installation:

remotes::install_github("reconhub/incidence#110")

Here are the changes:

Still needs to be done:

Example

library('incidence')
dat <- outbreaks::ebola_sim$linelist$date_of_onset
print(iso <- incidence(dat, "isoweek"))
#> <incidence object>
#> [5888 cases from days 2014-04-07 to 2015-04-27]
#> [5888 cases from ISO weeks 2014-W15 to 2015-W18]
#> 
#> $counts: matrix with 56 rows and 1 columns
#> $n: 5888 cases in total
#> $dates: 56 dates marking the left-side of bins
#> $interval: 1 week
#> $timespan: 386 days
#> $cumulative: FALSE
plot(iso)

plot(iso, labels_week = FALSE)


print(cdc <- incidence(dat, "MMWRweek"))
#> <incidence object>
#> [5888 cases from days 2014-04-06 to 2015-04-26]
#> [5888 cases from MMWR weeks 2014-W15 to 2015-W17]
#> 
#> $counts: matrix with 56 rows and 1 columns
#> $n: 5888 cases in total
#> $dates: 56 dates marking the left-side of bins
#> $interval: 1 week
#> $timespan: 386 days
#> $cumulative: FALSE
plot(cdc, labels_week = FALSE)

print(sat <- incidence(dat, "Saturday week"))
#> <incidence object>
#> [5888 cases from days 2014-04-05 to 2015-04-25]
#> [5888 cases from (Saturday) weeks 2014-W14 to 2015-W17]
#> 
#> $counts: matrix with 56 rows and 1 columns
#> $n: 5888 cases in total
#> $dates: 56 dates marking the left-side of bins
#> $interval: 1 week
#> $timespan: 386 days
#> $cumulative: FALSE
plot(sat, labels_week = FALSE)

print(sat2 <- incidence(dat, "2 Saturday weeks"))
#> <incidence object>
#> [5888 cases from days 2014-04-05 to 2015-04-18]
#> [5888 cases from (Saturday) weeks 2014-W14 to 2015-W16]
#> 
#> $counts: matrix with 28 rows and 1 columns
#> $n: 5888 cases in total
#> $dates: 28 dates marking the left-side of bins
#> $interval: 2 weeks
#> $timespan: 379 days
#> $cumulative: FALSE
plot(sat2, labels_week = FALSE)

Created on 2019-03-12 by the reprex package (v0.2.1)

zkamvar commented 5 years ago

It would also be nice if @aspina7 and @jakobschumacher could see if this works for them

zkamvar commented 5 years ago

If we want to get this onto CRAN relatively soon, this also needs to be merged before the end of the week so that we can submit it before the 20th.

zkamvar commented 5 years ago

For the print info for incidence object, I propose that the actual date range of observational cases is also printed. Currently only the date range used for computing the bin size is printed. This info will remind the user the difference between the two date ranges.

Taking print(iso <- incidence(dat, "isoweek")) as an illustration, I expect the following print info. I believe this print info is much clear.

#> <incidence object>
#> [5888 cases observed from days 2014-04-07 to 2015-04-30]
#> [weekly bins (or bin size in days) computed from days 2014-04-07 to 2015-04-27]
#> [weekly bins computed from ISO weeks 2014-W15 to 2015-W18]

That's not a bad idea, but this is currently not possible since the dates are binned before they are placed in the object. This also happens if the user uses any binning higher than 1 day. To achieve the suggested behaviour, we would need to add the original date range as another item or attribute in the incidence object. I would say that this is a bit out of scope of the PR, but would be a good suggestion to add to the issue tracker wishlist

zkamvar commented 5 years ago

Not convinced its worth having named intervals, why not just have start day and specify how long you want it to be? e.g. monday and 7 days...

The users can already specify something like “2 Monday weeks” if they want to. Implementing the epi, mmwr, and iso keywords is an extra.

The thing is, it’s really not much overhead for this implementation and it aligns with existing methods in the lubridate, ISOweek, and EPIweek packages.

Sent from my iPhone

On Mar 13, 2019, at 08:58, Alex Spina notifications@github.com wrote:

@aspina7 commented on this pull request.

In R/incidence.R:

+#' 2016: +#' +#' - interval = "2 monday weeks" (Monday 2016-09-05) +#' - interval = "1 tue week" (Tuesday 2016-08-30) +#' - interval = "1 Wed week" (Wednesday 2016-08-31) +#' - interval = "1 Thursday week" (Thursday 2016-09-01) +#' - interval = "1 F week" (Friday 2016-09-02) +#' - interval = "1 Saturday week" (Saturday 2016-09-03) +#' - interval = "Sunday week" (Sunday 2016-09-04) +#' +#' It's also possible to use something like "3 weeks: Saturday"; In addition, +#' there are keywords reserved for specific days of the week: +#'
+#' - interval = "week", standard = TRUE (Default, Monday) +#' - interval = "ISOweek" (Monday) +#' - interval = "EPIweek" (Sunday) Not convinced its worth having named intervals, why not just have start day and specify how long you want it to be? e.g. monday and 7 days...

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.