# Using the Children Weight Model In bw: Dynamic Body Weight Models for Children and Adults

require("bw")
require("ggplot2")


In this vignette we explain how to use the model for children in R; we develop and explain the equations involved both for casual and advanced readers.

# Usage in R {#user}

## Inputs

The main inputs for the body weight change model in children are:

| Input | Meaning | Optional | Default | |------:|------:|------:|------:| | age | Age (yrs) | No | - | | sex | Either 'male' or 'female' | No | - |

As an example consider a 7 year old 'female':

female_model1 <- child_weight(age = 7, sex = "female")


Furthermore, the model allows the user to input Fat and Fat Free Mass composition of the body:

| Input | Meaning | Optional | Default | |------:|------:|------:|------:| | FM | Fat Mass (kg) | Yes | Model estimate | | FFM | Fat Free Mass (kg) | Yes | Model estimate |

For example, our female might have 19.9 kg of Fat Mass and 5.74 kg of Fat Free Mass:

female_model2 <- child_weight(age = 7, sex = "female", FM = 19.9, FFM = 5.74)


Energy intake can also be inputed as a vector of daily energy consumption:

| Input | Meaning | Optional | Default | |------:|------:|------:|------:| | EI | Energy Intake per day | Yes | Model estimate |

female_model3 <- child_weight(age = 7, sex = "female", FM = 19.9, FFM = 5.74,
EI = seq(1600, 1750, length.out = 365))


Note that in the examples above, EIchange = seq(1600, 1750, length.out = 365) is inputed as a vector with each day representing the consumption reduction for that day. See Energy section for additional information.

Other (optional) inputs include:

| Input | Meaning | Optional | Default | |------:|------:|------:|------:| | days | Number of days to run de model | Yes | $365$ | | dt | Time step for Rungue-Kutta 4 | Yes | $1$ | | checkValues | Boolean indicating whether the model should check parameters make sense | Yes | TRUE |

All inputs used in the model are:

| Input | Meaning | Optional | Default | |------:|------:|------:|------:| | age | Age (yrs) | No | - | | sex | Either 'male' or 'female' | No | - | | FM | Fat Mass (kg) | Yes | Model estimate | | FFM | Fat Free Mass (kg) | Yes | Model estimate | | EI | Energy Intake per day | Yes | Model estimate | | days | Time period (days) to run the model | Yes | $365$ | | dt | Time step for Rungue-Kutta 4 | Yes | $1$ | | checkValues | Check for internal consistency | Yes | TRUE |

Finally, we remark that one can also input data from a database to estimate individual-level weight change (see the related section)

#Database information
ages    <- c(8, 10, 7, 7, 12)
sexes   <- c("male", "female", "female", "male", "male")

#Returns a weight change matrix and other matrices
database_model <- child_weight(ages, sexes)


## Plots

Result plots can be obtained by model_plot function:

model_plot(female_model2, "Body_Weight")


Plotting options include "Body_Weight", Fat_Mass, and Fat_Free_Mass. Several can be chosen at the same time:

model_plot(female_model2, c("Body_Weight", "Fat_Mass"))


Variables can also be plotted against age:

model_plot(female_model2, c("Body_Weight", "Fat_Mass"), timevar = "Age")


## Energy

Energy intake is usually not continuously measured but measured at different and distant points in time (say 1 year apart). The function energy_build allows the user to interpolate different energy models between the interpolation points. As an example consider an individual that initially consumed 1600 kcals, by day 365 consumed in 1750 kcals and by day 730 had increased his consumption to 1820 kcals. The energy_build function interpolates those values via a Brownian Bridge:

EIbrownian <- energy_build(c(1600, 1750, 1820), c(0, 365, 730))


The interpolation looks like this:

ggplot() + geom_line(aes(x = 1:730, y = EI), data = data.frame(EI = EIbrownian)) +
theme_classic() +
xlab("Days") + ylab("Energy intake (kcals)") + ggtitle("Energy interpolation")


Such energy change matrix can be directly inputed in the model:

model_brownian <- child_weight(10, "male", EI = EIbrownian, days = 730)


Other interpolation modes include Linear, Exponential, Stepwise_R (right stepwise), Stepwise_L (left stepwise), and Logarithmic:

EIlinear      <- energy_build(c(1600, 1750, 1820), c(0, 365, 730), "Linear")
EIexponential <- energy_build(c(1600, 1750, 1820), c(0, 365, 730), "Exponential")
EIstepwise_r  <- energy_build(c(1600, 1750, 1820), c(0, 365, 730), "Stepwise_R")
EIstepwise_l  <- energy_build(c(1600, 1750, 1820), c(0, 365, 730), "Stepwise_L")
EIlogarithmic <- energy_build(c(1600, 1750, 1820), c(0, 365, 730), "Logarithmic")


Which look like this:

