Skip to content

Commit

Permalink
- changing the default value of use epiweek to FALSE
Browse files Browse the repository at this point in the history
- epiweek and new week definitions updated
  • Loading branch information
lsbastos authored and rafalopespx committed Feb 14, 2024
1 parent 3c11f31 commit 8cce598
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 27 deletions.
36 changes: 26 additions & 10 deletions R/data_w.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ data.w <- function(dataset,

# Notice that if max recording date is Saturday (DT_max_diadasemana = 6) then the week is complete,
# and the epiweek is on course. Otherwise some data must be ignored
aux.trimming.date = ifelse( use.epiweek, 6-DT_max_diadasemana, 0)

## Ignore data after the last Sunday of recording (Sunday as too)
aux.trimming.date = ifelse( use.epiweek | DT_max_diadasemana == 6, DT_max_diadasemana + 1, 0)


# ## Test for age bins
if(!is.numeric(bins_age)){
Expand Down Expand Up @@ -107,21 +110,34 @@ data.w <- function(dataset,
age_col <= max(bins_age)) |>
tidyr::drop_na(age_col) |>
dplyr::mutate(
# Alterando a data para o primeiro dia da semana
# Ex. se ultimo dado for de um domingo, entao a semana
# comeca na 2a anterior, se termina 5a, entao começará 6a
date_onset = date_onset -
as.integer(format(date_onset, "%w")) -
(6-DT_max_diadasemana),
date_report = date_report -
as.integer(format(date_report, "%w")) -
(6-DT_max_diadasemana),
## Onset date
# Moving the date to sunday
DT.sun.aux = as.integer(format(date_onset, "%w")),
## Altering the date for the first day of the week
dt.aux = date_onset -
# Last recording date (DT_max_diadasemana) is the last day of the new week format
DT.sun.aux +
ifelse( use.epiweek, 0, DT_max_diadasemana+1 -
ifelse(DT_max_diadasemana+1>DT.sun.aux,7, 0)
),
date_onset = dt.aux - ifelse( date_onset < dt.aux, 7, 0),
# Recording date
DT.sun.aux = as.integer(format(date_report, "%w")),
## Altering the date for the first day of the week
dt.aux = date_report -
# Last recording date (DT_max_diadasemana) is the last day of the new week format
DT.sun.aux +
ifelse( use.epiweek, 0, DT_max_diadasemana+1 -
ifelse(DT_max_diadasemana+1 > DT.sun.aux,7, 0)
),
date_report = dt.aux - ifelse( date_report < dt.aux, 7, 0),
Delay = as.numeric(date_report - date_onset) / 7,
fx_etaria = cut(age_col,
breaks = bins_age,
labels = labels_age,
right = F)
) |>
dplyr::select(-dt.aux, -DT.sun.aux) |>
tidyr::drop_na(fx_etaria) |>
dplyr::filter(Delay >= 0)

Expand Down
41 changes: 28 additions & 13 deletions R/data_w_no_age.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,39 +40,54 @@ data.w_no_age<-function(dataset,
trim.data <- 0
}

## Transforming trim.data into weeks
## Transforming trim.data into days
trim.data.w <- 7*trim.data

## K parameter of forecasting
K.w<-7*K

## Maximum date to be considered on the estimation
## Maximum date to be considered on the estimation (Last day)
DT_max <- max(dataset |>
dplyr::pull(var = {{date_report}}),
na.rm = T) - trim.data.w + K.w


## Last day of the week for the digitation date calculation
## Day of the week of the last day
DT_max_diadasemana <- as.integer(format(DT_max, "%w"))

# Notice that if max recording date is Saturday (DT_max_diadasemana = 6) then the week is complete,
# and the epiweek is on course. Otherwise some data must be ignored
aux.trimming.date = ifelse( use.epiweek, 6-DT_max_diadasemana, 0)
## Ignore data after the last Sunday of recording (Sunday as too)
aux.trimming.date = ifelse( use.epiweek | DT_max_diadasemana == 6, DT_max_diadasemana + 1, 0)

## Accounting for the maximum of days on the last week to be used
data_w <- dataset |>
dplyr::rename(date_report = {{date_report}},
date_onset = {{date_onset}}) |>
dplyr::filter(date_report <= DT_max - aux.trimming.date) |>
dplyr::mutate(
## Onset date
# Moving the date to sunday
DT.sun.aux = as.integer(format(date_onset, "%w")),
## Altering the date for the first day of the week
date_onset = date_onset -
as.integer(format(date_onset, "%w")) -
(6-DT_max_diadasemana),
date_report = date_report -
as.integer(format(date_report, "%w")) -
(6-DT_max_diadasemana),
Delay = as.numeric(date_report - date_onset) / 7) |>
dt.aux = date_onset -
# Last recording date (DT_max_diadasemana) is the last day of the new week format
DT.sun.aux +
ifelse( use.epiweek, 0, DT_max_diadasemana+1 -
ifelse(DT_max_diadasemana+1>DT.sun.aux,7, 0)
),
date_onset = dt.aux - ifelse( date_onset < dt.aux, 7, 0),
# Recording date
DT.sun.aux = as.integer(format(date_report, "%w")),
## Altering the date for the first day of the week
dt.aux = date_report -
# Last recording date (DT_max_diadasemana) is the last day of the new week format
DT.sun.aux +
ifelse( use.epiweek, 0, DT_max_diadasemana+1 -
ifelse(DT_max_diadasemana+1 > DT.sun.aux,7, 0)
),
date_report = dt.aux - ifelse( date_report < dt.aux, 7, 0),
Delay = as.numeric(date_report - date_onset) / 7
) |>
dplyr::select(-dt.aux, -DT.sun.aux) |>
dplyr::filter(Delay >= 0)

# Returning the data
Expand Down
2 changes: 1 addition & 1 deletion man/data.w.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/data.w_no_age.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/nowcasting_inla.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8cce598

Please sign in to comment.