Skip to content
/ lubridate Public

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
opened this issue Nov 7, 2016 · 6 comments
Closed

# Proposal for new func to calculate epiweek and epiyear #492

opened this issue Nov 7, 2016 · 6 comments

## Comments

### 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) } The text was updated successfully, but these errors were encountered:

### vspinu commented Nov 20, 2016

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

### vspinu commented Nov 20, 2016

 duplicate of #256.

closed this as completed in ``` f53a618 ``` Nov 20, 2016

### rbalshaw commented Nov 20, 2016

 Thank you, gentlemen. Rob On Nov 20, 2016, at 4:53 AM, Vitalie Spinu 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 commented Jul 6, 2017

 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: add something to the documentation explicitly stating this is the US/CDC implementation, not the ISO/WHO implementation. OR 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.

mentioned this issue Jul 6, 2017

### rbalshaw commented Jul 6, 2017 via email

 Agree - US CDC has set the definition of the “epiweek” while much of the rest of the world uses ISO standard. I would prefer option 2 with option 1 incorporated in the documentation. Thank you for pursuing this. Rob On Jul 6, 2017, at 3:07 PM, Chris Merkord > wrote: 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. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub<#492 (comment)>, or mute the thread.

### vspinu commented Jul 8, 2017

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

mentioned this issue Jul 10, 2017
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