GithubHelp home page GithubHelp logo

insp-rh / bw Goto Github PK

View Code? Open in Web Editor NEW
4.0 5.0 4.0 13.49 MB

Dynamic Weight Change Model

License: Other

R 6.39% C++ 5.84% HTML 87.24% TeX 0.52%
r physiological body-weight estimate-weight-change energy-intake differential-equations hall mathematical-modelling

bw's Introduction

bw: Dynamic Body Weight Model

The bw package implements the Dynamic Weight Change model from Hall et al. for adults and the Children dynamic weight model from Hall et al for children.

Installation

To install the latest version please run the following code:

if (!require(devtools)){install.packages("devtools")}
devtools::install_github("INSP-RH/bw")

Adult Model

The main function to estimate weight change is adult_weight. It takes as input body weight (kg), height (m), age (yrs), sex (either "male" or "female") either as column vectors from a database or as individual level. In addition it takes a day-by-day matrix for change in energy intake from baseline (kcal/day) and another matrix for change in sodium (mg/day).

#Individual's parameters
bw  <- 80
ht  <- 1.8
age <- 32
sex <- "female"

#Matrix of energy intake change for 100 days
deltaEI     <- rep(-100, 365)

#Function of sodium intake
deltaNA     <- rep(-10, 365)

#Estimate weight change. 
wtrajectory  <- adult_weight(bw, ht, age, sex, deltaEI, deltaNA)

The variable wtrajectory is a list containing matrices of all the modelled variables:

names(wtrajectory)
##  [1] "Time"                   "Age"                   
##  [3] "Adaptive_Thermogenesis" "Extracellular_Fluid"   
##  [5] "Glycogen"               "Fat_Mass"              
##  [7] "Lean_Mass"              "Body_Weight"           
##  [9] "Body_Mass_Index"        "BMI_Category"          
## [11] "Energy_Intake"          "Correct_Values"

These can be plotted with model_plot:

model_plot(wtrajectory)

The model can also be used for computing weight change for several individuals at a time:

#Antropometric data
weights <- c(45, 67, 58, 92, 81)
heights <- c(1.30, 1.73, 1.77, 1.92, 1.73)
ages    <- c(45, 23, 66, 44, 23)
sexes   <- c("male", "female", "female", "male", "male") 

#Matrix of energy consumption reduction: 
EIchange <- rbind(rep(-100, 365), rep(-200, 365), rep(-200, 365), 
                  rep(-123, 365), rep(-50, 365))

#Returns a weight change matrix and other matrices
model_weight <- adult_weight(weights, heights, ages, sexes, 
                             EIchange)

model_plot(model_weight)

Average for included variables can be done:

model_mean(model_weight)
##   time               variable group     mean  SE_mean Lower_CI_mean
## 1    1                    Age     1 40.20000 8.046117      24.42990
## 2    1 Adaptive_Thermogenesis     1  0.00000 0.000000       0.00000
## 3    1    Extracellular_Fluid     1 17.68290 2.445504      12.88980
## 4    1               Glycogen     1  0.50000 0.000000       0.50000
## 5    1               Fat_Mass     1 16.11919 1.634683      12.91527
## 6    1              Lean_Mass     1 32.94791 4.340489      24.44071
##   Upper_CI_mean  variance SE_variance Lower_CI_variance Upper_CI_variance
## 1      55.97010 323.70000  148.838516         31.981870         615.41813
## 2       0.00000   0.00000    0.000000          0.000000           0.00000
## 3      22.47600  29.90246   16.471194         -2.380486          62.18541
## 4       0.50000   0.00000    0.000000          0.000000           0.00000
## 5      19.32311  13.36094    5.819498          1.954934          24.76695
## 6      41.45512  94.19923   31.078690         33.286112         155.11234

BMI prevalence can be computed:

adult_bmi(model_weight)
##   Day Group  BMI_Category Mean       2.5 %    97.5 %
## 1   1     1        Normal  0.6  0.11990883 1.0800912
## 2   1     1     Pre-Obese  0.4 -0.08009117 0.8800912
## 3   2     1 Mild Thinness  0.2 -0.19199280 0.5919928
## 4   2     1        Normal  0.4 -0.08009117 0.8800912
## 5   2     1     Pre-Obese  0.4 -0.08009117 0.8800912
## 6   2     1 Mild Thinness  0.2 -0.19199280 0.5919928

Children Model

The function child_weight estimates weight change the same way as adult_weight. It takes as input age (yrs), sex ("male" or "female"), fat free mass (kg), and fat mass (kg). The functions model_mean and model_plot can be also com A function of energy intake (kcals/yr) for all the years can be inputed.

#Antropometric data
FatFree <- c(32, 17.2, 18.8, 20, 24.1)
Fat     <- c(4.30, 2.02, 3.07, 1.12, 2.93)
ages    <- c(10, 6.2, 5.4, 4, 4.1)
sexes   <- c("male", "female", "female", "male", "male") 

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

#Plot
model_plot(model_weight)

Mean by sex:

model_mean(model_weight, group = sexes)
##   time      variable  group      mean   SE_mean Lower_CI_mean
## 1    1           Age female  5.800000 0.3162278      5.180205
## 2    1           Age   male  6.033333 1.8107191      2.484389
## 3    1 Fat_Free_Mass female  2.545000 0.4150489      1.731519
## 4    1 Fat_Free_Mass   male  2.783333 0.8406732      1.135644
## 5    1      Fat_Mass female 18.000000 0.6324555     16.760410
## 6    1      Fat_Mass   male 25.366667 3.2146943     19.065982
##   Upper_CI_mean  variance  SE_variance Lower_CI_variance Upper_CI_variance
## 1      6.419795  0.320000 5.488310e-16         0.3200000          0.320000
## 2      9.582278 11.803333 5.387460e+00         1.2441059         22.362561
## 3      3.358481  0.551250 0.000000e+00         0.5512500          0.551250
## 4      4.431023  2.544233 1.161278e+00         0.2681696          4.820297
## 5     19.239590  1.280000 0.000000e+00         1.2800000          1.280000
## 6     31.667352 37.203333 1.698092e+01         3.9213403         70.485326

Additional information on usage can be found on the package's vignette:

browseVignettes("bw")

bw's People

Contributors

dalia1992 avatar isajunbad avatar rodrigozepeda avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

bw's Issues

Cannot install with build_vignettes

Installing devtools::install_github("INSP-RH/bw", build_vignettes = TRUE) throws an error on the ChildrenModel.Rmdvignette. This has to do with the energy not being inputed as transposed.

Error in weight[["BMI_Category"]] : subscript out of bounds

The following code throws an error both for model_mean and adult_bmi


require(survey)
require(bw)

mydata <- data.frame(
  id = 1:5,
  weight = c(45, 67, 58, 92, 81),
  height = c(1.30, 1.73, 1.77, 1.92, 1.73),
  age = c(45, 23, 66, 44, 23),
  sex = c("male", "female", "female", "male", "male"),
  energy_change = runif(5, -200, 200),
  prob = c(0.1, 0.2, 0.2, 0.05, 0.45))

#Get energy change with energy build function
eichange      <- energy_build(cbind(rep(0,5), mydata$energy_change), c(0, 365))

#Returns a weight change matrix and other matrices
database_model <- adult_weight(mydata$weight, mydata$height, mydata$age, mydata$sex,
                               eichange)

design <- svydesign(ids = ~id, probs = ~prob, data = mydata)
adult_bmi(database_model, design = design)
model_mean(database_model, design = design)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.