From b356a0db21620824eeaac0d855e6e2b5555b0403 Mon Sep 17 00:00:00 2001 From: Ernest Guevarra Date: Mon, 19 Feb 2024 16:44:34 +0000 Subject: [PATCH 1/3] change ipc_muac_check output; fix #2;#3;#4;#6;#7;#8 --- NAMESPACE | 3 +- R/muac_checks.R | 104 +++++++++++++++++++++++++++++++++++------- R/muac_prevalence.R | 40 ++++++---------- README.Rmd | 12 +++++ README.md | 69 +++++++++++++++++++++++++--- man/ipc_class.Rd | 8 ++-- man/ipc_muac_check.Rd | 44 ++++++++++-------- man/ipc_prevalence.Rd | 45 ++++++------------ man/ipctools.Rd | 9 ++++ man/muac_data.Rd | 19 ++++---- 10 files changed, 240 insertions(+), 113 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 3fc0fc6..e1618e2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,5 @@ # Generated by roxygen2: do not edit by hand -export(calculate_prevalence) export(calculate_unweighted_prevalence) export(calculate_weighted_prevalence) export(classify_acute_malnutrition) @@ -8,7 +7,9 @@ export(classify_age_ratio) export(classify_quality) export(classify_sd) export(classify_sex_ratio) +export(ipc_calculate_prevalence) export(ipc_muac_check) +export(summarise_muac_check) importFrom(dplyr,case_when) importFrom(dplyr,group_by) importFrom(dplyr,mutate) diff --git a/R/muac_checks.R b/R/muac_checks.R index e0d9d95..61d7182 100644 --- a/R/muac_checks.R +++ b/R/muac_checks.R @@ -38,6 +38,9 @@ #' Setting `.summary` to FALSE is usually only used for when the output #' structure is required for further analysis (i.e., calculation of #' prevalence). +#' @param .list Logical. Relevent only if `.summary` is TRUE. Should summary be +#' given in list format? If TRUE (default), then the output is in list format +#' otherwise a data.frame is provided. #' #' @return A data.frame with a single row with each column for each metric used #' to check MUAC dataset if `.summary` is TRUE. If `.summary` is FALSE, a @@ -59,7 +62,8 @@ ipc_muac_check <- function(df, muac_units = c("mm", "cm"), oedema = "oedema", oedema_recode = NULL, - .summary = TRUE) { + .summary = TRUE, + .list = TRUE) { ## Determine MUAC units ---- muac_units <- match.arg(muac_units) @@ -86,16 +90,53 @@ ipc_muac_check <- function(df, df <- df |> dplyr::mutate(muac = muac * 10) } +# if (.summary) { + summarise_muac_check(df, .summary = .summary, .list = .list) + # } else { + # df |> + # dplyr::mutate( + # age_ratio = nipnTK::ageRatioTest(as.integer(!is.na(age)))$observedR, + # age_ratio_p = nipnTK::ageRatioTest(as.integer(!is.na(age)))$p, + # sex_ratio = nipnTK::sexRatioTest(sex, codes = c(1, 2))$pM, + # sex_ratio_p = nipnTK::sexRatioTest(sex, codes = c(1, 2))$p, + # digit_preference = nipnTK::digitPreference(muac, digits = 0)$dps, + # digit_preference_class = nipnTK::digitPreference(muac, digits = 0)$dpsClass, + # std_dev = stats::sd(muac, na.rm = TRUE), + # age_ratio_class = classify_age_ratio(.data$age_ratio_p), + # sex_ratio_class = classify_sex_ratio(.data$sex_ratio_p), + # std_dev_class = classify_sd(.data$std_dev), + # quality_score = classify_quality( + # .data$age_ratio_class, .data$sex_ratio_class, + # .data$std_dev_class, .data$digit_preference_class + # )$q_score, + # quality_class = classify_quality( + # .data$age_ratio_class, .data$sex_ratio_class, + # .data$std_dev_class, .data$digit_preference_class + # )$q_class + # ) |> + # dplyr::relocate(.data$age_ratio_class, .after = "age_ratio_p") |> + # dplyr::relocate(.data$sex_ratio_class, .after = "sex_ratio_p") |> + # dplyr::relocate(.data$std_dev_class, .after = "std_dev") + # } +} + + +#' +#' @rdname ipc_muac_check +#' @export +#' + +summarise_muac_check <- function(df, .summary = TRUE, .list = TRUE) { if (.summary) { - df |> + muac_check <- df |> dplyr::summarise( - age_ratio = nipnTK::ageRatioTest(as.integer(!is.na(age)))$observedR, - age_ratio_p = nipnTK::ageRatioTest(as.integer(!is.na(age)))$p, - sex_ratio = nipnTK::sexRatioTest(sex, codes = c(1, 2))$pM, - sex_ratio_p = nipnTK::sexRatioTest(sex, codes = c(1, 2))$p, - digit_preference = nipnTK::digitPreference(muac, digits = 0)$dps, - digit_preference_class = nipnTK::digitPreference(muac, digits = 0)$dpsClass, - std_dev = stats::sd(muac, na.rm = TRUE), + age_ratio = nipnTK::ageRatioTest(as.integer(!is.na(.data$age)))$observedR, + age_ratio_p = nipnTK::ageRatioTest(as.integer(!is.na(.data$age)))$p, + sex_ratio = nipnTK::sexRatioTest(.data$sex, codes = c(1, 2))$pM, + sex_ratio_p = nipnTK::sexRatioTest(.data$sex, codes = c(1, 2))$p, + digit_preference = nipnTK::digitPreference(.data$muac, digits = 0)$dps, + digit_preference_class = nipnTK::digitPreference(.data$muac, digits = 0)$dpsClass, + std_dev = stats::sd(.data$muac, na.rm = TRUE), age_ratio_class = classify_age_ratio(.data$age_ratio_p), sex_ratio_class = classify_sex_ratio(.data$sex_ratio_p), std_dev_class = classify_sd(.data$std_dev), @@ -111,16 +152,41 @@ ipc_muac_check <- function(df, dplyr::relocate(.data$age_ratio_class, .after = "age_ratio_p") |> dplyr::relocate(.data$sex_ratio_class, .after = "sex_ratio_p") |> dplyr::relocate(.data$std_dev_class, .after = "std_dev") + + if (.list) { + muac_check <- list( + `Age Ratio` = list( + ratio = muac_check$age_ratio, + p = muac_check$age_ratio_p, + class = muac_check$age_ratio_class + ), + `Sex Ratio` = list( + ratio = muac_check$sex_ratio, + p = muac_check$sex_ratio_p, + class = muac_check$sex_ratio_class + ), + `Digit Preference` = list( + score = muac_check$digit_preference, + class = muac_check$digit_preference_class + ), + `Standard Deviation` = list( + std_dev = muac_check$std_dev, + class = muac_check$std_dev_class + ) + ) + } else { + muac_check + } } else { - df |> + muac_check <- df |> dplyr::mutate( - age_ratio = nipnTK::ageRatioTest(as.integer(!is.na(age)))$observedR, - age_ratio_p = nipnTK::ageRatioTest(as.integer(!is.na(age)))$p, - sex_ratio = nipnTK::sexRatioTest(sex, codes = c(1, 2))$pM, - sex_ratio_p = nipnTK::sexRatioTest(sex, codes = c(1, 2))$p, - digit_preference = nipnTK::digitPreference(muac, digits = 0)$dps, - digit_preference_class = nipnTK::digitPreference(muac, digits = 0)$dpsClass, - std_dev = stats::sd(muac, na.rm = TRUE), + age_ratio = nipnTK::ageRatioTest(as.integer(!is.na(.data$age)))$observedR, + age_ratio_p = nipnTK::ageRatioTest(as.integer(!is.na(.data$age)))$p, + sex_ratio = nipnTK::sexRatioTest(.data$sex, codes = c(1, 2))$pM, + sex_ratio_p = nipnTK::sexRatioTest(.data$sex, codes = c(1, 2))$p, + digit_preference = nipnTK::digitPreference(.data$muac, digits = 0)$dps, + digit_preference_class = nipnTK::digitPreference(.data$muac, digits = 0)$dpsClass, + std_dev = stats::sd(.data$muac, na.rm = TRUE), age_ratio_class = classify_age_ratio(.data$age_ratio_p), sex_ratio_class = classify_sex_ratio(.data$sex_ratio_p), std_dev_class = classify_sd(.data$std_dev), @@ -137,4 +203,8 @@ ipc_muac_check <- function(df, dplyr::relocate(.data$sex_ratio_class, .after = "sex_ratio_p") |> dplyr::relocate(.data$std_dev_class, .after = "std_dev") } + + ## Return muac_check ---- + muac_check } + diff --git a/R/muac_prevalence.R b/R/muac_prevalence.R index 4a4767b..d7cfb2b 100644 --- a/R/muac_prevalence.R +++ b/R/muac_prevalence.R @@ -1,6 +1,9 @@ #' #' Calculate wasting prevalence by MUAC #' +#' @param df A data.frame for a MUAC dataset on which appropriate checks have +#' been applied already produced via a call to `ipc_muac_check()` with the +#' `.summary` argument set to FALSE. #' @param age A numeric or integer value or vector of values for age of child. #' The age of child should be in months. #' @param sex A value or a vector of values for sex of child. The expected @@ -27,9 +30,6 @@ #' value for presence of oedema and "n" is the value for no oedema, then #' specify `c("y", "n)`. If set to NULL (default), then the values c(1, 0) #' are used. -#' @param quality_class A vector or character values indicating the -#' classification of the quality of the MUAC dataset. This is usually -#' created from applying the `ipc_muac_check()` function. #' @param status Which wasting anthropometric indicator to report. A choice #' between c("sam", "mam"). Default to "sam" #' @@ -42,19 +42,14 @@ #' status = "sam" #' ) #' -#' df <- ipc_muac_check( +#' ipc_muac_check( #' muac_data, age = "age", sex = "sex", #' muac = "muac", muac_units = "cm", #' oedema = "oedema", oedema_recode = c(1, 2), #' .summary = FALSE -#' ) +#' ) |> +#' ipc_calculate_prevalence() #' -#' with(df, -#' calculate_prevalence( -#' age = age, sex = sex, muac = muac, -#' oedema = oedema, quality_class = quality_class -#' ) -#' ) #' #' @rdname ipc_prevalence #' @export @@ -144,29 +139,22 @@ calculate_weighted_prevalence <- function(age, #' ## Function to calculate prevalence (weighted or unweighted as appropriate) ---- -calculate_prevalence <- function(age, - sex, - sex_recode = NULL, - muac, - muac_units = c("mm", "cm"), - oedema, - oedema_recode = NULL, - quality_class, - status = c("sam", "mam")) { +ipc_calculate_prevalence <- function(df, + status = c("sam", "mam")) { ## Get nut status to work on ---- status <- match.arg(status) ## Calculate prevalence data.frame ---- - prevalence <- data.frame(age, sex, muac, oedema, quality_class) |> + prevalence <- df |> dplyr::summarise( - quality_class = unique(quality_class), + quality_class = unique(.data$quality_class), unweighted_prevalence = calculate_unweighted_prevalence( - muac = muac, oedema = oedema, status = status + muac = .data$muac, oedema = .data$oedema, status = status ), weighted_prevalence = calculate_weighted_prevalence( - age = age, sex = sex, sex_recode = sex_recode, - muac = muac, muac_units = muac_units, - oedema = oedema, oedema_recode = oedema_recode, status = status + age = .data$age, sex = .data$sex, + muac = .data$muac, oedema = .data$oedema, + status = status ), .groups = "drop" ) |> diff --git a/README.Rmd b/README.Rmd index 348aa6c..0072206 100644 --- a/README.Rmd +++ b/README.Rmd @@ -68,6 +68,18 @@ These checks can be performed using the `ipc_muac_check()` function as follows: ipc_muac_check(df = muac_data, muac_units = "cm", oedema_recode = c(1, 2)) ``` +### Calculating acute malnutrition prevalence on a MUAC dataset + +The IPC-recommended approach to calculating prevalence of acute malnutrition based on MUAC is to perform a weighted analysis when either the age ratio test or the sex ratio test is problematic. For example, based on the MUAC check shown above, the example dataset `muac_data` has some issues with its age ratio and sex ratio. To calculate acute malnutrition prevalence from this dataset, a weighted analysis will have to be implemented. This can be done using the `ipc_calculate_prevalence()` function as follows: + +```{r ipc-prevalence} +ipc_muac_check( + df = muac_data, muac_units = "cm", + oedema_recode = c(1, 2), + .summary = FALSE +) |> + ipc_calculate_prevalence() +``` ## Citation diff --git a/README.md b/README.md index 4f0865d..5ee8fd1 100644 --- a/README.md +++ b/README.md @@ -93,13 +93,68 @@ follows: ``` r ipc_muac_check(df = muac_data, muac_units = "cm", oedema_recode = c(1, 2)) -#> # A tibble: 1 × 12 -#> age_ratio age_ratio_p age_ratio_class sex_ratio sex_ratio_p sex_ratio_class -#> -#> 1 Inf 7.79e-113 Problematic 0.506 0.848 Excellent -#> # ℹ 6 more variables: digit_preference , digit_preference_class , -#> # std_dev , std_dev_class , quality_score , -#> # quality_class +#> $`Age Ratio` +#> $`Age Ratio`$ratio +#> [1] Inf +#> +#> $`Age Ratio`$p +#> [1] 7.785732e-113 +#> +#> $`Age Ratio`$class +#> [1] Problematic +#> Levels: Problematic Poor Acceptable Excellent +#> +#> +#> $`Sex Ratio` +#> $`Sex Ratio`$ratio +#> p +#> 0.5057471 +#> +#> $`Sex Ratio`$p +#> [1] 0.8479104 +#> +#> $`Sex Ratio`$class +#> [1] Excellent +#> Levels: Problematic Poor Acceptable Excellent +#> +#> +#> $`Digit Preference` +#> $`Digit Preference`$score +#> [1] 16.35 +#> +#> $`Digit Preference`$class +#> SMART DPS Class +#> "Acceptable" +#> +#> +#> $`Standard Deviation` +#> $`Standard Deviation`$std_dev +#> [1] 12.45931 +#> +#> $`Standard Deviation`$class +#> [1] Excellent +#> Levels: Excellent Acceptable Poor Problematic +``` + +### Calculating acute malnutrition prevalence on a MUAC dataset + +The IPC-recommended approach to calculating prevalence of acute +malnutrition based on MUAC is to perform a weighted analysis when either +the age ratio test or the sex ratio test is problematic. For example, +based on the MUAC check shown above, the example dataset `muac_data` has +some issues with its age ratio and sex ratio. To calculate acute +malnutrition prevalence from this dataset, a weighted analysis will have +to be implemented. This can be done using the +`ipc_calculate_prevalence()` function as follows: + +``` r +ipc_muac_check( + df = muac_data, muac_units = "cm", + oedema_recode = c(1, 2), + .summary = FALSE +) |> + ipc_calculate_prevalence() +#> [1] 0.2179668 ``` ## Citation diff --git a/man/ipc_class.Rd b/man/ipc_class.Rd index 75de921..5a9fb88 100644 --- a/man/ipc_class.Rd +++ b/man/ipc_class.Rd @@ -44,22 +44,22 @@ the digit preference score (DPS)} \item{muac}{A numeric value or vector of numeric values for MUAC measurement of child. The expected values for MUAC are in millimetres. If units are -different, use `muac_units` to specify which units are used.} +different, use \code{muac_units} to specify which units are used.} \item{muac_units}{A character value for units used for MUAC measurement. Currently accepts either "mm" for millimetres (default) or "cm" for centimetres.} \item{oedema}{A value or a vector of values for oedema status of child. The -expected values for `oedema` is 1 = for presence of oedema and 2 for no -oedema. If data values are different, use `oedema_recode` to map out the +expected values for \code{oedema} is 1 = for presence of oedema and 2 for no +oedema. If data values are different, use \code{oedema_recode} to map out the values to what is required.} \item{oedema_recode}{A vector of values with length of 2 with the first element for the value signifiying presence of oedema and second element for the value signifying no oedema in the dataset. For example, if "y" is the value for presence of oedema and "n" is the value for no oedema, then -specify `c("y", "n)`. If set to NULL (default), then the values c(1, 0) +specify \verb{c("y", "n)}. If set to NULL (default), then the values c(1, 0) are used.} } \value{ diff --git a/man/ipc_muac_check.Rd b/man/ipc_muac_check.Rd index c62db11..5cd2e3f 100644 --- a/man/ipc_muac_check.Rd +++ b/man/ipc_muac_check.Rd @@ -2,6 +2,7 @@ % Please edit documentation in R/muac_checks.R \name{ipc_muac_check} \alias{ipc_muac_check} +\alias{summarise_muac_check} \title{Perform MUAC check based on IPC and CDC recommendations} \usage{ ipc_muac_check( @@ -13,61 +14,68 @@ ipc_muac_check( muac_units = c("mm", "cm"), oedema = "oedema", oedema_recode = NULL, - .summary = TRUE + .summary = TRUE, + .list = TRUE ) + +summarise_muac_check(df, .summary = TRUE, .list = TRUE) } \arguments{ \item{df}{A data.frame with information on age, sex, oedema status, and MUAC of each child} -\item{age}{A character value for name of variable in `df` for age of +\item{age}{A character value for name of variable in \code{df} for age of child. The age of child should be in months.} -\item{sex}{A character value for name of variale in `df` for sex of child. -The expected values for `sex` is 1 = males; 2 = females. If data values -are different, use `sex_recode` to map out the values to what is +\item{sex}{A character value for name of variale in \code{df} for sex of child. +The expected values for \code{sex} is 1 = males; 2 = females. If data values +are different, use \code{sex_recode} to map out the values to what is required.} \item{sex_recode}{A vector of values with length of 2 with the first element for the value signifiying males and second element for the value signifying females in the dataset. For example, if "m" is the value for -males and "f" is the value for females, then specify `c("m", "f)`. If +males and "f" is the value for females, then specify \verb{c("m", "f)}. If set to NULL (default), then the values c(1, 2) are used.} -\item{muac}{A character value for name of variable in `df` for MUAC +\item{muac}{A character value for name of variable in \code{df} for MUAC measurement of child. The expected values for MUAC are in millimetres. -If units are different, use `muac_units` to specify which units are used.} +If units are different, use \code{muac_units} to specify which units are used.} \item{muac_units}{A character value for units used for MUAC measurement. Currently accepts either "mm" for millimetres (default) or "cm" for centimetres.} -\item{oedema}{A character value for name of variable in `df` for oedema -status of child. The expected values for `oedema` is 1 = for presence of +\item{oedema}{A character value for name of variable in \code{df} for oedema +status of child. The expected values for \code{oedema} is 1 = for presence of oedema and 2 for no oedema. If data values are different, use -`oedema_recode` to map out the values to what is required.} +\code{oedema_recode} to map out the values to what is required.} \item{oedema_recode}{A vector of values with length of 2 with the first element for the value signifiying presence of oedema and second element for the value signifying no oedema in the dataset. For example, if "y" is the value for presence of oedema and "n" is the value for no oedema, then -specify `c("y", "n)`. If set to NULL (default), then the values c(1, 0) +specify \verb{c("y", "n)}. If set to NULL (default), then the values c(1, 0) are used.} \item{.summary}{Logical. Should output be a summary of all the checks peformed on the MUAC dataset? If TRUE (default), output will be a single row data.frame with each column for each metric used to check MUAC -dataset. If FALSE, a data.frame with same number of rows as `df` and -columns for each metric used to check MUAC dataset is added to `df`. -Setting `.summary` to FALSE is usually only used for when the output +dataset. If FALSE, a data.frame with same number of rows as \code{df} and +columns for each metric used to check MUAC dataset is added to \code{df}. +Setting \code{.summary} to FALSE is usually only used for when the output structure is required for further analysis (i.e., calculation of prevalence).} + +\item{.list}{Logical. Relevent only if \code{.summary} is TRUE. Should summary be +given in list format? If TRUE (default), then the output is in list format +otherwise a data.frame is provided.} } \value{ A data.frame with a single row with each column for each metric used - to check MUAC dataset if `.summary` is TRUE. If `.summary` is FALSE, a - data.frame with same number of rows as `df` and columns for each metric - used to check MUAC dataset is added to `df`. +to check MUAC dataset if \code{.summary} is TRUE. If \code{.summary} is FALSE, a +data.frame with same number of rows as \code{df} and columns for each metric +used to check MUAC dataset is added to \code{df}. } \description{ Perform MUAC check based on IPC and CDC recommendations diff --git a/man/ipc_prevalence.Rd b/man/ipc_prevalence.Rd index aca7cb6..d730683 100644 --- a/man/ipc_prevalence.Rd +++ b/man/ipc_prevalence.Rd @@ -3,7 +3,7 @@ \name{calculate_unweighted_prevalence} \alias{calculate_unweighted_prevalence} \alias{calculate_weighted_prevalence} -\alias{calculate_prevalence} +\alias{ipc_calculate_prevalence} \title{Calculate wasting prevalence by MUAC} \usage{ calculate_unweighted_prevalence( @@ -25,37 +25,27 @@ calculate_weighted_prevalence( status = c("sam", "mam") ) -calculate_prevalence( - age, - sex, - sex_recode = NULL, - muac, - muac_units = c("mm", "cm"), - oedema, - oedema_recode = NULL, - quality_class, - status = c("sam", "mam") -) +ipc_calculate_prevalence(df, status = c("sam", "mam")) } \arguments{ \item{muac}{A numeric value or vector of numeric values for MUAC measurement of child. The expected values for MUAC are in millimetres. If units are -different, use `muac_units` to specify which units are used.} +different, use \code{muac_units} to specify which units are used.} \item{muac_units}{A character value for units used for MUAC measurement. Currently accepts either "mm" for millimetres (default) or "cm" for centimetres.} \item{oedema}{A value or a vector of values for oedema status of child. The -expected values for `oedema` is 1 = for presence of oedema and 2 for no -oedema. If data values are different, use `oedema_recode` to map out the +expected values for \code{oedema} is 1 = for presence of oedema and 2 for no +oedema. If data values are different, use \code{oedema_recode} to map out the values to what is required.} \item{oedema_recode}{A vector of values with length of 2 with the first element for the value signifiying presence of oedema and second element for the value signifying no oedema in the dataset. For example, if "y" is the value for presence of oedema and "n" is the value for no oedema, then -specify `c("y", "n)`. If set to NULL (default), then the values c(1, 0) +specify \verb{c("y", "n)}. If set to NULL (default), then the values c(1, 0) are used.} \item{status}{Which wasting anthropometric indicator to report. A choice @@ -65,18 +55,18 @@ between c("sam", "mam"). Default to "sam"} The age of child should be in months.} \item{sex}{A value or a vector of values for sex of child. The expected -values for `sex` is 1 = males; 2 = females. If data values are different, -use `sex_recode` to map out the values to what is required.} +values for \code{sex} is 1 = males; 2 = females. If data values are different, +use \code{sex_recode} to map out the values to what is required.} \item{sex_recode}{A vector of values with length of 2 with the first element for the value signifiying males and second element for the value signifying females in the dataset. For example, if "m" is the value for -males and "f" is the value for females, then specify `c("m", "f)`. If +males and "f" is the value for females, then specify \verb{c("m", "f)}. If set to NULL (default), then the values c(1, 2) are used.} -\item{quality_class}{A vector or character values indicating the -classification of the quality of the MUAC dataset. This is usually -created from applying the `ipc_muac_check()` function.} +\item{df}{A data.frame for a MUAC dataset on which appropriate checks have +been applied already produced via a call to \code{ipc_muac_check()} with the +\code{.summary} argument set to FALSE.} } \value{ A single value, a vector of values, or a table providing a prevalence @@ -91,18 +81,13 @@ calculate_unweighted_prevalence( status = "sam" ) -df <- ipc_muac_check( +ipc_muac_check( muac_data, age = "age", sex = "sex", muac = "muac", muac_units = "cm", oedema = "oedema", oedema_recode = c(1, 2), .summary = FALSE -) +) |> +ipc_calculate_prevalence() -with(df, - calculate_prevalence( - age = age, sex = sex, muac = muac, - oedema = oedema, quality_class = quality_class - ) -) } diff --git a/man/ipctools.Rd b/man/ipctools.Rd index dafc31d..0c3089b 100644 --- a/man/ipctools.Rd +++ b/man/ipctools.Rd @@ -14,6 +14,15 @@ world. It provides a common understanding of the food security situation and enables decision-makers to take appropriate actions to mitigate and respond to food crises. This package provides functions and utilities that support IPC-related data analysis and visualisation. +} +\seealso{ +Useful links: +\itemize{ + \item \url{https://nutriverse.io/ipctools/} + \item \url{https://github.com/nutriverse/ipctools} + \item Report bugs at \url{https://github.com/nutriverse/ipctools/issues} +} + } \author{ \strong{Maintainer}: Ernest Guevarra \email{ernest@guevarra.io} (\href{https://orcid.org/0000-0002-4887-4415}{ORCID}) [copyright holder] diff --git a/man/muac_data.Rd b/man/muac_data.Rd index 7b040d0..e0f6481 100644 --- a/man/muac_data.Rd +++ b/man/muac_data.Rd @@ -6,16 +6,15 @@ \title{Nutrition survey data with MUAC and oedema measurements and location information anonymised.} \format{ -A data frame with 6 columns and 435 rows: - -| **Variable** | **Description** | -| :--- | :--- | -| *state_name* | Name of state | -| *district_name* | Name of district | -| *age* | Age of child in months | -| *sex* | Sex of child. 1 = male; 2 = female | -| *muac* | Mid-upper arm circumference (MUAC) measurement in centimetres | -| *oedema* | Presence or absence of oedema. 1 = oedema; 2 = no oedema | +A data frame with 6 columns and 435 rows:\tabular{ll}{ + \strong{Variable} \tab \strong{Description} \cr + \emph{state_name} \tab Name of state \cr + \emph{district_name} \tab Name of district \cr + \emph{age} \tab Age of child in months \cr + \emph{sex} \tab Sex of child. 1 = male; 2 = female \cr + \emph{muac} \tab Mid-upper arm circumference (MUAC) measurement in centimetres \cr + \emph{oedema} \tab Presence or absence of oedema. 1 = oedema; 2 = no oedema \cr +} } \usage{ muac_data From 3e8f01c1eec3c43076d961cbe9c46bd0edb6d373 Mon Sep 17 00:00:00 2001 From: Ernest Guevarra Date: Mon, 19 Feb 2024 16:48:10 +0000 Subject: [PATCH 2/3] initiate ci/cd gha; fix #10 --- .Rbuildignore | 1 + .github/.gitignore | 1 + .github/workflows/R-CMD-check.yaml | 49 +++++++++++++++++++++++++++ .github/workflows/test-coverage.yaml | 50 ++++++++++++++++++++++++++++ DESCRIPTION | 2 ++ README.Rmd | 2 ++ README.md | 3 ++ codecov.yml | 14 ++++++++ 8 files changed, 122 insertions(+) create mode 100644 .github/.gitignore create mode 100644 .github/workflows/R-CMD-check.yaml create mode 100644 .github/workflows/test-coverage.yaml create mode 100644 codecov.yml diff --git a/.Rbuildignore b/.Rbuildignore index 8d6140d..f774e44 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -4,3 +4,4 @@ ^README\.Rmd$ ^\.github$ ^data-raw$ +^codecov\.yml$ diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 0000000..2d19fc7 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 0000000..74d8c97 --- /dev/null +++ b/.github/workflows/R-CMD-check.yaml @@ -0,0 +1,49 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +name: R-CMD-check + +jobs: + R-CMD-check: + runs-on: ${{ matrix.config.os }} + + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + + strategy: + fail-fast: false + matrix: + config: + - {os: macos-latest, r: 'release'} + - {os: windows-latest, r: 'release'} + - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} + - {os: ubuntu-latest, r: 'release'} + - {os: ubuntu-latest, r: 'oldrel-1'} + + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes + + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + r-version: ${{ matrix.config.r }} + http-user-agent: ${{ matrix.config.http-user-agent }} + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::rcmdcheck + needs: check + + - uses: r-lib/actions/check-r-package@v2 + with: + upload-snapshots: true diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml new file mode 100644 index 0000000..960234c --- /dev/null +++ b/.github/workflows/test-coverage.yaml @@ -0,0 +1,50 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +name: test-coverage + +jobs: + test-coverage: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::covr + needs: coverage + + - name: Test coverage + run: | + covr::codecov( + quiet = FALSE, + clean = FALSE, + install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") + ) + shell: Rscript {0} + + - name: Show testthat output + if: always() + run: | + ## -------------------------------------------------------------------- + find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true + shell: bash + + - name: Upload test results + if: failure() + uses: actions/upload-artifact@v4 + with: + name: coverage-test-failures + path: ${{ runner.temp }}/package diff --git a/DESCRIPTION b/DESCRIPTION index a46b335..f02423c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -30,3 +30,5 @@ RoxygenNote: 7.2.3 Roxygen: list(markdown = TRUE) URL: https://nutriverse.io/ipctools/, https://github.com/nutriverse/ipctools BugReports: https://github.com/nutriverse/ipctools/issues +Suggests: + covr diff --git a/README.Rmd b/README.Rmd index 0072206..87f5c7a 100644 --- a/README.Rmd +++ b/README.Rmd @@ -18,6 +18,8 @@ knitr::opts_chunk$set( [![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip) [![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) +[![R-CMD-check](https://github.com/nutriverse/ipctools/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/nutriverse/ipctools/actions/workflows/R-CMD-check.yaml) +[![Codecov test coverage](https://codecov.io/gh/nutriverse/ipctools/branch/main/graph/badge.svg)](https://app.codecov.io/gh/nutriverse/ipctools?branch=main) The [Integrated Food Security Phase Classification (IPC)](https://www.ipcinfo.org/) is a widely used tool for classifying and analyzing the severity and magnitude of food insecurity and malnutrition situations in various countries and regions around the world. It provides a common understanding of the food security situation and enables decision-makers to take appropriate actions to mitigate and respond to food crises. This package provides functions and utilities that support IPC-related data analysis and visualisation. diff --git a/README.md b/README.md index 5ee8fd1..8420bb9 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,9 @@ has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip) [![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) +[![R-CMD-check](https://github.com/nutriverse/ipctools/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/nutriverse/ipctools/actions/workflows/R-CMD-check.yaml) +[![Codecov test +coverage](https://codecov.io/gh/nutriverse/ipctools/branch/main/graph/badge.svg)](https://app.codecov.io/gh/nutriverse/ipctools?branch=main) The [Integrated Food Security Phase Classification diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..04c5585 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,14 @@ +comment: false + +coverage: + status: + project: + default: + target: auto + threshold: 1% + informational: true + patch: + default: + target: auto + threshold: 1% + informational: true From 5a27aa453b09a687084c959f6711fa7ccc8745c7 Mon Sep 17 00:00:00 2001 From: Ernest Guevarra Date: Mon, 19 Feb 2024 17:31:25 +0000 Subject: [PATCH 3/3] create package website --- .Rbuildignore | 4 ++ .github/workflows/pkgdown.yaml | 48 ++++++++++++++++++ .gitignore | 1 + DESCRIPTION | 4 +- R/{muac_utils.R => muac_classification.R} | 5 +- README.Rmd | 2 + README.md | 2 + pkgdown/_pkgdown.yml | 60 +++++++++++++++++++++++ 8 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/pkgdown.yaml rename R/{muac_utils.R => muac_classification.R} (97%) create mode 100644 pkgdown/_pkgdown.yml diff --git a/.Rbuildignore b/.Rbuildignore index f774e44..e0c84ed 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -5,3 +5,7 @@ ^\.github$ ^data-raw$ ^codecov\.yml$ +^pkgdown/_pkgdown\.yml$ +^docs$ +^pkgdown$ +^_pkgdown\.yml$ diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml new file mode 100644 index 0000000..a7276e8 --- /dev/null +++ b/.github/workflows/pkgdown.yaml @@ -0,0 +1,48 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + release: + types: [published] + workflow_dispatch: + +name: pkgdown + +jobs: + pkgdown: + runs-on: ubuntu-latest + # Only restrict concurrency for non-PR jobs + concurrency: + group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::pkgdown, local::. + needs: website + + - name: Build site + run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) + shell: Rscript {0} + + - name: Deploy to GitHub pages 🚀 + if: github.event_name != 'pull_request' + uses: JamesIves/github-pages-deploy-action@v4.5.0 + with: + clean: false + branch: gh-pages + folder: docs diff --git a/.gitignore b/.gitignore index 5b6a065..234f028 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .Rhistory .RData .Ruserdata +docs diff --git a/DESCRIPTION b/DESCRIPTION index f02423c..876108c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -28,7 +28,9 @@ LazyData: true Language: en-GB RoxygenNote: 7.2.3 Roxygen: list(markdown = TRUE) -URL: https://nutriverse.io/ipctools/, https://github.com/nutriverse/ipctools +URL: https://nutriverse.io/ipctools/, + https://github.com/nutriverse/ipctools, + http://nutriverse.io/ipctools/ BugReports: https://github.com/nutriverse/ipctools/issues Suggests: covr diff --git a/R/muac_utils.R b/R/muac_classification.R similarity index 97% rename from R/muac_utils.R rename to R/muac_classification.R index e51c419..b7a20af 100644 --- a/R/muac_utils.R +++ b/R/muac_classification.R @@ -1,5 +1,6 @@ #' -#' Utility functions that support the main functions in the package +#' Classification functions that support the main functions for working with +#' MUAC datasets #' #' @param p Numeric value for p-value of a statistical test used in the #' various checks applied. @@ -36,7 +37,7 @@ #' age_ratio_p <- nipnTK::ageRatioTest(as.integer(!is.na(muac_data$age)))$p #' classify_age_ratio(age_ratio_p) #' -#' @rdname ipc_class +#' @rdname ipc_muac_class #' @export #' #' diff --git a/README.Rmd b/README.Rmd index 87f5c7a..57631a1 100644 --- a/README.Rmd +++ b/README.Rmd @@ -19,7 +19,9 @@ knitr::opts_chunk$set( [![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip) [![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) [![R-CMD-check](https://github.com/nutriverse/ipctools/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/nutriverse/ipctools/actions/workflows/R-CMD-check.yaml) +[![test-coverage](https://github.com/nutriverse/ipctools/actions/workflows/test-coverage.yaml/badge.svg)](https://github.com/nutriverse/ipctools/actions/workflows/test-coverage.yaml) [![Codecov test coverage](https://codecov.io/gh/nutriverse/ipctools/branch/main/graph/badge.svg)](https://app.codecov.io/gh/nutriverse/ipctools?branch=main) +[![CodeFactor](https://www.codefactor.io/repository/github/nutriverse/ipctools/badge)](https://www.codefactor.io/repository/github/nutriverse/ipctools) The [Integrated Food Security Phase Classification (IPC)](https://www.ipcinfo.org/) is a widely used tool for classifying and analyzing the severity and magnitude of food insecurity and malnutrition situations in various countries and regions around the world. It provides a common understanding of the food security situation and enables decision-makers to take appropriate actions to mitigate and respond to food crises. This package provides functions and utilities that support IPC-related data analysis and visualisation. diff --git a/README.md b/README.md index 8420bb9..494074a 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,10 @@ public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostat [![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) [![R-CMD-check](https://github.com/nutriverse/ipctools/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/nutriverse/ipctools/actions/workflows/R-CMD-check.yaml) +[![test-coverage](https://github.com/nutriverse/ipctools/actions/workflows/test-coverage.yaml/badge.svg)](https://github.com/nutriverse/ipctools/actions/workflows/test-coverage.yaml) [![Codecov test coverage](https://codecov.io/gh/nutriverse/ipctools/branch/main/graph/badge.svg)](https://app.codecov.io/gh/nutriverse/ipctools?branch=main) +[![CodeFactor](https://www.codefactor.io/repository/github/nutriverse/ipctools/badge)](https://www.codefactor.io/repository/github/nutriverse/ipctools) The [Integrated Food Security Phase Classification diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml new file mode 100644 index 0000000..b83cb8e --- /dev/null +++ b/pkgdown/_pkgdown.yml @@ -0,0 +1,60 @@ +title: ipctools + +url: http://nutriverse.io/ipctools/ + +template: + bootstrap: 5 + bootswatch: lumen + theme: haddock + ganalytics: # + +navbar: + bg: primary + type: light + structure: + #left: [home, intro, reference, articles, news] + left: [home, reference] + #right: [linkedin, github] + + # components: + # articles: + # text: Articles + # menu: + # - text: "Performing MUAC checks and calculating prevalence" + # href: articles/muac_checks.html + # linkedin: + # icon: "fab fa-linkedin fa-lg" + # href: https://www.linkedin.com/company/katilingban + +home: + #links: + #- text: Read more about haemoglobin concentrations for the diagnosis of anaemia and assessment of severity + # href: https://www.who.int/vmnis/indicators/haemoglobin.pdf + +reference: + - title: Description + contents: + - ipctools + + - title: MUAC checks + contents: + - ipc_muac_check + - summarise_muac_check + + - title: MUAC prevalence + contents: + - ipc_calculate_prevalence + - calculate_unweighted_prevalence + - calculate_weighted_prevalence + + - title: MUAC classification + contents: + - classify_age_ratio + - classify_sex_ratio + - classify_sd + - classify_quality + - classify_acute_malnutrition + + - title: Datasets + contents: + - muac_data