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
2 changes: 2 additions & 0 deletions R/concept-area.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ as_area <- function(x) {
stopifnot(all(x %in% c("1", "2", "urban", "rural", NA_character_)))
x[x == "1"] <- "Urban"
x[x == "2"] <- "Rural"
x[x == "urban"] <- "Urban"
x[x == "rural"] <- "Rural"
factor(x, levels = area_levels, ordered = FALSE)
}
73 changes: 53 additions & 20 deletions R/concepts.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ concepts <- concepts_list(
concept(
key = "pregnancymonths",
label = "Pregnancy Months",
acceptor = concept_acceptor(is.numeric, "TODO"),
acceptor = concept_acceptor(
is.numeric,
"Preganancy Months should be a numeric value."
),
standardizer = identity,
validator = is.numeric,
prototype = NA_real_
Expand All @@ -94,7 +97,10 @@ concepts <- concepts_list(
concept(
key = "pregnancyweeks",
label = "Pregnancy Weeks",
acceptor = concept_acceptor(is.numeric, "TODO"),
acceptor = concept_acceptor(
is.numeric,
"Preganancy Weeks should be a numeric value."
),
standardizer = identity,
validator = is.numeric,
prototype = NA_real_
Expand Down Expand Up @@ -171,7 +177,10 @@ concepts <- concepts_list(
concept(
key = "smokes_cigarettes_per_day",
label = "Number of cigarettes per day",
acceptor = concept_acceptor(is.numeric, "TODO"),
acceptor = concept_acceptor(
is.numeric,
"Number of cigarettes per day should be a numeric value."
),
standardizer = identity,
validator = is.numeric,
prototype = NA_real_
Expand All @@ -180,7 +189,10 @@ concepts <- concepts_list(
concept(
key = "altitude",
label = "Elevation",
acceptor = concept_acceptor(is.numeric, "TODO"),
acceptor = concept_acceptor(
is.numeric,
"Elevation should be a numeric value."
),
standardizer = identity,
validator = is.numeric,
prototype = NA_real_
Expand All @@ -197,7 +209,7 @@ concepts <- concepts_list(
) &&
any(!is.na(x))
},
"TODO"
"Area can only be '1', '2', 'urban' or 'rural'. All lower-case. At least one value must not be NA."
),
standardizer = as_area,
validator = \(x) is.factor(x) & all(levels(x) == area_levels),
Expand All @@ -207,7 +219,10 @@ concepts <- concepts_list(
concept(
key = "region",
label = "Region",
acceptor = concept_acceptor(\(x) is.character(x) | is.numeric(x), "TODO"),
acceptor = concept_acceptor(
\(x) is.character(x) | is.numeric(x),
"Region should be a numeric or a character value."
),
standardizer = as.character,
validator = is.character,
prototype = NA_character_
Expand All @@ -216,7 +231,10 @@ concepts <- concepts_list(
concept(
key = "wealth_quintile",
label = "Wealth Quintile",
acceptor = concept_acceptor(wealth_quintiles_acceptor, "TODO"),
acceptor = concept_acceptor(
wealth_quintiles_acceptor,
"Wealth Quintiles must only be 1,2,3,4,5 or Q1,Q2,Q3,Q4,Q5 or NA."
),
standardizer = as_wealth_quintiles,
validator = \(x) is.factor(x) & all(levels(x) == wealth_quintiles_levels),
prototype = NA_character_
Expand All @@ -234,7 +252,7 @@ concepts <- concepts_list(
) &&
any(!is.na(x))
},
"TODO"
"Mother's Education must be a numeric value of 0,1,2,3 or NA."
),
standardizer = as_mothers_education,
validator = \(x) is.factor(x) & all(levels(x) == mothers_education_levels),
Expand All @@ -244,7 +262,10 @@ concepts <- concepts_list(
concept(
key = "sample_weight",
label = "Sample Weight",
acceptor = concept_acceptor(is.numeric, "TODO"),
acceptor = concept_acceptor(
is.numeric,
"Sample Weight must be a numeric value."
),
standardizer = identity,
validator = is.numeric,
prototype = NA_real_
Expand All @@ -253,7 +274,10 @@ concepts <- concepts_list(
concept(
key = "iodine",
label = "Urinary Iodine Concentration (\u00b5g/L)",
acceptor = concept_acceptor(is.numeric, "TODO"),
acceptor = concept_acceptor(
is.numeric,
"Urinary Iodine Concentration must be a numeric value."
),
standardizer = identity,
validator = is.numeric,
prototype = measurement_g_l(NA_real_),
Expand All @@ -263,7 +287,10 @@ concepts <- concepts_list(
concept(
key = "haemoglobin",
label = "Haemoglobin (g/L)",
acceptor = concept_acceptor(is.numeric, "TODO"),
acceptor = concept_acceptor(
is.numeric,
"Haemoglobin must be a numeric value."
),
standardizer = identity,
validator = is.numeric,
prototype = measurement_g_l(NA_real_),
Expand All @@ -273,7 +300,10 @@ concepts <- concepts_list(
concept(
key = "ferritin",
label = "Ferritin (\u00b5g/L)",
acceptor = concept_acceptor(is.numeric, "TODO"),
acceptor = concept_acceptor(
is.numeric,
"Ferritin must be a numeric value."
),
standardizer = identity,
validator = is.numeric,
prototype = measurement_mcg_l(NA_real_),
Expand All @@ -283,7 +313,7 @@ concepts <- concepts_list(
concept(
key = "AGP",
label = "AGP",
acceptor = concept_acceptor(is.numeric, "TODO"),
acceptor = concept_acceptor(is.numeric, "AGP must be a numeric value."),
standardizer = identity,
validator = is.numeric,
prototype = measurement_g_l(NA_real_),
Expand All @@ -293,7 +323,7 @@ concepts <- concepts_list(
concept(
key = "CRP",
label = "CRP",
acceptor = concept_acceptor(is.numeric, "TODO"),
acceptor = concept_acceptor(is.numeric, "CRP must be a numeric value."),
standardizer = identity,
validator = is.numeric,
prototype = measurement_mg_l(NA_real_),
Expand All @@ -302,8 +332,11 @@ concepts <- concepts_list(
## other_grouping_variable ----
concept(
key = "other_grouping_variable",
label = "Other filter",
acceptor = concept_acceptor(\(x) is.character(x) | is.numeric(x), "TODO"),
label = "Other grouping",
acceptor = concept_acceptor(
\(x) is.character(x) | is.numeric(x),
"Other group must be either a character or numeric value."
),
standardizer = as.character,
validator = is.character,
prototype = NA_character_
Expand All @@ -312,7 +345,7 @@ concepts <- concepts_list(
concept(
key = "cluster",
label = "Cluster",
acceptor = concept_acceptor(is.numeric, "TODO"),
acceptor = concept_acceptor(is.numeric, "Cluster must be a numeric value."),
standardizer = identity,
validator = is.numeric,
prototype = NA_integer_
Expand All @@ -321,7 +354,7 @@ concepts <- concepts_list(
concept(
key = "strata",
label = "Strata",
acceptor = concept_acceptor(is.numeric, "TODO"),
acceptor = concept_acceptor(is.numeric, "Strata must be a numeric value."),
standardizer = identity,
validator = is.numeric,
prototype = NA_integer_
Expand All @@ -338,7 +371,7 @@ concepts <- concepts_list(
) &&
any(!is.na(x))
},
"TODO"
"Fasting must be '1', 'yes', 'y' for 'yes' or '2', 'no','n' for 'no'."
),
standardizer = as.character,
validator = is.character,
Expand All @@ -356,7 +389,7 @@ concepts <- concepts_list(
) &&
any(!is.na(x))
},
"TODO"
"Malaria must be '1', 'yes', 'y' for 'yes' or '2', 'no','n' for 'no'."
),
standardizer = function(x) {
x <- as.character(x)
Expand Down
2 changes: 1 addition & 1 deletion R/indicators-export.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#'
#' Notes:
#' \itemize{
#' \item \code{indicator_iodine} does not produce individual level classifications.
#' \item \code{indicator_iodine} does not produce individual level classifications. All results are 'NA'.
#' }
#' @include indicators-anaemia.R
#' @rdname indicators
Expand Down
6 changes: 5 additions & 1 deletion R/indicators.R
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,11 @@ indicators_compute_all <- function(indicators, values, concepts) {
} else {
tibble::tibble(
result = result,
input_value = indicator_adjust_value(indicator, base_values[[i]], concepts)
input_value = indicator_adjust_value(
indicator,
base_values[[i]],
concepts
)
)
}
}
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ result <- mn_stats(

``` r
covr::package_coverage()
#> micronutrients Coverage: 77.72%
#> R/concept-area.R: 0.00%
#> micronutrients Coverage: 78.10%
#> R/concept-fasting-status.R: 0.00%
#> R/concept-helpers.R: 0.00%
#> R/concept-iron-deficiency.R: 0.00%
Expand All @@ -121,10 +120,11 @@ covr::package_coverage()
#> R/concepts.R: 85.37%
#> R/age.R: 85.71%
#> R/concept-pregnancy-status.R: 87.50%
#> R/indicators.R: 88.89%
#> R/indicators.R: 89.13%
#> R/age-groups.R: 89.61%
#> R/prevalence.R: 96.80%
#> R/adjustments-export.R: 100.00%
#> R/classifications.R: 100.00%
#> R/concept-area.R: 100.00%
#> R/indicators-export.R: 100.00%
```
2 changes: 1 addition & 1 deletion man/indicators.Rd

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

11 changes: 11 additions & 0 deletions tests/testthat/test-concepts.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,14 @@ test_that("concepts_from_args: some concepts have default values if not supplied
)
}
})

test_that("area is properly encoded", {
x <- as_area(c("1", "2", "urban", "rural", NA_character_))
expect_equal(
x,
factor(
c("Urban", "Rural", "Urban", "Rural", NA_character_),
levels = area_levels
)
)
})
6 changes: 5 additions & 1 deletion tests/testthat/test-prevalence.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ test_that("mn_stats", {
pregnancyweeks = testdata$pregnancyweeks,
pregnancymonths = testdata$pregnancymonths,
cluster = 1:nrow(testdata),
strata = rep.int(1, nrow(testdata))
strata = rep.int(1, nrow(testdata)),
area = testdata$area
)
expect_true(is.data.frame(res))
expect_true(nrow(res) > 0)
Expand Down Expand Up @@ -112,4 +113,7 @@ test_that("mn_stats", {
"ida_adj_ul"
)
)
expect_true(
all(c("Area: Urban", "Area: Rural") %in% res$Group)
)
})
Loading