Browse Source

mmwr tweaks

tags/v0.7.0
boB Rudis 4 years ago
parent
commit
601179e949
No known key found for this signature in database GPG Key ID: 2A514A4997464560
4 changed files with 37 additions and 25 deletions
  1. +1
    -0
      NAMESPACE
  2. +0
    -25
      R/aaa.R
  3. +31
    -0
      R/mmwr-map.r
  4. +5
    -0
      man/mmwrid_map.Rd

+ 1
- 0
NAMESPACE View File

@ -6,6 +6,7 @@ export(geographic_spread)
export(hospitalizations)
export(ili_weekly_activity_indicators)
export(ilinet)
export(mmwrid_map)
export(pi_mortality)
export(state_data_providers)
export(surveillance_areas)


+ 0
- 25
R/aaa.R View File

@ -1,15 +1,3 @@
# THIS IS NOT EXPORTED FROM MMWRweek but I need it
# Find start date for a calendar year
#
# Finds the state date given a numeric calendar year
# @author Jarad Niemi \email{niemi@@iastate.edu}
.start_date = function(year) {
# Finds start state for this calendar year
jan1 = as.Date(paste(year, '-01-01', sep=''))
wday = as.numeric(MMWRweekday(jan1))
jan1 - (wday-1) + 7*(wday>4)
}
# CDC U.S. region names to ID map
.region_map <- c(national=3, hhs=1, census=2, state=5)
@ -40,16 +28,3 @@
"B (Yamagata Lineage)", "H3N2v")
# Week Starts
.tmp <- lapply(1962:2030, .start_date)
mapply(function(.x, .y) {
data_frame(
wk_start = seq(.tmp[[.x]], .tmp[[.y]], "1 week"),
wk_num = 1:length(wk_start)
) -> tmp
tmp[-nrow(tmp),]
}, 1:(length(.tmp)-1), 2:length(.tmp), SIMPLIFY=FALSE) -> .wk
.wk <- Reduce(rbind.data.frame, .wk)
.wk$mmwrid <- 1:nrow(.wk)

+ 31
- 0
R/mmwr-map.r View File

@ -0,0 +1,31 @@
# THIS IS NOT EXPORTED FROM MMWRweek but I need it
# Find start date for a calendar year
#
# Finds the state date given a numeric calendar year
# @author Jarad Niemi \email{niemi@@iastate.edu}
.start_date = function(year) {
# Finds start state for this calendar year
jan1 = as.Date(paste(year, '-01-01', sep=''))
wday = as.numeric(MMWRweekday(jan1))
jan1 - (wday-1) + 7*(wday>4)
}
# I discovered why 1962!: https://www.cdc.gov/mmwr/preview/mmwrhtml/su6004a9.htm
.tmp <- lapply(1962:2050, .start_date)
mapply(function(.x, .y) {
data_frame(
wk_start = seq(.tmp[[.x]], .tmp[[.y]], "1 week"),
wk_end = wk_start + 6,
year_wk_num = 1:length(wk_start)
) -> tmp
tmp[-nrow(tmp),]
}, 1:(length(.tmp)-1), 2:length(.tmp), SIMPLIFY=FALSE) -> mmwrid_map
mmwrid_map <- Reduce(rbind.data.frame, mmwrid_map)
mmwrid_map$mmwrid <- 1:nrow(mmwrid_map)
#' @title MMWR ID to Calendar Mappings
#' @name mmwrid_map
#' @export
NULL

+ 5
- 0
man/mmwrid_map.Rd View File

@ -0,0 +1,5 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mmwr-map.r
\name{mmwrid_map}
\alias{mmwrid_map}
\title{MMWR ID to Calendar Mappings}

Loading…
Cancel
Save