diff --git a/NAMESPACE b/NAMESPACE index cfcae34..7661e8b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,8 +5,8 @@ export(combine_plots) export(gen_data_le) export(gen_data_mean) export(gen_data_mean_weighted_burden_wide) -export(gen_data_mean_weighted_inc_wide) export(gen_data_weighted) +export(gen_data_weighted_ds) export(gen_data_weighted_rf) export(hgps_theme) export(inc_cum) diff --git a/R/data-process.R b/R/data-process.R index 69ff8f5..8a3b51c 100644 --- a/R/data-process.R +++ b/R/data-process.R @@ -168,45 +168,63 @@ gen_data_weighted_rf <- function(data_weighted) { #' #' This function calculates the differences between intervention and baseline values for incidences. #' -#' @param data_mean_weighted A data frame containing weighted mean values for various metrics. +#' @param data_weighted A data frame containing weighted mean values for various metrics. #' @return A data frame with differences between intervention and baseline values for incidences. #' @export -gen_data_mean_weighted_inc_wide <- function(data_mean_weighted) { - data_mean_weighted_inc <- dplyr::select(data_mean_weighted, - data_mean_weighted$source, - data_mean_weighted$timediff, - data_mean_weighted$totalcase_ihd, - data_mean_weighted$totalcase_diabetes, - data_mean_weighted$totalcase_stroke, - data_mean_weighted$totalcase_asthma, - #data_mean_weighted$totalcase_stomachcancer, - data_mean_weighted$totalcase_ckd) +gen_data_weighted_ds <- function(data_weighted) { + data_weighted_ds <- dplyr::select(data_weighted, + data_weighted$source, + data_weighted$time, + data_weighted$simID, + data_weighted$totalcase_ihd, + data_weighted$totalcase_diabetes, + data_weighted$totalcase_stroke, + data_weighted$totalcase_asthma, + data_weighted$totalcase_ckd) + + data_weighted_ds_wide <- tidyr::pivot_wider(data_weighted_ds, + names_from = data_weighted_ds$source, + id_cols = c(data_weighted_ds$time, data_weighted_ds$simID), + values_from = c(data_weighted_ds$totalcase_ihd, + data_weighted_ds$totalcase_diabetes, + data_weighted_ds$totalcase_stroke, + data_weighted_ds$totalcase_asthma, + data_weighted_ds$totalcase_ckd)) - data_mean_weighted_inc_wide <- tidyr::pivot_wider(data_mean_weighted_inc, - names_from = data_mean_weighted_inc$source, - id_cols = data_mean_weighted_inc$timediff, - values_from = c(data_mean_weighted_inc$totalcase_ihd, - data_mean_weighted_inc$totalcase_diabetes, - data_mean_weighted_inc$totalcase_stroke, - data_mean_weighted_inc$totalcase_asthma, - #data_mean_weighted_inc$totalcase_stomachcancer, - data_mean_weighted_inc$totalcase_ckd)) + data_weighted_ds_wide <- data_weighted_ds_wide |> + dplyr::mutate(data_weighted_ds_wide$diff_inc_ihd <- 100*(data_weighted_ds_wide$totalcase_ihd_intervention - data_weighted_ds_wide$totalcase_ihd_baseline), + data_weighted_ds_wide$diff_inc_db <- 100*(data_weighted_ds_wide$totalcase_diabetes_intervention - data_weighted_ds_wide$totalcase_diabetes_baseline), + data_weighted_ds_wide$diff_inc_stroke <- 100*(data_weighted_ds_wide$totalcase_stroke_intervention - data_weighted_ds_wide$totalcase_stroke_baseline), + data_weighted_ds_wide$diff_inc_asthma <- 100*(data_weighted_ds_wide$totalcase_asthma_intervention - data_weighted_ds_wide$totalcase_asthma_baseline), + data_weighted_ds_wide$diff_inc_ckd <- 100*(data_weighted_ds_wide$totalcase_ckd_intervention - data_weighted_ds_wide$totalcase_ckd_baseline)) - data_mean_weighted_inc_wide$diff_ihd <- 100*(data_mean_weighted_inc_wide$totalcase_ihd_intervention - data_mean_weighted_inc_wide$totalcase_ihd_baseline) - data_mean_weighted_inc_wide$diff_diabetes <- 100*(data_mean_weighted_inc_wide$totalcase_diabetes_intervention - data_mean_weighted_inc_wide$totalcase_diabetes_baseline) - data_mean_weighted_inc_wide$diff_stroke <- 100*(data_mean_weighted_inc_wide$totalcase_stroke_intervention - data_mean_weighted_inc_wide$totalcase_stroke_baseline) - data_mean_weighted_inc_wide$diff_asthma <- 100*(data_mean_weighted_inc_wide$totalcase_asthma_intervention - data_mean_weighted_inc_wide$totalcase_asthma_baseline) - #data_mean_weighted_inc_wide$diff_stomachcancer <- 100*(data_mean_weighted_inc_wide$totalcase_stomachcancer_intervention - data_mean_weighted_inc_wide$totalcase_stomachcancer_baseline) - data_mean_weighted_inc_wide$diff_ckd <- 100*(data_mean_weighted_inc_wide$totalcase_ckd_intervention - data_mean_weighted_inc_wide$totalcase_ckd_baseline) + data_weighted_ds_wide <- data_weighted_ds_wide |> + dplyr::group_by(data_weighted_ds_wide$simID) |> + dplyr::mutate(data_weighted_ds_wide$cumdiff_inc_ihd <- cumsum(data_weighted_ds_wide$diff_inc_ihd), + data_weighted_ds_wide$cumdiff_inc_db <- cumsum(data_weighted_ds_wide$diff_inc_db), + data_weighted_ds_wide$cumdiff_inc_stroke <- cumsum(data_weighted_ds_wide$diff_inc_stroke), + data_weighted_ds_wide$cumdiff_inc_asthma <- cumsum(data_weighted_ds_wide$diff_inc_asthma), + data_weighted_ds_wide$cumdiff_inc_ckd <- cumsum(data_weighted_ds_wide$diff_inc_ckd)) - data_mean_weighted_inc_wide$cumdiff_ihd <- cumsum(data_mean_weighted_inc_wide$diff_ihd) - data_mean_weighted_inc_wide$cumdiff_diabetes <- cumsum(data_mean_weighted_inc_wide$diff_diabetes) - data_mean_weighted_inc_wide$cumdiff_stroke <- cumsum(data_mean_weighted_inc_wide$diff_stroke) - data_mean_weighted_inc_wide$cumdiff_asthma <- cumsum(data_mean_weighted_inc_wide$diff_asthma) - #data_mean_weighted_inc_wide$cumdiff_stomachcancer <- cumsum(data_mean_weighted_inc_wide$diff_stomachcancer) - data_mean_weighted_inc_wide$cumdiff_ckd <- cumsum(data_mean_weighted_inc_wide$diff_ckd) + data_weighted_ds_wide_collapse <- data_weighted_ds_wide |> + dplyr::group_by(data_weighted_ds_wide$time) |> + dplyr::summarise(data_weighted_ds_wide$diff_inc_ihd_mean <- mean(data_weighted_ds_wide$cumdiff_inc_ihd), + data_weighted_ds_wide$diff_inc_ihd_min <- min(data_weighted_ds_wide$cumdiff_inc_ihd), + data_weighted_ds_wide$diff_inc_ihd_max <- max(data_weighted_ds_wide$cumdiff_inc_ihd), + data_weighted_ds_wide$diff_inc_db_mean <- mean(data_weighted_ds_wide$cumdiff_inc_db), + data_weighted_ds_wide$diff_inc_db_min <- min(data_weighted_ds_wide$cumdiff_inc_db), + data_weighted_ds_wide$diff_inc_db_max <- max(data_weighted_ds_wide$cumdiff_inc_db), + data_weighted_ds_wide$diff_inc_stroke_mean <- mean(data_weighted_ds_wide$cumdiff_inc_stroke), + data_weighted_ds_wide$diff_inc_stroke_min <- min(data_weighted_ds_wide$cumdiff_inc_stroke), + data_weighted_ds_wide$diff_inc_stroke_max <- max(data_weighted_ds_wide$cumdiff_inc_stroke), + data_weighted_ds_wide$diff_inc_asthma_mean <- mean(data_weighted_ds_wide$cumdiff_inc_asthma), + data_weighted_ds_wide$diff_inc_asthma_min <- min(data_weighted_ds_wide$cumdiff_inc_asthma), + data_weighted_ds_wide$diff_inc_asthma_max <- max(data_weighted_ds_wide$cumdiff_inc_asthma), + data_weighted_ds_wide$diff_inc_ckd_mean <- mean(data_weighted_ds_wide$cumdiff_inc_ckd), + data_weighted_ds_wide$diff_inc_ckd_min <- min(data_weighted_ds_wide$cumdiff_inc_ckd), + data_weighted_ds_wide$diff_inc_ckd_max <- max(data_weighted_ds_wide$cumdiff_inc_ckd)) - return(data_mean_weighted_inc_wide) + return(data_weighted_ds_wide_collapse) } #' Calculate Differences for Burden of Disease diff --git a/man/gen_data_mean_weighted_inc_wide.Rd b/man/gen_data_weighted_ds.Rd similarity index 62% rename from man/gen_data_mean_weighted_inc_wide.Rd rename to man/gen_data_weighted_ds.Rd index fa9f32a..b70405d 100644 --- a/man/gen_data_mean_weighted_inc_wide.Rd +++ b/man/gen_data_weighted_ds.Rd @@ -1,13 +1,13 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/data-process.R -\name{gen_data_mean_weighted_inc_wide} -\alias{gen_data_mean_weighted_inc_wide} +\name{gen_data_weighted_ds} +\alias{gen_data_weighted_ds} \title{Calculate Differences for Incidences} \usage{ -gen_data_mean_weighted_inc_wide(data_mean_weighted) +gen_data_weighted_ds(data_weighted) } \arguments{ -\item{data_mean_weighted}{A data frame containing weighted mean values for various metrics.} +\item{data_weighted}{A data frame containing weighted mean values for various metrics.} } \value{ A data frame with differences between intervention and baseline values for incidences.