Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions R/classifications.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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”).
#'
Expand Down Expand Up @@ -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'"
)
}
}
Expand All @@ -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'."
)
}
}
Expand Down
4 changes: 4 additions & 0 deletions R/indicators-export.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

#' Indicators
#'
#' Notes:
#' \itemize{
#' \item \code{indicator_iodine} does not produce individual level classifications.
#' }
#' @include indicators-anaemia.R
#' @rdname indicators
#' @export
Expand Down
58 changes: 4 additions & 54 deletions R/indicators-iodine.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
),
Expand Down
3 changes: 3 additions & 0 deletions R/prevalence.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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%
Expand All @@ -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%
Expand Down
5 changes: 4 additions & 1 deletion man/indicators.Rd

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

6 changes: 3 additions & 3 deletions man/individual_classification.Rd

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

6 changes: 3 additions & 3 deletions man/mn_stats.Rd

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