# install.packages("devtools")
# library(express)
# library(flexsurv)
# library(devtools)
# devtools::install_github("dayoonkwon/BioAge")
# library(Matrix)
library(BioAge) #topic of example
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union

###Step 1: train algorithms in NHANES III and project biological aging measures in NHANES IV I train in the NHANES III and project biological aging measures into the NHANES IV by using the hd_nhanes, kdm_nhanes, and phenoage_nhanes function of the BioAge package.

#HD using NHANES (separate training for men and women)
hd = hd_nhanes(biomarkers=c("albumin","alp","lncrp","totchol","lncreat","hba1c","sbp","bun","uap","lymph","mcv","wbc"))

#KDM bioage using NHANES (separate training for men and women)
kdm = kdm_nhanes(biomarkers=c("albumin","alp","lncrp","totchol","lncreat","hba1c","sbp","bun","uap","lymph","mcv","wbc"))

#phenoage uinsg NHANES
phenoage = phenoage_nhanes(biomarkers=c("albumin_gL","alp","lncrp","totchol","lncreat_umol","hba1c","sbp","bun","uap","lymph","mcv","wbc"))

###Step 2: compare original KDM bioage and phenoage algorithms with algorithms composed with new biomarker set The projected data and estimated models are saved as part of the list structure. The dataset can be drawn by typing data. The model can be drawn by typing fit.

#assemble NHANES IV dataset with projected biological aging measures for analysis
data = merge(hd$data, kdm$data) %>% merge(., phenoage$data)

###Figure1. Association of biological aging measures with chronological age in NAHNES IV dataset In the figure below, the graphs titled “KDM Biological Age” and “Levine Phenotypic Age” show measures based on the original biomarker sets published in Levine 2013 J Geron A and Levine et al. 2018 AGING. The remaining graphs shows the new measures computed with the biomarker set specified within this code.

#select biological age variables
agevar = c("kdm0","phenoage0","kdm","phenoage","hd","hd_log")

label = c("KDM\nBiological Age",
          "Levine\nPhenotypic Age",
          "Modified-KDM\nBiological Age",
          "Modified-Levine\nPhenotypic Age",
          "Homeostatic\nDysregulation",
          "Log\nHomeostatic\nDysregulation")

#plot age vs bioage
plot_ba(data, agevar, label)
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 140840 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 140840 rows containing missing values (`geom_point()`).

###Figure2. Correlations among biological aging measures The figure plots associations among the different biological aging measures. Cells below the diagonal show scatter plots of the measures listed above the cell (x-axis) and to the right (y-axis). Cells above the diagonal show the Pearson correlations for the measures listed below the cell and to the left. For this analysis, KDM Biological Age and Levine Phenotypic Age measures are differenced from chronological age (i.e. plotted values = BA-CA).

#select biological age variables
agevar = c("kdm_advance0","phenoage_advance0","kdm_advance","phenoage_advance","hd","hd_log")

#prepare lables
#values should be formatted for displaying along diagonal of the plot
#names should be used to match variables and order is preserved
label = c(
  "kdm_advance0"="KDM\nBiological Age\nAdvancement",
  "phenoage_advance0"="Levine\nPhenotypic Age\nAdvancement",
  "kdm_advance"="Modified-KDM\nBiological Age\nAdvancement",
  "phenoage_advance"="Modified-Levine\nPhenotypic Age\nAdvancement",
  "hd" = "Homeostatic\nDysregulation",
  "hd_log" = "Log\nHomeostatic\nDysregulation")

#use variable name to define the axis type ("int" or "float")
axis_type = c(
  "kdm_advance0"="float",
  "phenoage_advance0"="float",
  "kdm_advance"="float",
  "phenoage_advance"="flot",
  "hd"="flot",
  "hd_log"="float")

#plot BAA corplot
plot_baa(data,agevar,label,axis_type)

###Table 1. Associations of biological aging measures with mortality

