diff --git a/R/classifications.R b/R/classifications.R index 9bf5bb4..273ecea 100644 --- a/R/classifications.R +++ b/R/classifications.R @@ -6,10 +6,10 @@ #' @param indicators a list of indicators that should be computed. Note, please do not add the same indicator twice. Also you can only use one adjustment at a time at the moment. #' @param sex A vector indicating the sex of individuals. Accepted values: for Male (1/ "M"/ "m") and for Female (2/ "F"/ "f"). #' . If missing, prevalence will not be calculated for any biomarker because micronutrient status cut offs are sex-specific. -#' @param age A numeric vector of ages in years for the individuals in the dataset. If you have the in other units, you have to use the \code{age} object. For example: if you have age in months, you can create an `age` object like this \code{age(age_in_months, unit = "months")}. +#' @param age A numeric vector of ages in years for the individuals in the dataset. If you have age in other units, you have to use the \code{age} object. For example: if you have age in months, you can create an `age` object like this \code{age(age_in_months, unit = "months")}. #' @param pregnancy_status (Optional) A vector indicating pregnancy status. Accepted values: For Yes ("Y", "y", or "1"), No ("N", "n", or "2"), Unknown ("unk" or "3" or blank). #' When Unknown ("unk" or "3" or blank), it will be categorized as "not pregnant". -#' Note that 'pregnancy_status' should not be missing when 'pregnancyweeks' or 'pregnancymonths' contain valid, non-missing values. Missing 'pregnancy_status' in these cases will be considered as 'not pregnant'. +#' Note that 'pregnancy_status' should not be missing when 'pregnancyweeks' or 'pregnancymonths' contain valid, non-missing values. Observations with missing values in 'pregnancy_status' will be considered as 'not pregnant'. #' @param lactating_status (Optional) A vector indicating lactation status. Accepted values: For Yes ("Y", "y", or "1"), No ("N", "n", or "2"). #' @param pregnancyweeks (Optional) A numeric vector indicating the number of weeks of pregnancy. #' @param pregnancymonths (Optional) A numeric vector indicating the number of months of pregnancy. @@ -19,7 +19,7 @@ #' @param iodine (Optional) A vector of iodine measurements (in \\u00b5gg/L). #' @param haemoglobin (Optional) A vector of haemoglobin measurements (in g/L). #' @param altitude (Optional) A numeric vector representing elevation above sea level (in meters), used to adjust for altitude-related effects. Elevation is a compulsory variable and it should always be reported in the dataset. Even when no elevation data is collected, a variable for 'elevation' should be created and set as "0" for all individuals without reported elevation. When elevation is not reported, that individual case will be excluded from the analysis and considered as 'missing' -#' @param is_smoker (Optional) A vector indicating smoking status. Accepted values: for Yes ("Y", "y", or "1"), No ("N", "n", or "2"), Unknown ("unk" or "3"). When ‘smoking status’ is mapped and no value is reported, the tool will consider this value as "no smoking". +#' @param is_smoker (Optional) A vector indicating smoking status. Accepted values: for Yes ("Y", "y", or "1"), No ("N", "n", or "2"), Unknown ("unk" or "3"). Note that 'is_smoker' should not be missing when 'smokes_cigarettes_per_day' contains valid and not missing values. Observations with missing values in 'is_smoker' will be considered as a 'non-smoker'. #' @param smokes_cigarettes_per_day (Optional) A numeric vector representing the number of cigarettes smoked per day. Note that 'is_smoker' should not be missing when 'smokes_cigarettes_per_day' contain valid, non-missing values. Missing 'is_smoker' in these cases will be considered as 'not a smoker'. #' @param malaria (Optional) A vector indicating malaria status. Accepted values: for Yes (“Y”, “y”, or “1”) and No (“N”, “n”, or “2”). #' @@ -174,7 +174,7 @@ validate_concepts <- function(concepts) { if (!is.null(is_smoker) && !is.null(smokes_cigarettes_per_day)) { if (any(is.na(is_smoker) & !is.na(smokes_cigarettes_per_day))) { warning( - "Missing `is_smoker`: a non NA value for `is_smoker` is required when `smokes_cigarettes_per_day` is not NA." + "Missing `is_smoker`: a non NA value for `is_smoker` is required when `smokes_cigarettes_per_day` is not NA. Otherwise, these observations will be considered as 'not smoker'" ) } } @@ -184,14 +184,14 @@ validate_concepts <- function(concepts) { if (!is.null(pregnancy_status) && !is.null(pregnancyweeks)) { if (any(is.na(pregnancy_status) & !is.na(pregnancyweeks))) { warning( - "Missing `pregnancy_status`: a non NA value for `pregnancy_status` is required when `pregnancyweeks` is not NA." + "Missing `pregnancy_status`: a non NA value for `pregnancy_status` is required when `pregnancyweeks` is not NA. Otherwise, these observations will be considered as 'not pregnant'." ) } } if (!is.null(pregnancy_status) && !is.null(pregnancymonths)) { if (any(is.na(pregnancy_status) & !is.na(pregnancymonths))) { warning( - "Missing `pregnancy_status`: a non NA value for `pregnancy_status` is required when `pregnancymonths` is not NA." + "Missing `pregnancy_status`: a non NA value for `pregnancy_status` is required when `pregnancymonths` is not NA. Otherwise, these observations will be considered as 'not pregnant'." ) } } diff --git a/R/indicators-export.R b/R/indicators-export.R index 1f6d934..d62d4ae 100644 --- a/R/indicators-export.R +++ b/R/indicators-export.R @@ -3,6 +3,10 @@ #' Indicators #' +#' Notes: +#' \itemize{ +#' \item \code{indicator_iodine} does not produce individual level classifications. +#' } #' @include indicators-anaemia.R #' @rdname indicators #' @export diff --git a/R/indicators-iodine.R b/R/indicators-iodine.R index 74b6db0..cbff32b 100644 --- a/R/indicators-iodine.R +++ b/R/indicators-iodine.R @@ -38,39 +38,7 @@ iodine_indicator <- indicator( "pregnancy_status" ), global_condition = age_in_years(age) >= 0, # no restrictions - categories = list( - category( - name = "Adequate iodine intake", - - # not pregnant - (!is_pregnant(pregnancy_status) | is.na(is_pregnant(pregnancy_status))) & - value >= 100 & - value < 300, - - # pregnant - is_pregnant(pregnancy_status) & - value >= 150 & - value < 500 - ), - category( - name = "Excessive iodine intake", - - (!is_pregnant(pregnancy_status) | is.na(is_pregnant(pregnancy_status))) & - value >= 300, - - is_pregnant(pregnancy_status) & - value >= 500 - ), - category( - name = "Insufficient iodine intake", - - (!is_pregnant(pregnancy_status) | is.na(is_pregnant(pregnancy_status))) & - value < 100, - - is_pregnant(pregnancy_status) & - value < 150 - ) - ), + categories = list(), adjustment = adjustment( required_concepts = c( "age", @@ -91,32 +59,14 @@ iodine_indicator <- indicator( paste0("iodine_p", x) ) }), - prevalence_categories = list( - excessive_iodine = \(x) { - ifelse(is.na(x), NA, x %in% "Excessive iodine intake") - }, - insufficient_iodine = \(x) { - ifelse(is.na(x), NA, x %in% "Insufficient iodine intake") - } - ), - prevalence_category_names = c( - excessive_iodine = "Excessive iodine intake", - insufficient_iodine = "Insufficient iodine intake" - ), + prevalence_categories = list(), + prevalence_category_names = c(), drop_columns = list( short = c( #"iodine_mean", "iodine_mean_sd", "iodine_mean_ll", - "iodine_mean_ul", - "excessive_iodine_r", - "excessive_iodine_se", - "excessive_iodine_ll", - "excessive_iodine_ul", - "insufficient_iodine_r", - "insufficient_iodine_se", - "insufficient_iodine_ll", - "insufficient_iodine_ul" + "iodine_mean_ul" ), long = NULL ), diff --git a/R/prevalence.R b/R/prevalence.R index b055d87..5a05deb 100644 --- a/R/prevalence.R +++ b/R/prevalence.R @@ -353,6 +353,9 @@ build_prevalence_survey_data <- function(survey_df, indicators) { for (indicator in indicators) { indicator_name <- indicator_abbreviated_name(indicator) prev_categories <- indicator_prevalence_categories(indicator) + if (length(prev_categories) == 0) { + next() + } agg_prev_categories <- indicator_agg_prevalence_categories(indicator) result <- survey_df[[paste0(indicator_name, "_result")]] prev_results <- as_tibble(lapply(prev_categories, \(fun) fun(result))) diff --git a/README.md b/README.md index bd4b391..9dfcc55 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ result <- mn_stats( ``` r covr::package_coverage() -#> micronutrients Coverage: 77.66% +#> micronutrients Coverage: 77.72% #> R/concept-area.R: 0.00% #> R/concept-fasting-status.R: 0.00% #> R/concept-helpers.R: 0.00% @@ -117,13 +117,13 @@ covr::package_coverage() #> R/indicators-iodine.R: 33.33% #> R/utils.R: 39.58% #> R/indicators-composite.R: 56.67% -#> R/indicators-ferritin.R: 63.01% +#> R/indicators-ferritin.R: 63.45% #> R/concepts.R: 85.37% #> R/age.R: 85.71% #> R/concept-pregnancy-status.R: 87.50% #> R/indicators.R: 88.89% #> R/age-groups.R: 89.61% -#> R/prevalence.R: 96.79% +#> R/prevalence.R: 96.80% #> R/adjustments-export.R: 100.00% #> R/classifications.R: 100.00% #> R/indicators-export.R: 100.00% diff --git a/man/indicators.Rd b/man/indicators.Rd index 6a866bf..11f88d8 100644 --- a/man/indicators.Rd +++ b/man/indicators.Rd @@ -19,5 +19,8 @@ indicator_iodine() \item{ferritin_adjustment}{the adjustment method for ferritin.} } \description{ -Indicators +Notes: +\itemize{ +\item \code{indicator_iodine} does not produce individual level classifications. +} } diff --git a/man/individual_classification.Rd b/man/individual_classification.Rd index a19326f..d631270 100644 --- a/man/individual_classification.Rd +++ b/man/individual_classification.Rd @@ -29,11 +29,11 @@ individual_classification( \item{sex}{A vector indicating the sex of individuals. Accepted values: for Male (1/ "M"/ "m") and for Female (2/ "F"/ "f"). . If missing, prevalence will not be calculated for any biomarker because micronutrient status cut offs are sex-specific.} -\item{age}{A numeric vector of ages in years for the individuals in the dataset. If you have the in other units, you have to use the \code{age} object. For example: if you have age in months, you can create an \code{age} object like this \code{age(age_in_months, unit = "months")}.} +\item{age}{A numeric vector of ages in years for the individuals in the dataset. If you have age in other units, you have to use the \code{age} object. For example: if you have age in months, you can create an \code{age} object like this \code{age(age_in_months, unit = "months")}.} \item{pregnancy_status}{(Optional) A vector indicating pregnancy status. Accepted values: For Yes ("Y", "y", or "1"), No ("N", "n", or "2"), Unknown ("unk" or "3" or blank). When Unknown ("unk" or "3" or blank), it will be categorized as "not pregnant". -Note that 'pregnancy_status' should not be missing when 'pregnancyweeks' or 'pregnancymonths' contain valid, non-missing values. Missing 'pregnancy_status' in these cases will be considered as 'not pregnant'.} +Note that 'pregnancy_status' should not be missing when 'pregnancyweeks' or 'pregnancymonths' contain valid, non-missing values. Observations with missing values in 'pregnancy_status' will be considered as 'not pregnant'.} \item{pregnancyweeks}{(Optional) A numeric vector indicating the number of weeks of pregnancy.} @@ -53,7 +53,7 @@ Note that 'pregnancy_status' should not be missing when 'pregnancyweeks' or 'pre \item{altitude}{(Optional) A numeric vector representing elevation above sea level (in meters), used to adjust for altitude-related effects. Elevation is a compulsory variable and it should always be reported in the dataset. Even when no elevation data is collected, a variable for 'elevation' should be created and set as "0" for all individuals without reported elevation. When elevation is not reported, that individual case will be excluded from the analysis and considered as 'missing'} -\item{is_smoker}{(Optional) A vector indicating smoking status. Accepted values: for Yes ("Y", "y", or "1"), No ("N", "n", or "2"), Unknown ("unk" or "3"). When ‘smoking status’ is mapped and no value is reported, the tool will consider this value as "no smoking".} +\item{is_smoker}{(Optional) A vector indicating smoking status. Accepted values: for Yes ("Y", "y", or "1"), No ("N", "n", or "2"), Unknown ("unk" or "3"). Note that 'is_smoker' should not be missing when 'smokes_cigarettes_per_day' contains valid and not missing values. Observations with missing values in 'is_smoker' will be considered as a 'non-smoker'.} \item{smokes_cigarettes_per_day}{(Optional) A numeric vector representing the number of cigarettes smoked per day. Note that 'is_smoker' should not be missing when 'smokes_cigarettes_per_day' contain valid, non-missing values. Missing 'is_smoker' in these cases will be considered as 'not a smoker'.} diff --git a/man/mn_stats.Rd b/man/mn_stats.Rd index 2f710a3..130d375 100644 --- a/man/mn_stats.Rd +++ b/man/mn_stats.Rd @@ -37,11 +37,11 @@ mn_stats( \item{sex}{A vector indicating the sex of individuals. Accepted values: for Male (1/ "M"/ "m") and for Female (2/ "F"/ "f"). . If missing, prevalence will not be calculated for any biomarker because micronutrient status cut offs are sex-specific.} -\item{age}{A numeric vector of ages in years for the individuals in the dataset. If you have the in other units, you have to use the \code{age} object. For example: if you have age in months, you can create an \code{age} object like this \code{age(age_in_months, unit = "months")}.} +\item{age}{A numeric vector of ages in years for the individuals in the dataset. If you have age in other units, you have to use the \code{age} object. For example: if you have age in months, you can create an \code{age} object like this \code{age(age_in_months, unit = "months")}.} \item{pregnancy_status}{(Optional) A vector indicating pregnancy status. Accepted values: For Yes ("Y", "y", or "1"), No ("N", "n", or "2"), Unknown ("unk" or "3" or blank). When Unknown ("unk" or "3" or blank), it will be categorized as "not pregnant". -Note that 'pregnancy_status' should not be missing when 'pregnancyweeks' or 'pregnancymonths' contain valid, non-missing values. Missing 'pregnancy_status' in these cases will be considered as 'not pregnant'.} +Note that 'pregnancy_status' should not be missing when 'pregnancyweeks' or 'pregnancymonths' contain valid, non-missing values. Observations with missing values in 'pregnancy_status' will be considered as 'not pregnant'.} \item{lactating_status}{(Optional) A vector indicating lactation status. Accepted values: For Yes ("Y", "y", or "1"), No ("N", "n", or "2").} @@ -57,7 +57,7 @@ Note that 'pregnancy_status' should not be missing when 'pregnancyweeks' or 'pre \item{altitude}{(Optional) A numeric vector representing elevation above sea level (in meters), used to adjust for altitude-related effects. Elevation is a compulsory variable and it should always be reported in the dataset. Even when no elevation data is collected, a variable for 'elevation' should be created and set as "0" for all individuals without reported elevation. When elevation is not reported, that individual case will be excluded from the analysis and considered as 'missing'} -\item{is_smoker}{(Optional) A vector indicating smoking status. Accepted values: for Yes ("Y", "y", or "1"), No ("N", "n", or "2"), Unknown ("unk" or "3"). When ‘smoking status’ is mapped and no value is reported, the tool will consider this value as "no smoking".} +\item{is_smoker}{(Optional) A vector indicating smoking status. Accepted values: for Yes ("Y", "y", or "1"), No ("N", "n", or "2"), Unknown ("unk" or "3"). Note that 'is_smoker' should not be missing when 'smokes_cigarettes_per_day' contains valid and not missing values. Observations with missing values in 'is_smoker' will be considered as a 'non-smoker'.} \item{smokes_cigarettes_per_day}{(Optional) A numeric vector representing the number of cigarettes smoked per day. Note that 'is_smoker' should not be missing when 'smokes_cigarettes_per_day' contain valid, non-missing values. Missing 'is_smoker' in these cases will be considered as 'not a smoker'.}