-
Notifications
You must be signed in to change notification settings - Fork 207
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
Comments
So it's exactly as isoweek but the week starts on Sunday? |
duplicate of #256. |
Thank you, gentlemen. Rob On Nov 20, 2016, at 4:53 AM, Vitalie Spinu <[email protected]mailto:[email protected]> wrote: Closed #492#492 via f53a618f53a618. — |
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:
Let me know what you think. I'd be happy to work on a solution and submit a pull request. |
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 <[email protected]<mailto:[email protected]>> 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<https://github.com/notifications/unsubscribe-auth/AS8Q_5_P90Sad2kR94Bwb9a0JOTzWOIiks5sLVqbgaJpZM4Krgzq>.
|
Please open a new issue for this. Would adding |
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: