Skip to content

Commit

Permalink
normalization functions
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriellemackinnon committed Jul 24, 2024
1 parent dd0634f commit 1f36fb1
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions R/iidda.analysis/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export(mutate_time_vars)
export(names_to_join_by)
export(normalize_disease_hierarchy)
export(normalize_location)
export(normalize_population)
export(normalize_time_scales)
export(num_days)
export(num_days_util)
Expand Down
25 changes: 25 additions & 0 deletions R/iidda.analysis/R/normalization_tools.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,31 @@ normalize_location = function(data){
}


#' Normalize Population
#'
#'
#'
#' @param data Tidy dataset with columns period_start_date, period_end_date,
#' iso_3166_2
#' @param harmonized_population Harmonized population data from API or
#' iidda-staging/derived_data/pop_ca_1871-2021_harmonized/pop_ca_1871-2021_harmonized/pop_ca_1871-2021_harmonized.csv
#'
#' @return Tidy dataset joined with harmonized population
#'
#' @export
normalize_population = function(data, harmonized_population){
(data
|> mutate(across(starts_with("period_"), readr::parse_date))
|> mutate(days_this_period = iidda.analysis::num_days(period_start_date, period_end_date))
|> mutate(period_mid_date = iidda.analysis::mid_dates(period_start_date, period_end_date, days_this_period))
|> left_join(harmonized_population |> group_by(iso_3166_2) |> mutate(date = as.Date(date))
, by = dplyr::join_by(iso_3166_2, closest(period_mid_date >= date))
, multiple = "all"
)
)
}


#' Is Leaf Disease
#'
#' Given a set of `disease`-`nesting_disease` pairs that all share the same
Expand Down
21 changes: 21 additions & 0 deletions R/iidda.analysis/man/normalize_population.Rd

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

2 changes: 1 addition & 1 deletion R/iidda/R/data_prep_tools.R
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ basal_disease = function(disease, disease_lookup, encountered_diseases = charact
#' columns that describe a global disease hierarchy that will be applied
#' to find the basal disease of each `disease` in data
#'
#' @return
#' @return tidy dataset with basal disease
#'
#' @export
add_basal_disease = function(data, lookup){
Expand Down
3 changes: 3 additions & 0 deletions R/iidda/man/add_basal_disease.Rd

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

0 comments on commit 1f36fb1

Please sign in to comment.