table_surv(data, agevar, label)
Table 1. Associations of biological aging measures with mortality. BioAge coefficients in the table are hazard ratios estimated from Cox proportional hazard regressions. KDM Biological Age and Levine Phenotypic Age measures were differenced from chronological age for analysis (i.e. values = BA-CA). These differenced values were then standardized to have M=0, SD=1 separately for men and women within the analysis sample so that effect-sizes are denominated in terms of a sex-specific 1 SD unit increase in biological age advancement. Models included covariates for chronological age and sex. The original KDM Biological Age algorithm (left-most column) was projected onto data from NHANES 2007-2010 only because other NHANES IV waves did not include spirometry measurements. The original Levine Phenotypic Age algorithm (second column from left) was projected onto data from NHANES 1999-2010 and 2015-2018 only because the intervening waves did not include CRP measurements.
KDM Biological Age Advancement Levine Phenotypic Age Advancement Modified-KDM Biological Age Advancement Modified-Levine Phenotypic Age Advancement Homeostatic Dysregulation Log Homeostatic Dysregulation
Hazard Ratio (95% CI)
Full Sample
  n 8234 27837 26580 26580 26580 26580
  BioAge 1.36 (1.2, 1.55) 1.47 (1.42, 1.51) 1.26 (1.22, 1.31) 1.43 (1.37, 1.49) 1.35 (1.3, 1.4) 1.44 (1.38, 1.51)
Stratified by Gender
Men
  n 4114 13421 12879 12879 12879 12879
  BioAge 1.44 (1.23, 1.69) 1.44 (1.38, 1.5) 1.28 (1.22, 1.34) 1.41 (1.34, 1.49) 1.32 (1.26, 1.38) 1.4 (1.32, 1.49)
Women
  n 4120 14416 13701 13701 13701 13701
  BioAge 1.23 (0.98, 1.54) 1.52 (1.45, 1.6) 1.24 (1.18, 1.31) 1.46 (1.37, 1.55) 1.39 (1.32, 1.48) 1.53 (1.41, 1.66)
Stratified by Race
White
  n 3937 13958 13447 13447 13447 13447
  BioAge 1.44 (1.21, 1.72) 1.54 (1.47, 1.6) 1.28 (1.22, 1.34) 1.49 (1.42, 1.58) 1.42 (1.35, 1.49) 1.52 (1.43, 1.63)
Black
  n 1467 5176 4851 4851 4851 4851
  BioAge 1.51 (1.15, 1.99) 1.37 (1.28, 1.47) 1.26 (1.17, 1.35) 1.36 (1.26, 1.48) 1.33 (1.23, 1.43) 1.47 (1.31, 1.64)
Other
  n 2830 8703 8282 8282 8282 8282
  BioAge 1.21 (0.89, 1.65) 1.37 (1.28, 1.48) 1.19 (1.1, 1.29) 1.3 (1.19, 1.42) 1.23 (1.14, 1.33) 1.27 (1.15, 1.4)
People Aged 65 and Younger
Aged 65 and Younger
  n 6915 21252 20344 20344 20344 20344
  BioAge 1.27 (1.06, 1.53) 1.61 (1.52, 1.7) 1.34 (1.25, 1.44) 1.51 (1.41, 1.61) 1.45 (1.36, 1.54) 1.54 (1.42, 1.67)

###Table 2. Associations of biological aging measures with healthspan-related characteristics The linear regression models and sample sizes in “Table 2” and “Table 3” below are saved as part of the list structure. Regression model can be drawn by typing table. Sample size can be drawn by typing n.

table2 = table_health(data,agevar,outcome = c("health","adl","lnwalk","grip_scaled"), label)

#pull table
table2$table
Table 2. Associations of biological aging measures with healthspan-related characteristics. Coefficients are from linear regressions of healthspan-related characteristics on biological aging measures. Outcome variables were standardized to have M=0, SD=1 for analysis. Standardization was performed separately for men and women in the case of grip strength. Walk speed was log transformed prior to standardization to reduce skew. KDM Biological Age and Levine Phenotypic Age measures were differenced from chronological age for analysis (i.e. values = BA-CA). These differenced values were then standardized to have M=0, SD=1 separately for men and women within the analysis sample so that effect-sizes are denominated in terms of a sex-specific 1 SD unit increase in biological age advancement. Models included covariates for chronological age and sex. The original KDM Biological Age algorithm (left-most column) was projected onto data from NHANES 2007-2010 only because other NHANES IV waves did not include spirometry measurements. The original Levine Phenotypic Age algorithm (second column from left) was projected onto data from NHANES 1999-2010 and 2015-2018 only because the intervening waves did not include CRP measurements. Walk speed was measured only in NHANES 1999-2002 and is available only for participants aged 50 and older. Grip strength was measured only in NHANES 2011-2014.
KDM Biological Age Advancement Levine Phenotypic Age Advancement Modified-KDM Biological Age Advancement Modified-Levine Phenotypic Age Advancement Homeostatic Dysregulation Log Homeostatic Dysregulation
b (95% CI)
Full Sample
  health 0.25 (0.23, 0.27) 0.21 (0.2, 0.22) 0.15 (0.14, 0.16) 0.18 (0.17, 0.19) 0.23 (0.21, 0.24) 0.23 (0.22, 0.24)
  adl 0.13 (0.1, 0.16) 0.17 (0.15, 0.19) 0.09 (0.08, 0.11) 0.14 (0.13, 0.16) 0.11 (0.1, 0.13) 0.12 (0.11, 0.14)
  lnwalk - 0.21 (0.18, 0.24) 0.1 (0.07, 0.12) 0.15 (0.12, 0.18) 0.15 (0.12, 0.18) 0.17 (0.14, 0.2)
  grip_scaled - - - - - -
Stratified by Gender
Men
  health 0.23 (0.2, 0.26) 0.22 (0.2, 0.23) 0.17 (0.15, 0.18) 0.18 (0.17, 0.2) 0.21 (0.2, 0.23) 0.22 (0.2, 0.24)
  adl 0.12 (0.08, 0.15) 0.15 (0.13, 0.17) 0.1 (0.08, 0.12) 0.12 (0.1, 0.14) 0.09 (0.07, 0.11) 0.1 (0.08, 0.13)
  lnwalk - 0.16 (0.12, 0.2) 0.08 (0.05, 0.12) 0.11 (0.07, 0.14) 0.12 (0.08, 0.15) 0.14 (0.1, 0.18)
  grip_scaled - - - - - -
Women
  health 0.28 (0.25, 0.31) 0.22 (0.2, 0.23) 0.14 (0.12, 0.15) 0.17 (0.15, 0.19) 0.24 (0.22, 0.26) 0.24 (0.23, 0.26)
  adl 0.14 (0.09, 0.19) 0.19 (0.17, 0.22) 0.08 (0.06, 0.11) 0.16 (0.14, 0.19) 0.14 (0.12, 0.17) 0.16 (0.13, 0.19)
  lnwalk - 0.27 (0.22, 0.31) 0.11 (0.07, 0.15) 0.19 (0.14, 0.23) 0.18 (0.13, 0.22) 0.21 (0.16, 0.26)
  grip_scaled - - - - - -
Stratified by Race
White
  health 0.3 (0.27, 0.33) 0.27 (0.25, 0.28) 0.17 (0.15, 0.18) 0.25 (0.23, 0.26) 0.24 (0.23, 0.26) 0.24 (0.23, 0.26)
  adl 0.15 (0.11, 0.19) 0.2 (0.18, 0.22) 0.1 (0.08, 0.12) 0.17 (0.15, 0.19) 0.13 (0.11, 0.15) 0.13 (0.11, 0.16)
  lnwalk - 0.25 (0.21, 0.28) 0.12 (0.09, 0.15) 0.18 (0.15, 0.22) 0.15 (0.11, 0.19) 0.16 (0.12, 0.2)
  grip_scaled - - - - - -
Black
  health 0.18 (0.13, 0.22) 0.17 (0.14, 0.19) 0.15 (0.13, 0.18) 0.16 (0.14, 0.18) 0.2 (0.17, 0.22) 0.21 (0.18, 0.24)
  adl 0.08 (0, 0.16) 0.13 (0.1, 0.17) 0.08 (0.05, 0.12) 0.11 (0.08, 0.15) 0.11 (0.07, 0.15) 0.12 (0.07, 0.17)
  lnwalk - 0.14 (0.07, 0.21) 0.03 (-0.03, 0.1) 0.1 (0.03, 0.17) 0.08 (0.01, 0.15) 0.11 (0.02, 0.2)
  grip_scaled - - - - - -
Other
  health 0.15 (0.11, 0.19) 0.15 (0.13, 0.17) 0.11 (0.09, 0.13) 0.13 (0.11, 0.15) 0.17 (0.15, 0.19) 0.17 (0.15, 0.19)
  adl 0.15 (0.09, 0.21) 0.15 (0.12, 0.18) 0.09 (0.06, 0.12) 0.12 (0.09, 0.15) 0.1 (0.07, 0.13) 0.12 (0.08, 0.15)
  lnwalk - 0.15 (0.09, 0.21) 0.01 (-0.04, 0.07) 0.08 (0.03, 0.14) 0.06 (0.01, 0.11) 0.07 (0.01, 0.14)
  grip_scaled - - - - - -
Stratified by Age
Age 20-40
  health 0.21 (0.17, 0.25) 0.19 (0.17, 0.21) 0.15 (0.12, 0.17) 0.12 (0.1, 0.14) 0.19 (0.16, 0.22) 0.15 (0.13, 0.18)
  adl 0.02 (-0.08, 0.13) 0.11 (0.06, 0.17) 0.04 (-0.02, 0.1) 0.07 (0.02, 0.12) 0.06 (0, 0.13) 0.06 (0, 0.12)
  lnwalk - - - - - -
  grip_scaled - - - - - -
Age 40-60
  health 0.28 (0.25, 0.32) 0.26 (0.24, 0.28) 0.19 (0.17, 0.21) 0.22 (0.2, 0.24) 0.28 (0.26, 0.3) 0.28 (0.26, 0.3)
  adl 0.18 (0.09, 0.27) 0.17 (0.12, 0.21) 0.09 (0.05, 0.14) 0.12 (0.08, 0.17) 0.15 (0.1, 0.2) 0.17 (0.12, 0.22)
  lnwalk - 0.22 (0.17, 0.27) 0.15 (0.1, 0.19) 0.17 (0.13, 0.22) 0.21 (0.17, 0.26) 0.22 (0.17, 0.26)
  grip_scaled - - - - - -
Age 60-80
  health 0.26 (0.22, 0.3) 0.21 (0.19, 0.23) 0.14 (0.12, 0.15) 0.2 (0.18, 0.22) 0.22 (0.2, 0.24) 0.26 (0.24, 0.28)
  adl 0.11 (0.08, 0.15) 0.16 (0.14, 0.17) 0.09 (0.07, 0.11) 0.14 (0.12, 0.16) 0.11 (0.1, 0.13) 0.12 (0.1, 0.15)
  lnwalk - 0.21 (0.17, 0.25) 0.09 (0.06, 0.13) 0.14 (0.1, 0.18) 0.14 (0.1, 0.17) 0.16 (0.12, 0.2)
  grip_scaled - - - - - -
#pull sample sizes
table2$n
Table 2.1. Sample sizes for regression in Table 2. Coefficients are from linear regressions of healthspan-related characteristics on biological aging measures.
KDM Biological Age Advancement Levine Phenotypic Age Advancement Modified-KDM Biological Age Advancement Modified-Levine Phenotypic Age Advancement Homeostatic Dysregulation Log Homeostatic Dysregulation
n
Full Sample
  health 7886 31077 30235 30235 30235 30235
  adl 2812 14005 13512 13512 13512 13512
  lnwalk - 3607 3531 3531 3531 3531
  grip_scaled - - - - - -
Stratified by Gender
Men
  health 3974 15213 14849 14849 14849 14849
  adl 1407 6921 6715 6715 6715 6715
  lnwalk - 1795 1768 1768 1768 1768
  grip_scaled - - - - - -
Women
  health 3912 15864 15386 15386 15386 15386
  adl 1405 7084 6797 6797 6797 6797
  lnwalk - 1812 1763 1763 1763 1763
  grip_scaled - - - - - -
Stratified by Race
White
  health 3802 14634 14305 14305 14305 14305
  adl 1537 7464 7256 7256 7256 7256
  lnwalk - 2122 2098 2098 2098 2098
  grip_scaled - - - - - -
Black
  health 1397 5938 5732 5732 5732 5732
  adl 501 2486 2356 2356 2356 2356
  lnwalk - 547 525 525 525 525
  grip_scaled - - - - - -
Other
  health 2687 10505 10198 10198 10198 10198
  adl 774 4055 3900 3900 3900 3900
  lnwalk - 938 908 908 908 908
  grip_scaled - - - - - -
Stratified by Age
Age 20-40
  health 2864 10445 10161 10161 10161 10161
  adl 298 1337 1286 1286 1286 1286
  lnwalk - - - - - -
  grip_scaled - - - - - -
Age 40-60
  health 2830 9866 9630 9630 9630 9630
  adl 497 2180 2092 2092 2092 2092
  lnwalk - 1017 991 991 991 991
  grip_scaled - - - - - -
Age 60-80
  health 2192 9916 9661 9661 9661 9661
  adl 2017 9622 9321 9321 9321 9321
  lnwalk - 2133 2092 2092 2092 2092
  grip_scaled - - - - - -

Table 3. Associations of socioeconomic circumstances measures with measures of biological aging

table3 = table_ses(data,agevar,exposure = c("edu","annual_income","poverty_ratio"), label)

#pull table
table3$table
Table 3. Associations of socioeconomic circumstances measures with measures of biological aging. Coefficients are from linear regressions of biological aging measures on measures of socioeconomic circumstances. KDM Biological Age and Levine Phenotypic Age measures were differenced from chronological age for analysis (i.e. values = BA-CA). These differenced values were then standardized to have M=0, SD=1 separately for men and women within the analysis sample. Socioeconomic circumstances measures were standardized to M=0, SD=1 for analysis so that effect-sizes are denominated in terms of a 1 SD unit improvement in socioeconomic circumstances. Models included covariates for chronological age and sex. The original KDM Biological Age algorithm (left-most column) was projected onto data from NHANES 2007-2010 only because other NHANES IV waves did not include spirometry measurements. The original Levine Phenotypic Age algorithm (second column from left) was projected onto data from NHANES 1999-2010 and 2015-2018 only because the intervening waves did not include CRP measurements.
KDM Biological Age Advancement Levine Phenotypic Age Advancement Modified-KDM Biological Age Advancement Modified-Levine Phenotypic Age Advancement Homeostatic Dysregulation Log Homeostatic Dysregulation
b (95% CI)
Full Sample
  edu -0.19 (-0.22, -0.17) -0.07 (-0.08, -0.06) -0.07 (-0.08, -0.06) -0.09 (-0.1, -0.07) -0.11 (-0.12, -0.1) -0.11 (-0.12, -0.1)
  annual_income -0.17 (-0.19, -0.15) -0.11 (-0.12, -0.1) -0.08 (-0.09, -0.07) -0.12 (-0.13, -0.11) -0.12 (-0.13, -0.11) -0.11 (-0.12, -0.11)
  poverty_ratio -0.18 (-0.21, -0.16) -0.14 (-0.15, -0.13) -0.07 (-0.08, -0.06) -0.11 (-0.12, -0.1) -0.12 (-0.13, -0.11) -0.12 (-0.13, -0.11)
Stratified by Gender
Men
  edu -0.21 (-0.24, -0.18) -0.08 (-0.09, -0.06) -0.08 (-0.09, -0.06) -0.09 (-0.11, -0.08) -0.1 (-0.11, -0.09) -0.1 (-0.11, -0.09)
  annual_income -0.16 (-0.19, -0.13) -0.1 (-0.11, -0.08) -0.06 (-0.08, -0.05) -0.11 (-0.13, -0.1) -0.11 (-0.12, -0.09) -0.1 (-0.12, -0.09)
  poverty_ratio -0.18 (-0.21, -0.15) -0.12 (-0.13, -0.1) -0.07 (-0.08, -0.05) -0.11 (-0.12, -0.09) -0.11 (-0.13, -0.1) -0.11 (-0.12, -0.1)
