knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
The minihealth
package is a central component of
JAMES. The package
xyz
, bse
, ird
, individual
and cabinet
for analysing individual growth data; individual
, donordata
and bds
formats into each other;individual
objects.Install the development version minihealth
by
install.packages("remotes") remotes::install_github("stefvanbuuren/minihealth")
There is no release on CRAN.
The S4 class xyz
stores three variables useful for anthropometric data:
x
: usually age, but can also be height (in weight-for-height);y
: measurement, e.g. height or weight;z
: Z-score of y
conditional on x
.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.
# 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.
The S4 class individual
bundles four different types of information,
each of which is coded by its own class:
individualID
: ID information, like name, date of birth;individualBG
: Background, like sex, gestional age or etnicity;individualAN
: Bundles person's anthrometric data, like hgt
and wgt
;individualBS
: Bundles person's brokenstick estimates;individualRW
: Stores raw data, e.g. milestones;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
:
donordata_to_individual()
takes data in donordata
format, and converts it into individual
format;convert_bds_individual()
takes data in bds
format, and converts it into individual
format;See the respective documentation for more detail. Both functions have inverse (but lossy) transformations.
cabinet
is a collection of multiple objects of class individual
;data.frame(d1)
extracts the data frame from objects of class xyz
;get_xyz(rob, "hgt")
extracts the data frame from objects of class individual
;get_range(rob)
extract the age range from objects of class individual
.Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.