Skip to content

Commit 56de8f8

Browse files
Merge pull request #75 from nutriverse/cran-release-v0.2.0
CRAN release v0.2.0
2 parents ef8ca07 + 5c71218 commit 56de8f8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+1034
-261
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@
2626
^CODE_OF_CONDUCT\.md$
2727
^codecov\.yml$
2828
^_pkgdown\.yml$
29+
^revdep$

DESCRIPTION

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: nipnTK
22
Type: Package
33
Title: National Information Platforms for Nutrition Anthropometric Data Toolkit
4-
Version: 0.1.2.9000
4+
Version: 0.2.0
55
Authors@R: c(
66
person(given = "Mark",
77
family = "Myatt",
@@ -23,7 +23,6 @@ Depends: R (>= 2.10)
2323
Imports:
2424
stats,
2525
graphics,
26-
bbw,
2726
withr
2827
Suggests:
2928
testthat,

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export(pyramid.plot)
2525
export(qqNormalPlot)
2626
export(sexRatioTest)
2727
export(skewKurt)
28-
importFrom(bbw,recode)
2928
importFrom(graphics,abline)
3029
importFrom(graphics,axTicks)
3130
importFrom(graphics,axis)

NEWS.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# nipnTK 0.2.0
2+
3+
## Bug fixes
4+
5+
* Resolved issue with `ageRatioTest()` not working properly when age has
6+
missing values
7+
8+
* Resolved issue with `ageRatioTest()` not providing appropriate results when
9+
age values are numeric
10+
11+
## General updates
12+
13+
* Updated general package documentation
14+
15+
* Added CITATION entry
16+
17+
118
# nipnTK 0.1.2.9000
219

320
Third release of `nipnTK`. This is a GitHub-only development release. In this

R/ageChildren.R

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
################################################################################
22
#
3-
#' Goodness of fit to an expected (model-based) age distribution
3+
#' Goodness of fit to an expected model-based age distribution
44
#'
5-
#' @param age Vector of ages
6-
#' @param u5mr Under five years mortality rate as deaths / 10,000 persons / day
7-
#' @param groups Age groupings specified as recodes parameter in the
8-
#' [bbw::recode()] function; default is
9-
#' `"6:17=1; 18:29=2; 30:41=3; 42:53=4; 54:59=5"`
5+
#' A simple model-based method for calculating expected numbers using
6+
#' exponential decay in a population in which births and deaths balance each
7+
#' other and with a 1:1 male to female sex ratio. This function is built
8+
#' specifically to test goodness of fit for a sample of children aged 6-59
9+
#' months old grouped into four 1 year age groups and 1 half year age group
10+
#' (6 to less than 18 months, 18 to less than 30 months, 30 to less than 42
11+
#' months, 42 to less than 54 months, and 54 months to less than 60 months).
1012
#'
11-
#' @return A list of class "ageChildren" with:
13+
#' @param age A vector of ages. Should either be in whole months (integer) or in
14+
#' calculated decimal months (numeric).
15+
#' @param u5mr A numeric value for under five years mortality rate expressed as
16+
#' deaths / 10,000 persons / day. Default is set to 1.
17+
#'
18+
#' @returns A list of class "ageChildren" with:
1219
#'
1320
#' | **Variable** | **Description** |
1421
#' | :--- | :--- |
@@ -42,24 +49,46 @@
4249
################################################################################
4350

4451
ageChildren <- function(age,
45-
u5mr = 0,
46-
groups = "6:17=1; 18:29=2; 30:41=3; 42:53=4; 54:59=5") {
47-
ycag <- bbw::recode(age, groups)
52+
u5mr = 1) {
53+
## If age is numeric ----
54+
if (is.numeric(age)) age <- floor(age)
55+
56+
## If age is integer ----
57+
if (is.integer(age)) age <- age
58+
59+
## If x is not numeric or integer ----
60+
if (!is.numeric(age) & !is.integer(age))
61+
stop("Age should be of class integer or numeric. Try again.")
62+
63+
## Check that u5mr is numeric ----
64+
if (!is.numeric(u5mr))
65+
stop ("Under-5 mortality rate should be numeric. Try again.")
66+
67+
## Create breaks ----
68+
breaks <- c(6, 18, 30, 42, 54, 60)
69+
70+
## Create age groupings based on breaks ----
71+
ycag <- cut(
72+
age, breaks = breaks, labels = seq_len(length(breaks) - 1),
73+
include.lowest = TRUE, right = FALSE,
74+
)
75+
76+
## Model the age distribution ----
4877
z <- (u5mr / 10000) * 365.25
49-
t <- 0:4
50-
p <- exp(-z * 0:4)
78+
t <- seq(from = 0, to = length(breaks) - 2, by = 1)
79+
p <- exp(-z * t)
5180
d <- c(1, 1, 1, 1, 0.5)
5281
p <- d * p / sum(d * p)
5382
expected <- p * sum(table(ycag))
54-
names(expected) <- 1:5
55-
observed <- fullTable(ycag, values = 1:5)
56-
X2 <- sum((observed - expected)^2 / expected)
57-
pX2 <- stats::pchisq(X2, df = 4, lower.tail = FALSE)
83+
names(expected) <- seq_len(length(breaks) - 1)
84+
observed <- fullTable(ycag, values = seq_len(length(breaks) - 1))
85+
X2 <- sum((observed - expected) ^ 2 / expected)
86+
pX2 <- stats::pchisq(X2, df = length(breaks) - 2, lower.tail = FALSE)
5887
result <- list(u5mr = u5mr,
5988
observed = observed,
6089
expected = expected,
6190
X2 = X2,
62-
df = 4,
91+
df = length(breaks) - 2,
6392
p = pX2)
6493
class(result) <- "ageChildren"
6594
return(result)
@@ -73,7 +102,7 @@ ageChildren <- function(age,
73102
#' @param x Object resulting from applying [ageChildren()] function
74103
#' @param ... Additional [print()] arguments
75104
#'
76-
#' @return Printed output of [ageChildren()] function
105+
#' @returns Printed output of [ageChildren()] function
77106
#'
78107
#' @examples
79108
#' # Print Chi-Squared test for age of children in dp.ex02 sample dataset using
@@ -103,7 +132,7 @@ print.ageChildren <- function(x, ...) {
103132
#' @param x Object resulting from applying [ageChildren()] function
104133
#' @param ... Additional [barplot()] graphical parameters
105134
#'
106-
#' @return Bar plot comparing table of observed counts vs table of expected
135+
#' @returns Bar plot comparing table of observed counts vs table of expected
107136
#' counts
108137
#'
109138
#' @examples

R/ageHeaping.R

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
#' very common. This is a major reason why data from nutritional anthropometry
88
#' surveys is often analysed and reported using broad age groups.
99
#'
10-
#' @param x Vector of ages
10+
#' @param x A vector of ages. Should either be in whole months (integer) or in
11+
#' calculated decimal months (numeric).
1112
#' @param divisor Divisor (usually 5, 6, 10, or 12); default is 12
1213
#'
13-
#' @return A list of class "ageHeaping" with:
14+
#' @returns A list of class "ageHeaping" with:
1415
#'
1516
#' | **Variable** | **Description** |
1617
#' | :--- | :--- |
@@ -38,12 +39,14 @@
3839
################################################################################
3940

4041
ageHeaping <- function(x, divisor = 12) {
42+
## If x is not numeric or integer ----
43+
if (!is.numeric(x) & !is.integer(x))
44+
stop("Age should be of class integer or numeric. Try again.")
45+
4146
dataName <- deparse(substitute(x))
4247
r <- x %% divisor
4348
tab <- fullTable(r, values = 0:(divisor - 1))
44-
names(dimnames(tab)) <- paste("Remainder of ",
45-
dataName, " / ",
46-
divisor, sep = "")
49+
names(dimnames(tab)) <- paste0("Remainder of ", dataName, " / ", divisor)
4750
chiSq <- stats::chisq.test(tab)
4851
pct <- round(prop.table(tab) * 100, 1)
4952
result <- list(X2 = chiSq$statistic, df = chiSq$parameter,
@@ -60,7 +63,7 @@ ageHeaping <- function(x, divisor = 12) {
6063
#' @param x Object resulting from applying the [ageHeaping()] function
6164
#' @param ... Additional [print()] arguments
6265
#'
63-
#' @return Printed output of the [ageHeaping()] function
66+
#' @returns Printed output of the [ageHeaping()] function
6467
#'
6568
#' @examples
6669
#' # Print age heaping test on SMART survey data in Kabul, Afghanistan (dp.ex02)
@@ -93,7 +96,7 @@ print.ageHeaping <- function(x, ...) {
9396
#' @param cex Character expansion (numeric); default is 0.75
9497
#' @param ... Additional [plot()] graphical parameters
9598
#'
96-
#' @return Barplot of frequency of remainders of age when divided by a specified
99+
#' @returns Barplot of frequency of remainders of age when divided by a specified
97100
#' divisor
98101
#'
99102
#' @examples

R/ageRatioTest.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#' of the observed ratio to the expected ratio is then compared statistically
1010
#' using Chi-squared test.
1111
#'
12-
#' @param x A vector for age. Should either be in whole months (integer) or in
12+
#' @param x A vector of ages. Should either be in whole months (integer) or in
1313
#' calculated decimal months (numeric).
1414
#' @param ratio Expected age ratio. Default is 0.85.
1515
#'
@@ -75,7 +75,7 @@ ageRatioTest <- function(x, ratio = 0.85) {
7575
#' @param x Object resulting from applying [ageRatioTest()] function
7676
#' @param ... Additional [print()] arguments
7777
#'
78-
#' @return Printed output of [ageRatioTest()] function
78+
#' @returns Printed output of [ageRatioTest()] function
7979
#'
8080
#' @examples
8181
#' # Print age-ratio test results for survey dataset from Kabul, Afghanistan

R/boxText.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#' @param lwd Border width
1111
#' @param pad Add padding to (L) and (R) ends of bounding box
1212
#'
13-
#' @return NULL
13+
#' @returns NULL
1414
#'
1515
#' @examples
1616
#' ## Use of boxtext in the ageHeaping plot function

R/digitPreference.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
#' WHO MONICA Project e-publications No. 9, WHO, Geneva, May 1998 available
1818
#' from \url{https://www.thl.fi/publications/monica/bp/bpqa.htm}}
1919
#'
20-
#' @param x Numeric vector
21-
#' @param digits Number of decimal places in `x`. using `digits = 1`
20+
#' @param x Numeric vector of measurements
21+
#' @param digits Number of decimal places in `x`. Using `digits = 1`
2222
#' (e.g.) allows 105 to be treated as 105.0
2323
#' @param values A vector of possible values for the final digit (default = 0:9)
2424
#'
25-
#' @return A list of class `"digitPreference"` with:
25+
#' @returns A list of class `"digitPreference"` with:
2626
#'
2727
#' | **Variable** | **Description** |
2828
#' | :--- | :--- |
@@ -70,7 +70,7 @@ digitPreference <- function(x, digits = 1, values = 0:9) {
7070
#' @param x Object resulting from applying the [digitPreference()] function.
7171
#' @param ... Additional [print()] parameters
7272
#'
73-
#' @return Printed output of [digitPreference()] function
73+
#' @returns Printed output of [digitPreference()] function
7474
#'
7575
#' @examples
7676
#' # Print output of digit preference test applied to anthropometric data from a
@@ -102,7 +102,7 @@ print.digitPreference <- function(x, ...) {
102102
#' @param cex Character expansion; default is 0.75
103103
#' @param ... Additional [plot()] parameters
104104
#'
105-
#' @return Plotted output of [digitPreference()] function comparing the
105+
#' @returns Plotted output of [digitPreference()] function comparing the
106106
#' frequencies of the various final digits
107107
#'
108108
#' @examples

R/fullTable.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#' @param values A vector of values to be included in a table. Default is:
77
#' `min(x, na.rm = TRUE):max(x, na.rm = TRUE)`
88
#'
9-
#' @return A table object including zero cells
9+
#' @returns A table object including zero cells
1010
#'
1111
#' @examples
1212
#' # Generate some artificial data and then apply `fullTable()`

0 commit comments

Comments
 (0)