Women
  edu -0.18 (-0.21, -0.15) -0.08 (-0.1, -0.07) -0.06 (-0.08, -0.05) -0.08 (-0.1, -0.07) -0.12 (-0.13, -0.1) -0.12 (-0.13, -0.1)
  annual_income -0.18 (-0.21, -0.15) -0.12 (-0.13, -0.11) -0.09 (-0.1, -0.07) -0.13 (-0.15, -0.12) -0.13 (-0.14, -0.12) -0.12 (-0.14, -0.11)
  poverty_ratio -0.19 (-0.22, -0.16) -0.15 (-0.17, -0.14) -0.07 (-0.08, -0.05) -0.11 (-0.13, -0.1) -0.13 (-0.14, -0.12) -0.12 (-0.13, -0.11)
Stratified by Race
White
  edu -0.24 (-0.27, -0.21) -0.14 (-0.15, -0.12) -0.1 (-0.11, -0.08) -0.17 (-0.19, -0.16) -0.11 (-0.13, -0.1) -0.12 (-0.13, -0.1)
  annual_income -0.18 (-0.21, -0.15) -0.14 (-0.16, -0.13) -0.09 (-0.1, -0.07) -0.17 (-0.18, -0.15) -0.12 (-0.14, -0.11) -0.12 (-0.13, -0.11)
  poverty_ratio -0.19 (-0.21, -0.16) -0.17 (-0.19, -0.16) -0.08 (-0.1, -0.07) -0.17 (-0.18, -0.15) -0.11 (-0.13, -0.1) -0.11 (-0.13, -0.1)
Black
  edu -0.11 (-0.17, -0.06) -0.04 (-0.06, -0.01) -0.05 (-0.08, -0.02) -0.08 (-0.11, -0.05) -0.08 (-0.11, -0.06) -0.06 (-0.08, -0.04)
  annual_income -0.12 (-0.18, -0.07) -0.1 (-0.12, -0.07) -0.1 (-0.13, -0.08) -0.11 (-0.14, -0.09) -0.1 (-0.12, -0.08) -0.08 (-0.1, -0.06)
  poverty_ratio -0.12 (-0.17, -0.06) -0.14 (-0.16, -0.11) -0.1 (-0.12, -0.07) -0.11 (-0.14, -0.09) -0.11 (-0.13, -0.09) -0.09 (-0.11, -0.07)
Other
  edu -0.1 (-0.13, -0.07) -0.02 (-0.03, 0) -0.04 (-0.06, -0.03) -0.05 (-0.07, -0.03) -0.08 (-0.1, -0.07) -0.08 (-0.1, -0.07)
  annual_income -0.09 (-0.13, -0.05) -0.03 (-0.05, -0.02) -0.03 (-0.05, -0.02) -0.09 (-0.1, -0.07) -0.08 (-0.1, -0.07) -0.08 (-0.1, -0.06)
  poverty_ratio -0.11 (-0.15, -0.08) -0.06 (-0.08, -0.05) -0.02 (-0.04, -0.01) -0.07 (-0.09, -0.05) -0.08 (-0.1, -0.07) -0.08 (-0.1, -0.06)
Stratified by Age
Age 20-40
  edu -0.14 (-0.18, -0.11) -0.08 (-0.09, -0.06) -0.02 (-0.04, -0.01) -0.06 (-0.08, -0.04) -0.06 (-0.07, -0.04) -0.07 (-0.09, -0.06)
  annual_income -0.09 (-0.12, -0.06) -0.06 (-0.08, -0.05) 0 (-0.02, 0.01) -0.05 (-0.07, -0.03) -0.03 (-0.05, -0.02) -0.05 (-0.06, -0.03)
  poverty_ratio -0.13 (-0.16, -0.1) -0.1 (-0.11, -0.08) -0.01 (-0.02, 0.01) -0.04 (-0.05, -0.02) -0.04 (-0.05, -0.03) -0.05 (-0.07, -0.04)
