Skip to content

Commit

Permalink
change to
Browse files Browse the repository at this point in the history
  • Loading branch information
SaranjeetKaur committed Aug 22, 2024
1 parent 061ed34 commit 3896405
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 38 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
84 changes: 51 additions & 33 deletions R/data-process.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

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

0 comments on commit 3896405

Please sign in to comment.