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

Proposal for new func to calculate epiweek and epiyear #492

Closed
rbalshaw opened this issue Nov 7, 2016 · 6 comments
Closed

Proposal for new func to calculate epiweek and epiyear #492

rbalshaw opened this issue Nov 7, 2016 · 6 comments

Comments

@rbalshaw
Copy link

rbalshaw commented Nov 7, 2016

The epiweek function takes a scalar x or vector x and returns the numeric epiweek for that date.

x can be entered as in any format recognized by lubridate's isoweek i.e., a date-time object. Must be a POSIXct, POSIXlt, Date, chron, yearmon, yearqtr, zoo, zooreg, timeDate, xts, its, ti, jul, timeSeries, or fts object
Here is the "definition" I've been working from (this defines both week and year).

The first epi week of the year ends, by definition, on the first Saturday of January, as long as it falls at least four days into the month. Each epi week begins on a Sunday and ends on a Saturday.

This can be achieved by simple change to isoweek and isoyear.

epiweek is based on isoweek from lubridate. The difference is in dn, where we add +6 here and +4 in isoweek because here we want to know where first Sat falls rather than first Thurs as in isoweek.

epiweek <- function(x)
{
require(lubridate)
xdate <- make_datetime(year(x), month(x), day(x))
dn <- 1 + (wday(xdate) + 6)%%7
nth <- xdate + ddays(4 - dn)
jan1 <- make_datetime(year(nth), 1, 1)
1L + as.integer(difftime(nth, jan1, units = "days")) %/% 7L
}

epiyear <- function(x)
{
require(lubridate)
xdate <- make_datetime(year(x), month(x), day(x))
dn <- 1 + (wday(xdate) + 6)%%7
nth <- xdate + ddays(4 - dn)
year(nth)
}

@vspinu
Copy link
Member

vspinu commented Nov 20, 2016

So it's exactly as isoweek but the week starts on Sunday?

@vspinu
Copy link
Member

vspinu commented Nov 20, 2016

duplicate of #256.

@vspinu vspinu closed this as completed in f53a618 Nov 20, 2016
@rbalshaw
Copy link
Author

Thank you, gentlemen.

Rob

On Nov 20, 2016, at 4:53 AM, Vitalie Spinu <notifications@github.commailto:notifications@github.com> wrote:

Closed #492#492 via f53a618f53a618.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHubhttps://github.com//issues/492#event-865600836, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AS8Q__ajQaaE0NwyWNJT5l7XXlhwJebJks5rAEK_gaJpZM4Krgzq.

@chrismerkord
Copy link

Epidemiological weeks begin on Sunday in the U.S. and are used by the CDC and various state agencies. But in most of the rest of the world, epi weeks begin on Monday and are therefore equivalent to iso weeks. The World Health Organization and pretty much every other international organization, and most countries other than the US (as far as I know) use this ISO standard for epidemiological weeks.

I would like to see one of two things happen:

  1. add something to the documentation explicitly stating this is the US/CDC implementation, not the ISO/WHO implementation.
    OR
  2. add an argument to the function allowing the user to choose between these two options.

Let me know what you think. I'd be happy to work on a solution and submit a pull request.

@rbalshaw
Copy link
Author

rbalshaw commented Jul 6, 2017 via email

@vspinu
Copy link
Member

vspinu commented Jul 8, 2017

Please open a new issue for this. Would adding week_start option as in wday help?

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

3 participants