Age 40-60
  edu -0.2 (-0.24, -0.17) -0.09 (-0.1, -0.07) -0.08 (-0.1, -0.07) -0.09 (-0.11, -0.07) -0.12 (-0.14, -0.11) -0.13 (-0.14, -0.11)
  annual_income -0.19 (-0.23, -0.16) -0.15 (-0.17, -0.13) -0.09 (-0.11, -0.08) -0.16 (-0.18, -0.14) -0.14 (-0.16, -0.13) -0.15 (-0.17, -0.13)
  poverty_ratio -0.2 (-0.23, -0.16) -0.17 (-0.18, -0.15) -0.08 (-0.09, -0.06) -0.13 (-0.15, -0.11) -0.14 (-0.16, -0.12) -0.14 (-0.16, -0.13)
Age 60-80
  edu -0.24 (-0.28, -0.2) -0.07 (-0.09, -0.05) -0.09 (-0.11, -0.07) -0.09 (-0.11, -0.07) -0.14 (-0.16, -0.12) -0.12 (-0.14, -0.1)
  annual_income -0.24 (-0.29, -0.19) -0.1 (-0.12, -0.08) -0.11 (-0.14, -0.09) -0.13 (-0.15, -0.11) -0.16 (-0.18, -0.14) -0.14 (-0.16, -0.12)
  poverty_ratio -0.25 (-0.3, -0.21) -0.14 (-0.16, -0.12) -0.12 (-0.14, -0.09) -0.14 (-0.16, -0.11) -0.18 (-0.2, -0.16) -0.16 (-0.18, -0.14)
#pull sample sizes
table3$n
Table 3.1: Sample sizes for regression in Table 3. Coefficients are from linear regressions of biological aging measures on measures of socioeconomic circumstances.
KDM Biological Age Advancement Levine Phenotypic Age Advancement Modified-KDM Biological Age Advancement Modified-Levine Phenotypic Age Advancement Homeostatic Dysregulation Log Homeostatic Dysregulation
n
Full Sample
  edu 8234 37526 35910 35910 35910 35910
  annual_income 7553 34245 32818 32818 32818 32818
  poverty_ratio 7553 34245 32818 32818 32818 32818
Stratified by Gender
Men
  edu 4116 18072 17384 17384 17384 17384
  annual_income 3785 16563 15948 15948 15948 15948
  poverty_ratio 3785 16563 15948 15948 15948 15948
Women
  edu 4118 19454 18526 18526 18526 18526
  annual_income 3768 17682 16870 16870 16870 16870
  poverty_ratio 3768 17682 16870 16870 16870 16870
Stratified by Race
White
  edu 3937 17297 16682 16682 16682 16682
  annual_income 3728 16194 15642 15642 15642 15642
  poverty_ratio 3728 16194 15642 15642 15642 15642
Black
  edu 1468 7218 6820 6820 6820 6820
  annual_income 1336 6525 6167 6167 6167 6167
  poverty_ratio 1336 6525 6167 6167 6167 6167
Other
  edu 2829 13011 12408 12408 12408 12408
  annual_income 2489 11526 11009 11009 11009 11009
  poverty_ratio 2489 11526 11009 11009 11009 11009
Stratified by Age
Age 20-40
  edu 3014 12944 12350 12350 12350 12350
  annual_income 2791 11947 11426 11426 11426 11426
  poverty_ratio 2791 11947 11426 11426 11426 11426
Age 40-60
  edu 2961 11798 11323 11323 11323 11323
  annual_income 2714 10827 10402 10402 10402 10402
  poverty_ratio 2714 10827 10402 10402 10402 10402
Age 60-80
  edu 2259 11641 11193 11193 11193 11193
  annual_income 2048 10447 10049 10049 10049 10049
  poverty_ratio 2048 10447 10049 10049 10049 10049

###Step 3: Project biological aging measures onto new data In this example, the projection dataset is from the CALERIE randomized controlled trial (data are not included in the package). For this analysis, CALERIE data were previously cleaned and units of measure and variable names were harmonized to match the NHANES data included with the package. All algorithms were trained using the NHANES III data and projected into the CALERIE using the hd_calc, kdm_calc, and phenoage_calc functions of the BioAge package.

##Projecting HD into the CALERIE using NHANES III For HD, the constructed variable is based on a malhanobis distance statistic, which is theoretically the distance between observations and a hypothetically healthy, young cohort. In this example, I train separately for men and women who are between the ages of 20 and 30 and not pregnant, and have observe biomarker data within clinically acceptable distributions. For clinical guidelines, I relied upon the ranges reported by the Mayo Clinic website.