ggplot() +
geom_line(aes(x = 1:730, y = EI, color = "Brownian"),
data = data.frame(EI = EIbrownian)) +
geom_line(aes(x = 1:730, y = EI, color = "Linear"),
data = data.frame(EI = EIlinear)) +
geom_line(aes(x = 1:730, y = EI, color = "Exponential"),
data = data.frame(EI = EIexponential)) +
geom_step(aes(x = 1:730, y = EI, color = "Right Stepwise"),
data = data.frame(EI = EIstepwise_r)) +
geom_step(aes(x = 1:730, y = EI, color = "Left Stepwise"),
data = data.frame(EI = EIstepwise_l)) +
geom_line(aes(x = 1:730, y = EI, color = "Logarithmic"),
data = data.frame(EI = EIlogarithmic)) +
xlab("Days") + ylab("Energy change (kcals)") +
ggtitle("Energy interpolation") +
theme_classic() +
scale_color_manual("Interpolation",
values = c("Brownian" = "red", "Linear" = "deepskyblue3",
"Exponential" = "forestgreen", "Logarithmic" = "purple",
"Right Stepwise" = "black", "Left Stepwise" = "green"))


These models result in different weight changes:

model_linear      <- child_weight(10, "male", EI = EIlinear, days = 730)
model_exponential <- child_weight(10, "male", EI = EIexponential, days = 730)
model_logarithmic <- child_weight(10, "male", EI = EIlogarithmic, days = 730)
model_stepwise_r  <- child_weight(10, "male", EI = EIstepwise_r, days = 730)
model_stepwise_l  <- child_weight(10, "male", EI = EIstepwise_l, days = 730)


Which look as follows:

ggplot() +
geom_line(aes(x = 1:730, y = as.vector(model_linear[["Body_Weight"]]), color = "Linear")) +
geom_line(aes(x = 1:730, y = as.vector(model_exponential[["Body_Weight"]]), color = "Exponential")) +
geom_line(aes(x = 1:730, y = as.vector(model_logarithmic[["Body_Weight"]]), color = "Logarithmic")) +
geom_line(aes(x = 1:730, y = as.vector(model_stepwise_r[["Body_Weight"]]), color = "Right Stepwise")) +
geom_line(aes(x = 1:730, y = as.vector(model_stepwise_l[["Body_Weight"]]), color = "Left Stepwise")) +
geom_line(aes(x = 1:730, y = as.vector(model_brownian[["Body_Weight"]]), color = "Brownian")) +
xlab("Days") + ylab("Weight (kg)") +
theme_classic()+
ggtitle("Weight change under different energy interpolations") +
scale_color_manual("Interpolation",
values = c("Brownian" = "red", "Linear" = "deepskyblue3",
"Exponential" = "forestgreen", "Logarithmic" = "purple",
"Right Stepwise" = "black", "Left Stepwise" = "green"))


## Using Richardson's function

The children model includes the option richardsonparams which is a list of parameters $list(K = NA, Q = NA, B = NA, A = NA, nu = NA, C = NA)$ representing $K, Q, \beta, A, \nu, C$. If parameters are specified, the model assumes the energy intake function is a generalized logistic function (Richardson's function @falkner2012human): $$EI(t) = A + \frac{K-A}{(C + Q e^{-\beta \cdot t})^{1/\nu}}.$$

girl <- child_weight(6,"female", days=365, dt = 5,
richardsonparams = list(K = 2700, Q = 10,
B = 12, A = 3, nu = 4,
C = 1))
model_plot(girl, "Body_Weight")


## Estimating weight change of a database

Vector data can also be used in the model to calculate weight change for several individuals at a time (which is quite faster than doing them individually). As an example consider the following dataset:

#Database information
mydata <- data.frame(
id = 1:5,
age = c(8, 10, 7, 7, 12),
sex = c("male", "female", "female", "male", "male"),
energy = runif(5, 1500, 2000),
prob = c(0.1, 0.2, 0.2, 0.05, 0.45))

#Get energy change with energy build function
eichange      <- energy_build(cbind(runif(5, 1500, 2000), mydata$energy), c(0, 365)) #Returns a weight change matrix and other matrices database_model <- child_weight(mydata$age, mydata$sex, EI = t(eichange))  Plots can also be obtained for the population with the same command model_plot: model_plot(database_model, "Body_Weight")  Summary measures can be obtained via model_mean which quantifies mean for 'Body_Weight', 'Fat_Free_Mass', and 'Fat_Mass': model_mean(database_model, "Body_Weight")  head(model_mean(database_model, "Body_Weight"))[,1:5]  Mean is only estimated for some points in time, to estimate mean for the whole period, consider changing the days vector variable: model_mean(database_model, "Body_Weight", days = 1:365)  head(model_mean(database_model, "Body_Weight", days = 1:365))[,1:5]  Mean can also be grouped by a variable (say, sex): model_mean(database_model, "Body_Weight", days = 1:365, group = mydata$sex)

head(model_mean(database_model, "Body_Weight", days = 1:365, group = mydata$sex))[,1:5]  Finally, model_mean can also be used to estimate survey means using the svydesign from the survey package: require("survey") design <- svydesign(ids = ~id, probs = ~prob, data = mydata) model_mean(database_model, group = mydata$sex, design = design)

require("survey")
design <- svydesign(ids = ~id, probs = ~prob, data = mydata)

# Additional information

Additional information on the adult's model, and why to use the dynamic adult model instead of other classical approaches can be found in the package's vignettes:

browseVignettes("bw")


# References

## Try the bw package in your browser

Any scripts or data that you put into this service are public.

bw documentation built on July 5, 2018, 5:03 p.m.