knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

minihealth

The minihealth package is a central component of JAMES. The package

Installation

Install the development version minihealth by

install.packages("remotes")
remotes::install_github("stefvanbuuren/minihealth")

There is no release on CRAN.

Example 1: Automatic Z-score calculation

The S4 class xyz stores three variables useful for anthropometric data:

Here are some examples for automatic $Z$-score calculation:

library(minihealth)

# specify length (in cm) for boy at ages 0, 0.2 and 0.5 years
new("xyz", x = c(0, 0.2, 0.5), y = c(51.0, 54.1, 63.4))

# at the minimum, specify sex for automatic Z-score calculation
new("xyz", x = c(0, 0.2, 0.5), y = c(51.0, 54.1, 63.4), sex = "male")

# specify weight (in kg) at same ages
d1 <- new("xyz", x = c(0, 0.2, 0.5), y = c(3.2, 5.2, 7.0), 
          sex = "male", yname = "wgt")
d1

# View reference names used to calculate Z-scores in d1
data.frame(d1)

It is also possible to perform the reverse calculation, where z is given and y is calculated.

# Standard weight centiles at age 0.5 year of Dutch boys
new("xyz", x = rep(0.5, 5), z = -2:2, sex = "male", yname = "wgt")

# Extend to grid of ages: 0y, 0.5y and 1y
new("xyz", x = rep(c(0, 0.5, 1), each = 5), z = rep(-2:2, 3), 
    sex = "male", yname = "wgt")

See the help ("?xyz-class") and the centile package for more examples.

Example 2: Automatic brokenstick estimation

# specify three height measures
boy <- new("xyz", x = c(0, 0.2, 0.5), y = c(51.0, 54.1, 63.4), 
           sex = "male")
boy

# calculate broken stick estimates at observed ages
new("bse", data = boy)

# calculate broken stick estimates at all break points
new("bse", data = boy, at = "knots")

See the help ("?bse-class") and the brokenstick package for more examples.

Example 3: Bundle all measures by individual

The S4 class individual bundles four different types of information, each of which is coded by its own class:

Creating an instance of class individual can be done by hand in two steps. First, create one or more of the four subclasses, and then
tie these together, as follows:

pid <- new("individualID", name = c("Rob", "Dorchester"),
           dob = as.Date("2014-08-22", "%Y-%m-%d"), 
           id = as.integer(204))
pbg <- new("individualBG", sex = "male", hgtf = 185)
pan <- new("individualAN",
           hgt = new("xyz", 
                     x = c(0, 0.2, 0.5), 
                     y = c(51.0, 54.1, 63.4), 
                     sex = pbg@sex),
           wgt = new("xyz", 
                     x = c(0, 0.5), 
                     y = c(3.2, 7.0), 
                     yname = "wgt", 
                     sex = pbg@sex))
pbs <- new("individualBS",
           bs.hgt = new("bse", yname = "hgt",
                        data = pan@hgt,
                        at = "knots",
                        sex = pbg@sex),
           bs.wgt = new("bse", yname = "wgt", 
                        data = pan@wgt, 
                        at = "knots",
                        sex = pbg@sex))
data <- data.frame(age = c(0.2, 0.5, 0.7),
                   k1430 = c(1, NA, NA),
                   k1431 = c(2, NA, NA),
                   k1437 = c(3, 1, 1),
                   k1438 = c(0, 1, 1),
                   k1439 = c(0, 1, 1))
map <- data.frame(from = c("k1430", "k1431", "k1437", "k1438", "k1439"),
                  to = c(879, 927, 928, 881, 883))
prw <- new("individualRW",
           ddi = new("ird", mst = data, map = map, instrument = "ddi"))

rob <- new("individual", pid, pbg, pan, pbs, prw)

Doing this sequence by hand is somewhat inconvenient. Fortunately, there are two functions that convert other formats into an object of class individual:

See the respective documentation for more detail. Both functions have inverse (but lossy) transformations.

Miscellaneous functionality



stefvanbuuren/minihealth documentation built on March 11, 2021, 7:10 p.m.