#The CALERIE dataset is loaded from my local drive that has previously been downloaded and cleaned
#projecting HD into the CALERIE using NHANES III (seperate training for gender)
# hd_fem = hd_calc(data = CALERIE %>%
#                       filter(gender == 2)%>%
#                       mutate(lncrp = log(crp)),
#                     reference = NHANES3_CLEAN %>%
#                       filter(gender == 2)%>%
#                       mutate(lncrp = log(crp)),
#                     biomarkers=c("albumin","alp","lncrp","totchol","lncreat","hba1c","sbp","bun","uap","lymph","mcv","wbc"))
# 
# hd_male = hd_calc(data = CALERIE %>%
#                        filter(gender == 1)%>%
#                        mutate(lncrp = log(crp)),
#                      reference = NHANES3_CLEAN %>%
#                        filter(gender == 1)%>%
#                        mutate(lncrp = log(crp)),
#                      biomarkers=c("albumin","alp","lncrp","totchol","lncreat","hba1c","sbp","bun","uap","lymph","mcv","wbc"))
# 
# #pull the HD dataset
# hd_data = rbind(hd_fem$data, hd_male$data)

###Projecting KDM bioage into the CALERIE using NHANES III Having estimated biological aging models using NHANES III in “Step 1”, I can project KDM bioage and phenoage into the CALERIE data by running kdm_calc and phenoage_calc and supplying a fit argument.

#projecting KDM bioage into the CALERIE using NHANES III (seperate training for gender)
# kdm_fem = kdm_calc(data = CALERIE %>%
#                         filter (gender ==2),
#                       biomarkers=c("albumin","alp","lncrp","totchol","lncreat","hba1c","sbp","bun","uap","lymph","mcv","wbc"),
#                    fit = kdm$fit$female,
#                    s_ba2 = kdm$fit$female$s_b2)
# 
# kdm_male = kdm_calc(data = CALERIE %>%
#                          filter (gender ==1),
#                        biomarkers=c("albumin","alp","lncrp","totchol","lncreat","hba1c","sbp","bun","uap","lymph","mcv","wbc"),
#                    fit = kdm$fit$male,
#                    s_ba2 = kdm$fit$male$s_b2)

#pull the KDM dataset
# kdm_data = rbind(kdm_fem$data, kdm_male$data)

###Projecting phenoage into the CALERIE using NHANES III

# phenoage_CALERIE = phenoage_calc(data = CALERIE,
#                             biomarkers = c("albumin_gL","alp","lncrp","totchol","lncreat_umol","hba1c","sbp","bun","uap","lymph","mcv","wbc"),
#                             fit = phenoage$fit)
# 
# phenoage_data = phenoage_CALERIE$data
# 
# #pull the full dataset
# newdata = left_join(CALERIE, hd_data[, c("sampleID", "hd", "hd_log")], by = "sampleID") %>%
#   left_join(., kdm_data[, c("sampleID", "kdm", "kdm_advance")], by = "sampleID") %>%
#   left_join(., phenoage_data[, c("sampleID","phenoage","phenoage_advance")], by = "sampleID") 

###Summary statistics of calculated biological aging measures for the CALERIE at pre-intervention baseline

# summary(newdata %>% filter(fu==0) %>% select(kdm, phenoage, hd, hd_log)) 
#>       kdm           phenoage           hd             hd_log     
#>  Min.   :22.37   Min.   :11.97   Min.   :0.8641   Min.   :2.097  
#>  1st Qu.:31.79   1st Qu.:27.41   1st Qu.:2.2555   1st Qu.:4.695  
#>  Median :38.70   Median :32.99   Median :2.7147   Median :5.229  
#>  Mean   :37.43   Mean   :32.64   Mean   :2.9256   Mean   :5.324  
#>  3rd Qu.:42.84   3rd Qu.:38.14   3rd Qu.:3.4509   3rd Qu.:6.023  
#>  Max.   :50.60   Max.   :50.58   Max.   :7.9852   Max.   :8.797  
#>  NA's   :13      NA's   :13      NA's   :13       NA's   :13

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.