1. Import data set

library(haven)
df <- read_sas("/Users/thien/Desktop/R-dir/Depressive Disorder project/nhanes.sas7bdat")

2. Dependent variables

library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.0      ✔ purrr   0.3.4 
## ✔ tibble  3.1.8      ✔ dplyr   1.0.10
## ✔ tidyr   1.2.1      ✔ stringr 1.5.0 
## ✔ readr   2.1.4      ✔ forcats 1.0.0 
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
# Filter the dataframe
df21 <- df %>%
  filter(DPQ010 != 7 & DPQ010 != 9 & !is.na(DPQ010))

df22 <- df21 %>%
  filter(DPQ020 != 7 & DPQ020 != 9 & !is.na(DPQ020))

df23 <- df22 %>%
  filter(DPQ030 != 7 & DPQ030 != 9 & !is.na(DPQ030))

df24 <- df23 %>%
  filter(DPQ040 != 7 & DPQ040 != 9 & !is.na(DPQ040))

df25 <- df24 %>%
  filter(DPQ050 != 7 & DPQ050 != 9 & !is.na(DPQ050))

df26 <- df25 %>%
  filter(DPQ060 != 7 & DPQ060 != 9 & !is.na(DPQ060))

df27 <- df26 %>%
  filter(DPQ070 != 7 & DPQ070 != 9 & !is.na(DPQ070))

df28 <- df27 %>%
  filter(DPQ080 != 7 & DPQ080 != 9 & !is.na(DPQ080))

df29 <- df28 %>%
  filter(DPQ090 != 7 & DPQ090 != 9 & !is.na(DPQ090))


# Create depression variable: 
depress <- df29
depress$dp = depress$DPQ010 + depress$DPQ020 + depress$DPQ030 + depress$DPQ040 + depress$DPQ050 + depress$DPQ060 + depress$DPQ070 + depress$DPQ080 + depress$DPQ090

# Create the new variable 'dp10'
depress <- depress %>%
  mutate(dp10 = ifelse(dp <= 9, 0, 1))

3. Some potential covariates

# 3.1 Create SBP and DBP
depress$SBP = (depress$BPXSY1 + depress$BPXSY2) / 2
depress$DBP =(depress$BPXDI1 + depress$BPXDI2) / 2

# 3.2 Create the variable ‘hyper’
hypertension <- depress %>%
   mutate(hyper = case_when(
      SBP >= 140 | DBP >= 90 | BPQ040A == 1 | BPQ050A == 1 ~ 1,
      TRUE ~ 0))

# 3.3 Create the variable ‘dyslip’ using case_when
lipid <- hypertension %>%
   mutate(dyslip = case_when(
      LBXTC >= 200 | LBXTR >= 150 | LBDLDL >= 100 | LBDHDD <= 40 | BPQ090D == 1 ~ 1,
      TRUE ~ 0
   ))

# 3.4 Create the ‘db’ variable using case_when
diab <- lipid %>%
   mutate(db = case_when(
      LBXGLU >= 126 | LBXGLT >= 200 | LBXGH >= 6.5 | DIQ070 == 1 ~ 1,
      TRUE ~ 0
   ))

4. Select variables (with nutrition variables) for analysis from original one

df3 <- subset(diab, select = c(      RIDAGEYR, RIAGENDR, RIDRETH3, DMDEDUC2, DMDMARTL, 
                                     SBP, DBP, BMXBMI, INDFMIN2, INDFMPIR, LBXSBU, LBXSCR, 
                                               LBXSASSI, LBXSATSI, LBXAPB, LBDHDD, 
                                               LBDLDL, LBXTR, LBXTC, LBXGLU, LBXGLT, 
                                               ALQ101, SMQ020, PAQ665, PAQ650, 
                                               LBXCOT, LBXHCT, URXCOTT, URXHCTT, 
                                               DBD100, DR1TKCAL, DR1TPROT, 
                                               DR1TCARB, DR1TSUGR, DR1TFIBE, 
                                               DR1TTFAT, DR1TSFAT, DR1TMFAT, 
                                               DR1TPFAT, DR1TCHOL, DR1TATOC, 
                                               DR1TATOA, DR1TRET, DR1TVARA, 
                                               DR1TACAR, DR1TBCAR, DR1TCRYP, 
                                               DR1TLYCO, DR1TLZ, DR1TVB1, DR1TVB2, 
                                               DR1TNIAC, DR1TVB6, DR1TFOLA, DR1TFA, 
                                               DR1TFF, DR1TFDFE, DR1TCHL, DR1TVB12, 
                                               DR1TB12A, DR1TVC, DR1TVD, DR1TVK, 
                                               DR1TCALC, DR1TPHOS, DR1TMAGN, DR1TIRON, 
                                               DR1TZINC, DR1TCOPP, DR1TSODI, DR1TPOTA, 
                                               DR1TSELE, DR1TCAFF, DR1TTHEO, DR1TALCO, 
                                               DR1TMOIS, DR1TS040, DR1TS060, DR1TS080, 
                                               DR1TS100, DR1TS120, DR1TS140, DR1TS160, 
                                               DR1TS180, DR1TM161, DR1TM181, DR1TM201, 
                                               DR1TM221, DR1TP182, DR1TP183, DR1TP184, 
                                               DR1TP204, DR1TP205, DR1TP225, DR1TP226, hyper, db, dyslip, dp10))

4. Rename variables

# Rename all variables in one code
df4 <- df3 %>% rename(age = RIDAGEYR, sex = RIAGENDR, ethnic = RIDRETH3, 
                      educ = DMDEDUC2, masts = DMDMARTL, BMI = BMXBMI, 
                      finc = INDFMIN2, PIR = INDFMPIR, 
                      BUN = LBXSBU, crea = LBXSCR, AST = LBXSASSI, ALT = LBXSATSI,
                      apoB = LBXAPB, HDL = LBDHDD, LDL = LBDLDL, 
                      TG = LBXTR, TC = LBXTC, Glu = LBXGLU, tolGlu = LBXGLT,
                      sCOT = LBXCOT, sHCOT = LBXHCT, uCOT = URXCOTT, uHCOT = URXHCTT)
# Filter out values ‘7, 77’ and ‘9, 99’ from categorical variables column
## Those values are unknown and confused values
df5 <- df4 %>%
  filter(educ %in% c('1', '2', '3', '4', '5'),
         masts %in% c('1', '2', '3', '4', '5', '6'),
         ALQ101 %in% c('1', '2'),
         SMQ020 %in% c('1', '2')
         )
# Change to factor
df_new = df5

df_new$dp10 = as.factor(df_new$dp10)
df_new$sex = as.factor(df_new$sex)
df_new$ethnic = as.factor(df_new$ethnic)
df_new$educ = as.factor(df_new$educ)
df_new$masts = as.factor(df_new$masts)
df_new$DBD100 = as.factor(df_new$DBD100)

df_new$ALQ101 = as.factor(df_new$ALQ101)
df_new$SMQ020 = as.factor(df_new$SMQ020)
df_new$PAQ650 = as.factor(df_new$PAQ650)
df_new$PAQ665 = as.factor(df_new$PAQ665)

df_new$hyper = as.factor(df_new$hyper)
df_new$db = as.factor(df_new$db)
df_new$dyslip = as.factor(df_new$dyslip)

5. Descriptive analysis

5.1 Table 1

library(table1)
## 
## Attaching package: 'table1'
## The following objects are masked from 'package:base':
## 
##     units, units<-
table1(~  .| dp10, data = df_new)
0
(N=4553)
1
(N=487)
Overall
(N=5040)
Age in years at screening
Mean (SD) 48.9 (17.6) 51.6 (16.4) 49.2 (17.5)
Median [Min, Max] 48.0 [20.0, 80.0] 54.0 [20.0, 80.0] 49.0 [20.0, 80.0]
sex
1 2275 (50.0%) 158 (32.4%) 2433 (48.3%)
2 2278 (50.0%) 329 (67.6%) 2607 (51.7%)
ethnic
1 607 (13.3%) 67 (13.8%) 674 (13.4%)
2 392 (8.6%) 57 (11.7%) 449 (8.9%)
3 2006 (44.1%) 216 (44.4%) 2222 (44.1%)
4 905 (19.9%) 105 (21.6%) 1010 (20.0%)
6 509 (11.2%) 17 (3.5%) 526 (10.4%)
7 134 (2.9%) 25 (5.1%) 159 (3.2%)
educ
1 292 (6.4%) 64 (13.1%) 356 (7.1%)
2 575 (12.6%) 103 (21.1%) 678 (13.5%)
3 1009 (22.2%) 117 (24.0%) 1126 (22.3%)
4 1442 (31.7%) 148 (30.4%) 1590 (31.5%)
5 1235 (27.1%) 55 (11.3%) 1290 (25.6%)
masts
1 2443 (53.7%) 187 (38.4%) 2630 (52.2%)
2 309 (6.8%) 57 (11.7%) 366 (7.3%)
3 484 (10.6%) 98 (20.1%) 582 (11.5%)
4 123 (2.7%) 27 (5.5%) 150 (3.0%)
5 872 (19.2%) 82 (16.8%) 954 (18.9%)
6 322 (7.1%) 36 (7.4%) 358 (7.1%)
Systolic: Blood pres (1st rdg) mm Hg
Mean (SD) 123 (17.2) 125 (19.1) 123 (17.4)
Median [Min, Max] 120 [70.0, 229] 122 [66.0, 216] 120 [66.0, 229]
Missing 412 (9.0%) 55 (11.3%) 467 (9.3%)
Diastolic: Blood pres (1st rdg) mm Hg
Mean (SD) 69.4 (12.5) 69.7 (12.4) 69.4 (12.5)
Median [Min, Max] 70.0 [0, 119] 71.0 [0, 104] 70.0 [0, 119]
Missing 412 (9.0%) 55 (11.3%) 467 (9.3%)
Body Mass Index (kg/m**2)
Mean (SD) 28.9 (6.87) 31.9 (9.32) 29.2 (7.19)
Median [Min, Max] 27.7 [14.1, 70.1] 30.8 [15.2, 82.9] 27.9 [14.1, 82.9]
Missing 41 (0.9%) 5 (1.0%) 46 (0.9%)
Annual family income
Mean (SD) 10.8 (13.4) 8.97 (15.0) 10.6 (13.6)
Median [Min, Max] 8.00 [1.00, 99.0] 6.00 [1.00, 99.0] 8.00 [1.00, 99.0]
Missing 41 (0.9%) 8 (1.6%) 49 (1.0%)
Ratio of family income to poverty
Mean (SD) 2.62 (1.66) 1.74 (1.33) 2.53 (1.65)
Median [Min, Max] 2.26 [0, 5.00] 1.27 [0, 5.00] 2.15 [0, 5.00]
Missing 322 (7.1%) 42 (8.6%) 364 (7.2%)
Blood urea nitrogen (mg/dL)
Mean (SD) 13.4 (5.73) 13.6 (9.17) 13.4 (6.15)
Median [Min, Max] 12.0 [1.00, 73.0] 12.0 [2.00, 95.0] 12.0 [1.00, 95.0]
Missing 170 (3.7%) 20 (4.1%) 190 (3.8%)
Creatinine (mg/dL)
Mean (SD) 0.912 (0.441) 0.995 (1.09) 0.920 (0.539)
Median [Min, Max] 0.860 [0.300, 16.6] 0.820 [0.360, 17.4] 0.860 [0.300, 17.4]
Missing 170 (3.7%) 20 (4.1%) 190 (3.8%)
Aspartate aminotransferase AST (U/L)
Mean (SD) 25.3 (18.6) 26.6 (21.7) 25.4 (18.9)
Median [Min, Max] 22.0 [9.00, 882] 22.0 [11.0, 294] 22.0 [9.00, 882]
Missing 172 (3.8%) 20 (4.1%) 192 (3.8%)
Alanine aminotransferase ALT (U/L)
Mean (SD) 25.0 (18.9) 25.7 (21.5) 25.1 (19.1)
Median [Min, Max] 20.0 [6.00, 536] 20.0 [7.00, 300] 20.0 [6.00, 536]
Missing 172 (3.8%) 20 (4.1%) 192 (3.8%)
Apolipoprotein (B) (mg/dL)
Mean (SD) 89.8 (24.6) 95.3 (26.5) 90.3 (24.8)
Median [Min, Max] 88.0 [24.0, 228] 94.0 [20.0, 234] 89.0 [20.0, 234]
Missing 2447 (53.7%) 273 (56.1%) 2720 (54.0%)
Direct HDL-Cholesterol (mg/dL)
Mean (SD) 52.9 (16.2) 51.2 (15.5) 52.8 (16.1)
Median [Min, Max] 50.0 [10.0, 173] 48.0 [22.0, 117] 50.0 [10.0, 173]
Missing 159 (3.5%) 17 (3.5%) 176 (3.5%)
LDL-cholesterol (mg/dL)
Mean (SD) 111 (34.6) 113 (37.1) 111 (34.9)
Median [Min, Max] 108 [14.0, 375] 112 [24.0, 288] 108 [14.0, 375]
Missing 2480 (54.5%) 276 (56.7%) 2756 (54.7%)
Triglyceride (mg/dL)
Mean (SD) 120 (130) 142 (98.7) 122 (128)
Median [Min, Max] 94.0 [14.0, 4230] 121 [21.0, 1000] 96.0 [14.0, 4230]
Missing 2446 (53.7%) 273 (56.1%) 2719 (53.9%)
Total Cholesterol( mg/dL)
Mean (SD) 189 (41.9) 192 (41.3) 189 (41.9)
Median [Min, Max] 185 [82.0, 813] 189 [85.0, 380] 186 [82.0, 813]
Missing 159 (3.5%) 17 (3.5%) 176 (3.5%)
Fasting Glucose (mg/dL)
Mean (SD) 107 (32.6) 117 (43.8) 107 (33.9)
Median [Min, Max] 99.0 [51.0, 405] 102 [67.0, 375] 99.0 [51.0, 405]
Missing 2436 (53.5%) 269 (55.2%) 2705 (53.7%)
Two Hour Glucose(OGTT) (mg/dL)
Mean (SD) 118 (50.1) 129 (52.3) 119 (50.3)
Median [Min, Max] 107 [40.0, 604] 121 [48.0, 352] 108 [40.0, 604]
Missing 2900 (63.7%) 336 (69.0%) 3236 (64.2%)
ALQ101
1 3293 (72.3%) 350 (71.9%) 3643 (72.3%)
2 1260 (27.7%) 137 (28.1%) 1397 (27.7%)
SMQ020
1 1924 (42.3%) 280 (57.5%) 2204 (43.7%)
2 2629 (57.7%) 207 (42.5%) 2836 (56.3%)
PAQ665
1 2009 (44.1%) 123 (25.3%) 2132 (42.3%)
2 2544 (55.9%) 364 (74.7%) 2908 (57.7%)
PAQ650
1 1090 (23.9%) 48 (9.9%) 1138 (22.6%)
2 3463 (76.1%) 439 (90.1%) 3902 (77.4%)
Cotinine, Serum (ng/mL)
Mean (SD) 56.7 (131) 104 (163) 61.3 (135)
Median [Min, Max] 0.0330 [0.0110, 1820] 0.233 [0.0110, 1030] 0.0360 [0.0110, 1820]
Missing 157 (3.4%) 18 (3.7%) 175 (3.5%)
Hematocrit (%)
Mean (SD) 22.6 (60.9) 45.4 (78.0) 24.8 (63.1)
Median [Min, Max] 0.0110 [0.0110, 1150] 0.0840 [0.0110, 540] 0.0110 [0.0110, 1150]
Missing 157 (3.4%) 18 (3.7%) 175 (3.5%)
Total Cotinine, urine (ng/mL)
Mean (SD) 686 (1830) 1570 (3240) 759 (2000)
Median [Min, Max] 0.411 [0.0210, 26800] 13.8 [0.0210, 24200] 0.451 [0.0210, 26800]
Missing 3076 (67.6%) 354 (72.7%) 3430 (68.1%)
Total Hydroxycotinine, urine (ng/mL)
Mean (SD) 1350 (4210) 3140 (6200) 1500 (4430)
Median [Min, Max] 0.739 [0.0210, 70600] 20.1 [0.0210, 40400] 0.829 [0.0210, 70600]
Missing 3076 (67.6%) 354 (72.7%) 3430 (68.1%)
DBD100
1 1442 (31.7%) 128 (26.3%) 1570 (31.2%)
2 944 (20.7%) 86 (17.7%) 1030 (20.4%)
3 637 (14.0%) 96 (19.7%) 733 (14.5%)
9 5 (0.1%) 0 (0%) 5 (0.1%)
Missing 1525 (33.5%) 177 (36.3%) 1702 (33.8%)
Energy (kcal)
Mean (SD) 2130 (1030) 2000 (1050) 2120 (1030)
Median [Min, Max] 1950 [193, 12100] 1790 [117, 7420] 1940 [117, 12100]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Protein (gm)
Mean (SD) 84.0 (46.2) 69.5 (42.8) 82.6 (46.1)
Median [Min, Max] 75.4 [0.850, 558] 60.9 [0, 396] 74.1 [0, 558]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Carbohydrate (gm)
Mean (SD) 253 (129) 253 (142) 253 (130)
Median [Min, Max] 230 [8.67, 1420] 224 [11.5, 844] 229 [8.67, 1420]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Total sugars (gm)
Mean (SD) 109 (78.0) 123 (98.2) 111 (80.2)
Median [Min, Max] 92.8 [0.130, 1120] 97.8 [0.610, 836] 93.1 [0.130, 1120]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Dietary fiber (gm)
Mean (SD) 17.3 (10.9) 14.6 (10.0) 17.0 (10.9)
Median [Min, Max] 14.9 [0, 136] 12.3 [0, 66.2] 14.6 [0, 136]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Total fat (gm)
Mean (SD) 82.3 (48.5) 74.1 (46.6) 81.5 (48.4)
Median [Min, Max] 73.5 [0.330, 548] 66.5 [0, 344] 72.8 [0, 548]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Total saturated fatty acids (gm)
Mean (SD) 26.2 (16.7) 24.4 (16.7) 26.0 (16.7)
Median [Min, Max] 23.0 [0.0910, 177] 20.5 [0, 94.2] 22.7 [0, 177]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Total monounsaturated fatty acids (gm)
Mean (SD) 28.9 (18.1) 25.2 (16.8) 28.5 (18.0)
Median [Min, Max] 25.4 [0.0430, 222] 22.1 [0, 131] 25.0 [0, 222]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Total polyunsaturated fatty acids (gm)
Mean (SD) 19.4 (13.6) 17.4 (12.7) 19.2 (13.6)
Median [Min, Max] 16.3 [0.0440, 182] 14.7 [0, 123] 16.2 [0, 182]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Cholesterol (mg)
Mean (SD) 305 (251) 248 (219) 300 (249)
Median [Min, Max] 233 [0, 2580] 185 [0, 1590] 229 [0, 2580]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Vitamin E as alpha-tocopherol (mg)
Mean (SD) 9.19 (7.88) 7.76 (6.44) 9.05 (7.76)
Median [Min, Max] 7.34 [0.0100, 158] 6.01 [0, 55.8] 7.19 [0, 158]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Added alpha-tocopherol (Vitamin E) (mg)
Mean (SD) 0.819 (3.82) 0.638 (2.73) 0.802 (3.73)
Median [Min, Max] 0 [0, 99.9] 0 [0, 20.7] 0 [0, 99.9]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Retinol (mcg)
Mean (SD) 410 (414) 353 (351) 404 (409)
Median [Min, Max] 308 [0, 7340] 253 [0, 3070] 305 [0, 7340]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Vitamin A, RAE (mcg)
Mean (SD) 624 (618) 486 (427) 612 (604)
Median [Min, Max] 474 [0, 8550] 382 [0, 3090] 465 [0, 8550]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Alpha-carotene (mcg)
Mean (SD) 401 (1240) 284 (758) 390 (1200)
Median [Min, Max] 45.0 [0, 35100] 30.0 [0, 6840] 43.0 [0, 35100]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Beta-carotene (mcg)
Mean (SD) 2340 (4840) 1430 (2500) 2250 (4680)
Median [Min, Max] 777 [0, 78800] 495 [0, 19700] 738 [0, 78800]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Beta-cryptoxanthin (mcg)
Mean (SD) 95.6 (433) 61.9 (127) 92.4 (414)
Median [Min, Max] 29.0 [0, 24300] 20.0 [0, 1700] 28.0 [0, 24300]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Lycopene (mcg)
Mean (SD) 5030 (8770) 4070 (7250) 4940 (8640)
Median [Min, Max] 1590 [0, 87900] 1160 [0, 50800] 1550 [0, 87900]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Lutein + zeaxanthin (mcg)
Mean (SD) 1660 (3770) 1080 (2090) 1610 (3650)
Median [Min, Max] 747 [0, 103000] 542 [0, 19800] 719 [0, 103000]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Thiamin (Vitamin B1) (mg)
Mean (SD) 1.61 (0.920) 1.38 (0.790) 1.59 (0.911)
Median [Min, Max] 1.43 [0.0220, 8.56] 1.23 [0.0990, 4.26] 1.41 [0.0220, 8.56]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Riboflavin (Vitamin B2) (mg)
Mean (SD) 2.09 (1.31) 1.87 (1.32) 2.07 (1.31)
Median [Min, Max] 1.84 [0.0240, 17.6] 1.60 [0, 16.3] 1.82 [0, 17.6]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Niacin (mg)
Mean (SD) 26.4 (16.9) 22.2 (16.1) 26.0 (16.9)
Median [Min, Max] 22.7 [0.215, 260] 19.2 [1.90, 168] 22.3 [0.215, 260]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Vitamin B6 (mg)
Mean (SD) 2.17 (1.74) 1.84 (2.16) 2.14 (1.79)
Median [Min, Max] 1.81 [0.0230, 48.3] 1.47 [0.0160, 34.9] 1.78 [0.0160, 48.3]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Total folate (mcg)
Mean (SD) 402 (259) 337 (209) 396 (256)
Median [Min, Max] 349 [0, 3170] 301 [0, 1330] 344 [0, 3170]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Folic acid (mcg)
Mean (SD) 174 (182) 152 (146) 172 (179)
Median [Min, Max] 128 [0, 2830] 108 [0, 1300] 126 [0, 2830]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Food folate (mcg)
Mean (SD) 228 (157) 186 (128) 224 (155)
Median [Min, Max] 192 [0, 2360] 158 [0, 1010] 189 [0, 2360]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Folate, DFE (mcg)
Mean (SD) 524 (369) 443 (297) 516 (364)
Median [Min, Max] 439 [0, 5150] 383 [0, 2240] 436 [0, 5150]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Total choline (mg)
Mean (SD) 346 (215) 282 (191) 340 (213)
Median [Min, Max] 299 [7.90, 2910] 244 [0, 1590] 293 [0, 2910]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Vitamin B12 (mcg)
Mean (SD) 4.94 (5.12) 4.16 (5.19) 4.86 (5.13)
Median [Min, Max] 3.64 [0, 78.8] 3.02 [0, 68.0] 3.59 [0, 78.8]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Added vitamin B12 (mcg)
Mean (SD) 1.01 (2.84) 0.871 (2.87) 1.00 (2.85)
Median [Min, Max] 0 [0, 44.9] 0 [0, 37.4] 0 [0, 44.9]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Vitamin C (mg)
Mean (SD) 82.6 (93.8) 64.9 (76.4) 81.0 (92.5)
Median [Min, Max] 53.4 [0, 2010] 36.1 [0, 553] 51.5 [0, 2010]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Vitamin D (D2 + D3) (mcg)
Mean (SD) 4.71 (6.02) 3.53 (3.69) 4.60 (5.85)
Median [Min, Max] 3.00 [0, 68.8] 2.55 [0, 26.6] 3.00 [0, 68.8]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Vitamin K (mcg)
Mean (SD) 122 (180) 89.7 (112) 119 (175)
Median [Min, Max] 73.1 [0, 4080] 59.9 [0, 941] 71.7 [0, 4080]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Calcium (mg)
Mean (SD) 938 (602) 838 (552) 928 (599)
Median [Min, Max] 817 [18.0, 7340] 704 [6.00, 3460] 808 [6.00, 7340]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Phosphorus (mg)
Mean (SD) 1390 (728) 1190 (671) 1370 (725)
Median [Min, Max] 1260 [56.0, 11500] 1110 [0, 4570] 1240 [0, 11500]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Magnesium (mg)
Mean (SD) 304 (163) 262 (143) 300 (161)
Median [Min, Max] 273 [20.0, 2730] 231 [0, 929] 269 [0, 2730]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Iron (mg)
Mean (SD) 14.5 (8.59) 12.8 (8.21) 14.3 (8.57)
Median [Min, Max] 12.5 [0.220, 99.7] 10.4 [0.130, 49.1] 12.4 [0.130, 99.7]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Zinc (mg)
Mean (SD) 11.1 (6.93) 9.42 (6.42) 11.0 (6.90)
Median [Min, Max] 9.68 [0.160, 73.9] 7.82 [0.280, 75.2] 9.53 [0.160, 75.2]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Copper (mg)
Mean (SD) 1.24 (0.785) 1.06 (0.649) 1.22 (0.775)
Median [Min, Max] 1.09 [0.0220, 14.2] 0.892 [0.0280, 6.74] 1.07 [0.0220, 14.2]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Sodium (mg)
Mean (SD) 3540 (1850) 3050 (1790) 3490 (1850)
Median [Min, Max] 3210 [45.0, 21400] 2710 [29.0, 13200] 3160 [29.0, 21400]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Potassium (mg)
Mean (SD) 2650 (1300) 2250 (1160) 2610 (1290)
Median [Min, Max] 2440 [110, 15900] 2090 [200, 7990] 2420 [110, 15900]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Selenium (mcg)
Mean (SD) 119 (71.7) 99.3 (64.3) 117 (71.2)
Median [Min, Max] 105 [0.700, 987] 84.8 [0, 551] 103 [0, 987]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Caffeine (mg)
Mean (SD) 142 (177) 176 (244) 146 (185)
Median [Min, Max] 95.0 [0, 2450] 102 [0, 2020] 96.0 [0, 2450]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Theobromine (mg)
Mean (SD) 35.7 (79.0) 45.5 (146) 36.6 (87.5)
Median [Min, Max] 0 [0, 1150] 0 [0, 2040] 0 [0, 2040]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Alcohol (gm)
Mean (SD) 10.4 (29.0) 9.22 (26.8) 10.3 (28.8)
Median [Min, Max] 0 [0, 591] 0 [0, 225] 0 [0, 591]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
Moisture (gm)
Mean (SD) 2890 (1510) 2860 (1580) 2890 (1520)
Median [Min, Max] 2590 [339, 17400] 2560 [379, 13900] 2590 [339, 17400]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
SFA 4:0 (Butanoic) (gm)
Mean (SD) 0.472 (0.485) 0.467 (0.508) 0.472 (0.487)
Median [Min, Max] 0.332 [0, 5.38] 0.309 [0, 3.09] 0.328 [0, 5.38]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
SFA 6:0 (Hexanoic) (gm)
Mean (SD) 0.297 (0.306) 0.289 (0.312) 0.296 (0.307)
Median [Min, Max] 0.213 [0, 3.01] 0.177 [0, 1.65] 0.210 [0, 3.01]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
SFA 8:0 (Octanoic) (gm)
Mean (SD) 0.252 (0.275) 0.244 (0.243) 0.251 (0.272)
Median [Min, Max] 0.182 [0, 4.31] 0.159 [0, 1.12] 0.180 [0, 4.31]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
SFA 10:0 (Decanoic) (gm)
Mean (SD) 0.486 (0.453) 0.468 (0.454) 0.485 (0.453)
Median [Min, Max] 0.367 [0, 3.90] 0.308 [0, 2.55] 0.363 [0, 3.90]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
SFA 12:0 (Dodecanoic) (gm)
Mean (SD) 0.824 (1.33) 0.803 (0.990) 0.822 (1.30)
Median [Min, Max] 0.487 [0, 26.4] 0.444 [0, 6.15] 0.484 [0, 26.4]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
SFA 14:0 (Tetradecanoic) (gm)
Mean (SD) 2.14 (1.85) 2.06 (1.91) 2.13 (1.85)
Median [Min, Max] 1.68 [0.00200, 18.8] 1.52 [0, 11.7] 1.66 [0, 18.8]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
SFA 16:0 (Hexadecanoic) (gm)
Mean (SD) 14.3 (8.86) 13.2 (8.78) 14.2 (8.86)
Median [Min, Max] 12.6 [0.0570, 91.7] 11.0 [0, 49.3] 12.5 [0, 91.7]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
SFA 18:0 (Octadecanoic) (gm)
Mean (SD) 6.36 (4.13) 5.94 (4.11) 6.32 (4.13)
Median [Min, Max] 5.56 [0.0160, 40.3] 4.99 [0, 22.8] 5.51 [0, 40.3]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
MFA 16:1 (Hexadecenoic) (gm)
Mean (SD) 1.08 (0.827) 0.925 (0.739) 1.07 (0.821)
Median [Min, Max] 0.915 [0, 13.9] 0.756 [0, 6.62] 0.896 [0, 13.9]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
MFA 18:1 (Octadecenoic) (gm)
Mean (SD) 26.1 (16.8) 22.8 (15.5) 25.8 (16.7)
Median [Min, Max] 22.9 [0.0330, 205] 19.9 [0, 126] 22.6 [0, 205]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
MFA 20:1 (Eicosenoic) (gm)
Mean (SD) 0.331 (0.329) 0.280 (0.266) 0.327 (0.324)
Median [Min, Max] 0.246 [0, 5.76] 0.214 [0, 2.49] 0.243 [0, 5.76]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
MFA 22:1 (Docosenoic) (gm)
Mean (SD) 0.0315 (0.112) 0.0210 (0.0414) 0.0305 (0.108)
Median [Min, Max] 0.00900 [0, 3.62] 0.00800 [0, 0.347] 0.00900 [0, 3.62]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
PFA 18:2 (Octadecadienoic) (gm)
Mean (SD) 17.1 (12.2) 15.3 (11.4) 17.0 (12.1)
Median [Min, Max] 14.4 [0.0390, 170] 12.8 [0, 111] 14.3 [0, 170]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
PFA 18:3 (Octadecatrienoic) (gm)
Mean (SD) 1.81 (1.42) 1.64 (1.40) 1.80 (1.42)
Median [Min, Max] 1.46 [0.00200, 16.6] 1.27 [0, 12.1] 1.45 [0, 16.6]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
PFA 18:4 (Octadecatetraenoic) (gm)
Mean (SD) 0.0110 (0.0376) 0.00706 (0.0225) 0.0106 (0.0365)
Median [Min, Max] 0.00100 [0, 0.635] 0.00100 [0, 0.190] 0.00100 [0, 0.635]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
PFA 20:4 (Eicosatetraenoic) (gm)
Mean (SD) 0.166 (0.144) 0.134 (0.122) 0.163 (0.143)
Median [Min, Max] 0.125 [0, 1.22] 0.101 [0, 0.868] 0.122 [0, 1.22]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
PFA 20:5 (Eicosapentaenoic) (gm)
Mean (SD) 0.0358 (0.117) 0.0199 (0.0690) 0.0343 (0.114)
Median [Min, Max] 0.00800 [0, 2.69] 0.00600 [0, 1.22] 0.00800 [0, 2.69]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
PFA 22:5 (Docosapentaenoic) (gm)
Mean (SD) 0.0262 (0.0422) 0.0188 (0.0219) 0.0255 (0.0408)
Median [Min, Max] 0.0160 [0, 1.07] 0.0130 [0, 0.181] 0.0160 [0, 1.07]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
PFA 22:6 (Docosahexaenoic) (gm)
Mean (SD) 0.0756 (0.211) 0.0450 (0.114) 0.0727 (0.204)
Median [Min, Max] 0.0130 [0, 4.34] 0.00800 [0, 1.62] 0.0130 [0, 4.34]
Missing 233 (5.1%) 39 (8.0%) 272 (5.4%)
hyper
0 2915 (64.0%) 225 (46.2%) 3140 (62.3%)
1 1638 (36.0%) 262 (53.8%) 1900 (37.7%)
db
0 3849 (84.5%) 364 (74.7%) 4213 (83.6%)
1 704 (15.5%) 123 (25.3%) 827 (16.4%)
dyslip
0 1354 (29.7%) 118 (24.2%) 1472 (29.2%)
1 3199 (70.3%) 369 (75.8%) 3568 (70.8%)

5.2 Exploratory data analysis

# About the DD variable
ggplot(data = df_new, mapping = aes(dp10, fill = dp10)) + geom_bar(width = 0.5) +
  xlab("Depressive Disorder") +
  scale_x_discrete(labels = c ("No", "Yes")) +
  ylab("Count") +
   
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "none") +
  geom_text(stat='count', aes(label=..count..), vjust=-0.5) +
  geom_text(stat='count', aes(label=paste0(round(after_stat(count/sum(count)*100),1),'%')), vjust=2, color = "black") 
## Warning: The dot-dot notation (`..count..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(count)` instead.

5.3 CompareGroup

library(compareGroups)
med_iqr <- compareGroups(dp10 ~ . , data = df_new, method = c(age = 2, finc = 2, PIR = 2, crea = 2, AST = 2, ALT = 2, TG = 2, Glu = 2))
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
createTable(med_iqr)
## 
## --------Summary descriptives table by 'dp10'---------
## 
## ___________________________________________________________________________________ 
##                                                0                1         p.overall 
##                                              N=4553           N=487                 
## ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ 
## Age in years at screening               48.0 [34.0;63.0] 54.0 [38.0;63.0]   0.001   
## sex:                                                                       <0.001   
##     1                                     2275 (50.0%)     158 (32.4%)              
##     2                                     2278 (50.0%)     329 (67.6%)              
## ethnic:                                                                    <0.001   
##     1                                     607 (13.3%)       67 (13.8%)              
##     2                                     392 (8.61%)       57 (11.7%)              
##     3                                     2006 (44.1%)     216 (44.4%)              
##     4                                     905 (19.9%)      105 (21.6%)              
##     6                                     509 (11.2%)       17 (3.49%)              
##     7                                     134 (2.94%)       25 (5.13%)              
## educ:                                                                      <0.001   
##     1                                     292 (6.41%)       64 (13.1%)              
##     2                                     575 (12.6%)      103 (21.1%)              
##     3                                     1009 (22.2%)     117 (24.0%)              
##     4                                     1442 (31.7%)     148 (30.4%)              
##     5                                     1235 (27.1%)      55 (11.3%)              
## masts:                                                                     <0.001   
##     1                                     2443 (53.7%)     187 (38.4%)              
##     2                                     309 (6.79%)       57 (11.7%)              
##     3                                     484 (10.6%)       98 (20.1%)              
##     4                                     123 (2.70%)       27 (5.54%)              
##     5                                     872 (19.2%)       82 (16.8%)              
##     6                                     322 (7.07%)       36 (7.39%)              
## Systolic: Blood pres (1st rdg) mm Hg       123 (17.2)       125 (19.1)      0.003   
## Diastolic: Blood pres (1st rdg) mm Hg     69.4 (12.5)      69.7 (12.4)      0.656   
## Body Mass Index (kg/m**2)                 28.9 (6.87)      31.9 (9.32)     <0.001   
## Annual family income                    8.00 [5.00;14.0] 6.00 [3.00;8.00]  <0.001   
## Ratio of family income to poverty       2.26 [1.13;4.28] 1.27 [0.78;2.35]  <0.001   
## Blood urea nitrogen (mg/dL)               13.4 (5.73)      13.6 (9.17)      0.597   
## Creatinine (mg/dL)                      0.86 [0.72;1.02] 0.82 [0.71;1.01]   0.052   
## Aspartate aminotransferase AST (U/L)    22.0 [19.0;27.0] 22.0 [18.5;28.0]   0.467   
## Alanine aminotransferase ALT (U/L)      20.0 [16.0;28.0] 20.0 [15.0;28.0]   0.369   
## Apolipoprotein (B) (mg/dL)                89.8 (24.6)      95.3 (26.5)      0.004   
## Direct HDL-Cholesterol (mg/dL)            52.9 (16.2)      51.2 (15.5)      0.019   
## LDL-cholesterol (mg/dL)                    111 (34.6)       113 (37.1)      0.359   
## Triglyceride (mg/dL)                    94.0 [64.0;139]   120 [80.0;183]   <0.001   
## Total Cholesterol( mg/dL)                  189 (41.9)       192 (41.3)      0.090   
## Fasting Glucose (mg/dL)                 99.0 [92.0;108]   102 [95.0;117]   <0.001   
## Two Hour Glucose(OGTT) (mg/dL)             118 (50.1)       129 (52.3)      0.016   
## ALQ101:                                                                     0.872   
##     1                                     3293 (72.3%)     350 (71.9%)              
##     2                                     1260 (27.7%)     137 (28.1%)              
## SMQ020:                                                                    <0.001   
##     1                                     1924 (42.3%)     280 (57.5%)              
##     2                                     2629 (57.7%)     207 (42.5%)              
## PAQ665:                                                                    <0.001   
##     1                                     2009 (44.1%)     123 (25.3%)              
##     2                                     2544 (55.9%)     364 (74.7%)              
## PAQ650:                                                                    <0.001   
##     1                                     1090 (23.9%)      48 (9.86%)              
##     2                                     3463 (76.1%)     439 (90.1%)              
## Cotinine, Serum (ng/mL)                    56.7 (131)       104 (163)      <0.001   
## Hematocrit (%)                            22.6 (60.9)      45.4 (78.0)     <0.001   
## Total Cotinine, urine (ng/mL)              686 (1833)      1573 (3242)      0.002   
## Total Hydroxycotinine, urine (ng/mL)      1348 (4209)      3143 (6196)      0.001   
## DBD100:                                                                     0.002   
##     1                                     1442 (47.6%)     128 (41.3%)              
##     2                                     944 (31.2%)       86 (27.7%)              
##     3                                     637 (21.0%)       96 (31.0%)              
##     9                                      5 (0.17%)        0 (0.00%)               
## Energy (kcal)                             2135 (1032)      1998 (1046)      0.009   
## Protein (gm)                              84.0 (46.2)      69.5 (42.8)     <0.001   
## Carbohydrate (gm)                          253 (129)        253 (142)       0.969   
## Total sugars (gm)                          109 (78.0)       123 (98.2)      0.006   
## Dietary fiber (gm)                        17.3 (10.9)      14.6 (10.0)     <0.001   
## Total fat (gm)                            82.3 (48.5)      74.1 (46.6)     <0.001   
## Total saturated fatty acids (gm)          26.2 (16.7)      24.4 (16.7)      0.029   
## Total monounsaturated fatty acids (gm)    28.9 (18.1)      25.2 (16.8)     <0.001   
## Total polyunsaturated fatty acids (gm)    19.4 (13.6)      17.4 (12.7)      0.001   
## Cholesterol (mg)                           305 (251)        248 (219)      <0.001   
## Vitamin E as alpha-tocopherol (mg)        9.19 (7.88)      7.76 (6.44)     <0.001   
## Added alpha-tocopherol (Vitamin E) (mg)   0.82 (3.82)      0.64 (2.73)      0.200   
## Retinol (mcg)                              410 (414)        353 (351)       0.002   
## Vitamin A, RAE (mcg)                       624 (618)        486 (427)      <0.001   
## Alpha-carotene (mcg)                       401 (1235)       284 (758)       0.004   
## Beta-carotene (mcg)                       2339 (4841)      1433 (2495)     <0.001   
## Beta-cryptoxanthin (mcg)                   95.6 (433)       61.9 (127)     <0.001   
## Lycopene (mcg)                            5027 (8770)      4068 (7255)      0.009   
## Lutein + zeaxanthin (mcg)                 1664 (3770)      1082 (2089)     <0.001   
## Thiamin (Vitamin B1) (mg)                 1.61 (0.92)      1.38 (0.79)     <0.001   
## Riboflavin (Vitamin B2) (mg)              2.09 (1.31)      1.87 (1.32)      0.001   
## Niacin (mg)                               26.4 (16.9)      22.2 (16.1)     <0.001   
## Vitamin B6 (mg)                           2.17 (1.74)      1.84 (2.16)      0.002   
## Total folate (mcg)                         402 (259)        337 (209)      <0.001   
## Folic acid (mcg)                           174 (182)        152 (146)       0.003   
## Food folate (mcg)                          228 (157)        186 (128)      <0.001   
## Folate, DFE (mcg)                          524 (369)        443 (297)      <0.001   
## Total choline (mg)                         346 (215)        282 (191)      <0.001   
## Vitamin B12 (mcg)                         4.94 (5.12)      4.16 (5.19)      0.003   
## Added vitamin B12 (mcg)                   1.01 (2.84)      0.87 (2.87)      0.316   
## Vitamin C (mg)                            82.6 (93.8)      64.9 (76.4)     <0.001   
## Vitamin D (D2 + D3) (mcg)                 4.71 (6.02)      3.53 (3.69)     <0.001   
## Vitamin K (mcg)                            122 (180)        89.7 (112)     <0.001   
## Calcium (mg)                               938 (602)        838 (552)      <0.001   
## Phosphorus (mg)                            1385 (728)       1194 (671)     <0.001   
## Magnesium (mg)                             304 (163)        262 (143)      <0.001   
## Iron (mg)                                 14.5 (8.59)      12.8 (8.21)     <0.001   
## Zinc (mg)                                 11.1 (6.93)      9.42 (6.42)     <0.001   
## Copper (mg)                               1.24 (0.79)      1.06 (0.65)     <0.001   
## Sodium (mg)                               3538 (1846)      3053 (1787)     <0.001   
## Potassium (mg)                            2646 (1300)      2250 (1161)     <0.001   
## Selenium (mcg)                             119 (71.7)      99.3 (64.3)     <0.001   
## Caffeine (mg)                              142 (177)        176 (244)       0.005   
## Theobromine (mg)                          35.7 (79.0)       45.5 (146)      0.162   
## Alcohol (gm)                              10.4 (29.0)      9.22 (26.8)      0.383   
## Moisture (gm)                             2892 (1509)      2858 (1579)      0.659   
## SFA 4:0 (Butanoic) (gm)                   0.47 (0.49)      0.47 (0.51)      0.852   
## SFA 6:0 (Hexanoic) (gm)                   0.30 (0.31)      0.29 (0.31)      0.600   
## SFA 8:0 (Octanoic) (gm)                   0.25 (0.28)      0.24 (0.24)      0.509   
## SFA 10:0 (Decanoic) (gm)                  0.49 (0.45)      0.47 (0.45)      0.414   
## SFA 12:0 (Dodecanoic) (gm)                0.82 (1.33)      0.80 (0.99)      0.693   
## SFA 14:0 (Tetradecanoic) (gm)             2.14 (1.85)      2.06 (1.91)      0.370   
## SFA 16:0 (Hexadecanoic) (gm)              14.3 (8.86)      13.2 (8.78)      0.008   
## SFA 18:0 (Octadecanoic) (gm)              6.36 (4.13)      5.94 (4.11)      0.039   
## MFA 16:1 (Hexadecenoic) (gm)              1.08 (0.83)      0.92 (0.74)     <0.001   
## MFA 18:1 (Octadecenoic) (gm)              26.1 (16.8)      22.8 (15.5)     <0.001   
## MFA 20:1 (Eicosenoic) (gm)                0.33 (0.33)      0.28 (0.27)     <0.001   
## MFA 22:1 (Docosenoic) (gm)                0.03 (0.11)      0.02 (0.04)     <0.001   
## PFA 18:2 (Octadecadienoic) (gm)           17.1 (12.2)      15.3 (11.4)      0.002   
## PFA 18:3 (Octadecatrienoic) (gm)          1.81 (1.42)      1.64 (1.40)      0.012   
## PFA 18:4 (Octadecatetraenoic) (gm)        0.01 (0.04)      0.01 (0.02)      0.001   
## PFA 20:4 (Eicosatetraenoic) (gm)          0.17 (0.14)      0.13 (0.12)     <0.001   
## PFA 20:5 (Eicosapentaenoic) (gm)          0.04 (0.12)      0.02 (0.07)     <0.001   
## PFA 22:5 (Docosapentaenoic) (gm)          0.03 (0.04)      0.02 (0.02)     <0.001   
## PFA 22:6 (Docosahexaenoic) (gm)           0.08 (0.21)      0.05 (0.11)     <0.001   
## hyper:                                                                     <0.001   
##     0                                     2915 (64.0%)     225 (46.2%)              
##     1                                     1638 (36.0%)     262 (53.8%)              
## db:                                                                        <0.001   
##     0                                     3849 (84.5%)     364 (74.7%)              
##     1                                     704 (15.5%)      123 (25.3%)              
## dyslip:                                                                     0.013   
##     0                                     1354 (29.7%)     118 (24.2%)              
##     1                                     3199 (70.3%)     369 (75.8%)              
## ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
# We can export this table by the following codes:
table_result <- createTable(med_iqr)
export2word(table_result, file = "tab1 with nutrition.docx")

6. Logistic regression model

# Change the reference category to 'No = 2'
# Those variables are categorical variables with 1: Yes, 2: No
df_new$SMQ020 <- relevel(df_new$SMQ020, ref = 2)
df_new$ALQ101 <- relevel(df_new$ALQ101, ref = 2)
df_new$PAQ665 <- relevel(df_new$PAQ665, ref = 2)
# Calculate OR(95% CI) for nutrition variables of having DD
library(epiDisplay)
## Loading required package: foreign
## Loading required package: survival
## Loading required package: MASS
## 
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
## 
##     select
## Loading required package: nnet
## 
## Attaching package: 'epiDisplay'
## The following object is masked from 'package:ggplot2':
## 
##     alpha
model1 = glm(dp10 ~ age + sex + educ + masts + PIR + SMQ020 + ALQ101 + PAQ665 + BMI + SBP + DBP + DR1TKCAL + DR1TPROT + DR1TCARB + DR1TSUGR + DR1TFIBE + DR1TTFAT + DR1TSFAT + DR1TMFAT + DR1TPFAT + DR1TCHOL, family = binomial, data = df_new)

logistic.display(model1)
## 
## Logistic regression predicting dp10 : 1 vs 0 
##  
##                       crude OR(95%CI)         adj. OR(95%CI)         
## age (cont. var.)      1.0093 (1.0032,1.0154)  1.0076 (0.9985,1.0167) 
##                                                                      
## sex: 2 vs 1           1.95 (1.56,2.44)        1.81 (1.4,2.35)        
##                                                                      
## educ: ref.=1                                                         
##    2                  0.83 (0.55,1.24)        0.87 (0.56,1.34)       
##    3                  0.5 (0.34,0.74)         0.57 (0.37,0.87)       
##    4                  0.47 (0.32,0.68)        0.61 (0.4,0.93)        
##    5                  0.21 (0.13,0.32)        0.48 (0.29,0.79)       
##                                                                      
## masts: ref.=1                                                        
##    2                  2.46 (1.67,3.61)        1.32 (0.85,2.06)       
##    3                  3.1 (2.32,4.15)         2.09 (1.52,2.87)       
##    4                  2.81 (1.69,4.67)        1.55 (0.9,2.67)        
##    5                  1.27 (0.93,1.72)        1.1 (0.78,1.55)        
##    6                  1.52 (1,2.31)           1.04 (0.66,1.65)       
##                                                                      
## PIR (cont. var.)      0.69 (0.64,0.75)        0.8 (0.73,0.88)        
##                                                                      
## SMQ020: 1 vs 2        1.84 (1.49,2.28)        1.45 (1.13,1.85)       
##                                                                      
## ALQ101: 1 vs 2        1.04 (0.81,1.32)        1.31 (0.99,1.74)       
##                                                                      
## PAQ665: 1 vs 2        0.44 (0.35,0.56)        0.57 (0.44,0.73)       
##                                                                      
## BMI (cont. var.)      1.05 (1.03,1.06)        1.04 (1.02,1.05)       
##                                                                      
## SBP (cont. var.)      1.0073 (1.0014,1.0133)  0.9996 (0.9922,1.0071) 
##                                                                      
## DBP (cont. var.)      1.0035 (0.9948,1.0123)  1.0042 (0.9943,1.0141) 
##                                                                      
## DR1TKCAL (cont. var.) 0.9999 (0.9998,1)       1.0002 (0.9997,1.0008) 
##                                                                      
## DR1TPROT (cont. var.) 0.9912 (0.9882,0.9942)  0.9927 (0.9869,0.9986) 
##                                                                      
## DR1TCARB (cont. var.) 1.0001 (0.9992,1.0009)  1.0003 (0.9964,1.0042) 
##                                                                      
## DR1TSUGR (cont. var.) 1.0017 (1.0006,1.0029)  1.0013 (0.9982,1.0045) 
##                                                                      
## DR1TFIBE (cont. var.) 0.974 (0.9627,0.9855)   0.9931 (0.9762,1.0104) 
##                                                                      
## DR1TTFAT (cont. var.) 0.9964 (0.9939,0.9989)  0.9986 (0.948,1.0519)  
##                                                                      
## DR1TSFAT (cont. var.) 0.99 (0.99,1)           1.01 (0.95,1.07)       
##                                                                      
## DR1TMFAT (cont. var.) 0.9883 (0.9814,0.9951)  0.9917 (0.9361,1.0505) 
##                                                                      
## DR1TPFAT (cont. var.) 0.9864 (0.9773,0.9956)  0.9982 (0.9441,1.0555) 
##                                                                      
## DR1TCHOL (cont. var.) 0.999 (0.9985,0.9995)   0.9996 (0.9989,1.0004) 
##                                                                      
##                       P(Wald's test) P(LR-test)
## age (cont. var.)      0.101          0.101     
##                                                
## sex: 2 vs 1           < 0.001        < 0.001   
##                                                
## educ: ref.=1                         0.009     
##    2                  0.521                    
##    3                  0.009                    
##    4                  0.022                    
##    5                  0.004                    
##                                                
## masts: ref.=1                        < 0.001   
##    2                  0.21                     
##    3                  < 0.001                  
##    4                  0.113                    
##    5                  0.599                    
##    6                  0.855                    
##                                                
## PIR (cont. var.)      < 0.001        < 0.001   
##                                                
## SMQ020: 1 vs 2        0.003          0.003     
##                                                
## ALQ101: 1 vs 2        0.059          0.057     
##                                                
## PAQ665: 1 vs 2        < 0.001        < 0.001   
##                                                
## BMI (cont. var.)      < 0.001        < 0.001   
##                                                
## SBP (cont. var.)      0.919          0.919     
##                                                
## DBP (cont. var.)      0.409          0.405     
##                                                
## DR1TKCAL (cont. var.) 0.436          0.448     
##                                                
## DR1TPROT (cont. var.) 0.015          0.013     
##                                                
## DR1TCARB (cont. var.) 0.889          0.889     
##                                                
## DR1TSUGR (cont. var.) 0.4            0.4       
##                                                
## DR1TFIBE (cont. var.) 0.432          0.429     
##                                                
## DR1TTFAT (cont. var.) 0.957          0.957     
##                                                
## DR1TSFAT (cont. var.) 0.702          0.701     
##                                                
## DR1TMFAT (cont. var.) 0.776          0.777     
##                                                
## DR1TPFAT (cont. var.) 0.95           0.95      
##                                                
## DR1TCHOL (cont. var.) 0.325          0.319     
##                                                
## Log-likelihood = -1097.9949
## No. of observations = 4041
## AIC value = 2253.9897
summary_model <- summary(model1)

# Extracting p-values
p_values <- summary_model$coefficients[, "Pr(>|z|)"]

# Sorting p-values and names in ascending order
sorted_p_values <- sort(p_values)
sorted_names <- names(p_values)[order(p_values)]

# Creating a bar plot in ascending order of -log(p-values)
barplot(-log(sorted_p_values), names.arg = sorted_names, horiz = TRUE, col = "blue", las = 1, main = "Important variables - based on p-value")

# Calculate OR(95% CI) for micro-nutrient variables of having DD
library(epiDisplay)
model2 = glm(dp10 ~ age + sex + educ + masts + PIR + SMQ020 + ALQ101 + PAQ665 + BMI + SBP + DBP + DR1TATOC + DR1TATOA + DR1TRET + DR1TVARA + DR1TACAR + DR1TBCAR + DR1TCRYP + DR1TLYCO + DR1TLZ + DR1TVB1 + DR1TVB2 + DR1TNIAC + DR1TVB6 +  DR1TFOLA + DR1TFA + DR1TFF + DR1TFDFE + DR1TCHL + DR1TVB12 + DR1TB12A + DR1TVC + DR1TVD + DR1TVK, family = binomial, data = df_new)

logistic.display(model2)
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## 
## Logistic regression predicting dp10 : 1 vs 0 
##  
##                       crude OR(95%CI)         adj. OR(95%CI)         
## age (cont. var.)      1.0093 (1.0032,1.0154)  1.0065 (0.9975,1.0155) 
##                                                                      
## sex: 2 vs 1           1.95 (1.56,2.44)        1.7 (1.31,2.21)        
##                                                                      
## educ: ref.=1                                                         
##    2                  0.83 (0.55,1.24)        0.93 (0.6,1.44)        
##    3                  0.5 (0.34,0.74)         0.62 (0.4,0.95)        
##    4                  0.47 (0.32,0.68)        0.63 (0.42,0.97)       
##    5                  0.21 (0.13,0.32)        0.49 (0.29,0.81)       
##                                                                      
## masts: ref.=1                                                        
##    2                  2.46 (1.67,3.61)        1.3 (0.83,2.01)        
##    3                  3.1 (2.32,4.15)         2.25 (1.64,3.09)       
##    4                  2.81 (1.69,4.67)        1.65 (0.96,2.84)       
##    5                  1.27 (0.93,1.72)        1.16 (0.82,1.65)       
##    6                  1.52 (1,2.31)           1.12 (0.7,1.77)        
##                                                                      
## PIR (cont. var.)      0.69 (0.64,0.75)        0.79 (0.72,0.87)       
##                                                                      
## SMQ020: 1 vs 2        1.84 (1.49,2.28)        1.46 (1.14,1.87)       
##                                                                      
## ALQ101: 1 vs 2        1.04 (0.81,1.32)        1.27 (0.96,1.69)       
##                                                                      
## PAQ665: 1 vs 2        0.44 (0.35,0.56)        0.56 (0.43,0.72)       
##                                                                      
## BMI (cont. var.)      1.05 (1.03,1.06)        1.03 (1.02,1.05)       
##                                                                      
## SBP (cont. var.)      1.0073 (1.0014,1.0133)  1 (0.9926,1.0075)      
##                                                                      
## DBP (cont. var.)      1.0035 (0.9948,1.0123)  1.0049 (0.9951,1.0148) 
##                                                                      
## DR1TATOC (cont. var.) 0.97 (0.95,0.99)        1.02 (0.99,1.04)       
##                                                                      
## DR1TATOA (cont. var.) 0.9864 (0.953,1.021)    0.9955 (0.9515,1.0415) 
##                                                                      
## DR1TRET (cont. var.)  0.9995 (0.9992,0.9998)  0.9945 (0.939,1.0533)  
##                                                                      
## DR1TVARA (cont. var.) 0.9994 (0.9991,0.9996)  1.0054 (0.9492,1.0649) 
##                                                                      
## DR1TACAR (cont. var.) 0.9998 (0.9997,1)       0.9998 (0.9974,1.0022) 
##                                                                      
## DR1TBCAR (cont. var.) 0.9999 (0.9999,1)       0.9995 (0.9947,1.0043) 
##                                                                      
## DR1TCRYP (cont. var.) 0.9986 (0.9976,0.9996)  0.9993 (0.9968,1.0018) 
##                                                                      
## DR1TLYCO (cont. var.) 1 (1,1)                 1 (1,1)                
##                                                                      
## DR1TLZ (cont. var.)   0.9999 (0.9998,1)       1 (0.9999,1.0001)      
##                                                                      
## DR1TVB1 (cont. var.)  0.71 (0.62,0.82)        0.88 (0.68,1.15)       
##                                                                      
## DR1TVB2 (cont. var.)  0.86 (0.78,0.95)        1.24 (1.06,1.45)       
##                                                                      
## DR1TNIAC (cont. var.) 0.98 (0.97,0.99)        0.98 (0.96,0.99)       
##                                                                      
## DR1TVB6 (cont. var.)  0.85 (0.78,0.93)        1.2 (1.04,1.38)        
##                                                                      
## DR1TFOLA (cont. var.) 1 (1,1)                 1.02 (0.9,1.15)        
##                                                                      
## DR1TFA (cont. var.)   1 (1,1)                 0.93 (0.81,1.06)       
##                                                                      
## DR1TFF (cont. var.)   1 (1,1)                 0.95 (0.86,1.05)       
##                                                                      
## DR1TFDFE (cont. var.) 1 (1,1)                 1.04 (0.94,1.15)       
##                                                                      
## DR1TCHL (cont. var.)  0.9983 (0.9976,0.9989)  0.9989 (0.9979,0.9999) 
##                                                                      
## DR1TVB12 (cont. var.) 0.96 (0.94,0.99)        1.03 (0.99,1.06)       
##                                                                      
## DR1TB12A (cont. var.) 0.99 (0.94,1.03)        0.93 (0.85,1.02)       
##                                                                      
## DR1TVC (cont. var.)   0.9969 (0.9954,0.9985)  0.9994 (0.9977,1.0011) 
##                                                                      
## DR1TVD (cont. var.)   0.95 (0.93,0.98)        0.97 (0.93,1)          
##                                                                      
## DR1TVK (cont. var.)   0.998 (0.9969,0.9991)   0.9996 (0.9975,1.0017) 
##                                                                      
##                       P(Wald's test) P(LR-test)
## age (cont. var.)      0.157          0.157     
##                                                
## sex: 2 vs 1           < 0.001        < 0.001   
##                                                
## educ: ref.=1                         0.01      
##    2                  0.756                    
##    3                  0.028                    
##    4                  0.034                    
##    5                  0.005                    
##                                                
## masts: ref.=1                        < 0.001   
##    2                  0.25                     
##    3                  < 0.001                  
##    4                  0.071                    
##    5                  0.392                    
##    6                  0.636                    
##                                                
## PIR (cont. var.)      < 0.001        < 0.001   
##                                                
## SMQ020: 1 vs 2        0.002          0.002     
##                                                
## ALQ101: 1 vs 2        0.092          0.089     
##                                                
## PAQ665: 1 vs 2        < 0.001        < 0.001   
##                                                
## BMI (cont. var.)      < 0.001        < 0.001   
##                                                
## SBP (cont. var.)      0.999          0.999     
##                                                
## DBP (cont. var.)      0.33           0.325     
##                                                
## DR1TATOC (cont. var.) 0.128          0.154     
##                                                
## DR1TATOA (cont. var.) 0.844          0.843     
##                                                
## DR1TRET (cont. var.)  0.85           0.85      
##                                                
## DR1TVARA (cont. var.) 0.855          0.855     
##                                                
## DR1TACAR (cont. var.) 0.88           0.88      
##                                                
## DR1TBCAR (cont. var.) 0.838          0.838     
##                                                
## DR1TCRYP (cont. var.) 0.568          0.567     
##                                                
## DR1TLYCO (cont. var.) 0.764          0.766     
##                                                
## DR1TLZ (cont. var.)   0.801          0.802     
##                                                
## DR1TVB1 (cont. var.)  0.353          0.348     
##                                                
## DR1TVB2 (cont. var.)  0.006          0.007     
##                                                
## DR1TNIAC (cont. var.) 0.008          0.007     
##                                                
## DR1TVB6 (cont. var.)  0.011          0.017     
##                                                
## DR1TFOLA (cont. var.) 0.798          0.797     
##                                                
## DR1TFA (cont. var.)   0.267          0.267     
##                                                
## DR1TFF (cont. var.)   0.305          0.303     
##                                                
## DR1TFDFE (cont. var.) 0.487          0.488     
##                                                
## DR1TCHL (cont. var.)  0.03           0.028     
##                                                
## DR1TVB12 (cont. var.) 0.182          0.217     
##                                                
## DR1TB12A (cont. var.) 0.149          0.146     
##                                                
## DR1TVC (cont. var.)   0.486          0.479     
##                                                
## DR1TVD (cont. var.)   0.053          0.041     
##                                                
## DR1TVK (cont. var.)   0.74           0.74      
##                                                
## Log-likelihood = -1094.176
## No. of observations = 4041
## AIC value = 2272.3519
summary_model <- summary(model2)

# Extracting p-values
p_values <- summary_model$coefficients[, "Pr(>|z|)"]

# Sorting p-values and names in ascending order
sorted_p_values <- sort(p_values)
sorted_names <- names(p_values)[order(p_values)]

# Creating a bar plot in ascending order of -log(p-values)
barplot(-log(sorted_p_values), names.arg = sorted_names, horiz = TRUE, col = "blue", las = 1, main = "Important variables - based on p-value")

# Calculate OR(95% CI) for mineral variables of having DD
library(epiDisplay)
model3 = glm(dp10 ~ age + sex + educ + masts + PIR + SMQ020 + ALQ101 + PAQ665 + BMI + SBP + DBP + DR1TCALC + DR1TPHOS + DR1TMAGN + DR1TIRON + DR1TZINC + DR1TCOPP + DR1TSODI + DR1TPOTA + DR1TSELE + DR1TCAFF + DR1TTHEO, family = binomial, data = df_new)

logistic.display(model3)
## 
## Logistic regression predicting dp10 : 1 vs 0 
##  
##                       crude OR(95%CI)         adj. OR(95%CI)         
## age (cont. var.)      1.0093 (1.0032,1.0154)  1.0055 (0.9965,1.0146) 
##                                                                      
## sex: 2 vs 1           1.95 (1.56,2.44)        1.71 (1.32,2.21)       
##                                                                      
## educ: ref.=1                                                         
##    2                  0.83 (0.55,1.24)        0.91 (0.59,1.4)        
##    3                  0.5 (0.34,0.74)         0.6 (0.39,0.92)        
##    4                  0.47 (0.32,0.68)        0.63 (0.41,0.95)       
##    5                  0.21 (0.13,0.32)        0.46 (0.28,0.77)       
##                                                                      
## masts: ref.=1                                                        
##    2                  2.46 (1.67,3.61)        1.35 (0.87,2.1)        
##    3                  3.1 (2.32,4.15)         2.15 (1.57,2.94)       
##    4                  2.81 (1.69,4.67)        1.58 (0.92,2.72)       
##    5                  1.27 (0.93,1.72)        1.17 (0.83,1.66)       
##    6                  1.52 (1,2.31)           1.12 (0.71,1.76)       
##                                                                      
## PIR (cont. var.)      0.69 (0.64,0.75)        0.8 (0.73,0.87)        
##                                                                      
## SMQ020: 1 vs 2        1.84 (1.49,2.28)        1.43 (1.12,1.84)       
##                                                                      
## ALQ101: 1 vs 2        1.04 (0.81,1.32)        1.28 (0.96,1.7)        
##                                                                      
## PAQ665: 1 vs 2        0.44 (0.35,0.56)        0.56 (0.43,0.72)       
##                                                                      
## BMI (cont. var.)      1.05 (1.03,1.06)        1.04 (1.02,1.05)       
##                                                                      
## SBP (cont. var.)      1.0073 (1.0014,1.0133)  1.0002 (0.9927,1.0077) 
##                                                                      
## DBP (cont. var.)      1.0035 (0.9948,1.0123)  1.0045 (0.9947,1.0145) 
##                                                                      
## DR1TCALC (cont. var.) 0.9997 (0.9995,0.9999)  1.0001 (0.9998,1.0004) 
##                                                                      
## DR1TPHOS (cont. var.) 0.9995 (0.9994,0.9997)  0.9999 (0.9994,1.0005) 
##                                                                      
## DR1TMAGN (cont. var.) 0.9981 (0.9972,0.9989)  1.001 (0.9991,1.0029)  
##                                                                      
## DR1TIRON (cont. var.) 0.9775 (0.9635,0.9917)  1.0037 (0.9827,1.0251) 
##                                                                      
## DR1TZINC (cont. var.) 0.9555 (0.9368,0.9746)  0.9967 (0.9649,1.0295) 
##                                                                      
## DR1TCOPP (cont. var.) 0.63 (0.52,0.77)        1.02 (0.72,1.45)       
##                                                                      
## DR1TSODI (cont. var.) 0.9998 (0.9998,0.9999)  1 (0.9999,1.0001)      
##                                                                      
## DR1TPOTA (cont. var.) 0.9997 (0.9996,0.9998)  0.9998 (0.9996,1)      
##                                                                      
## DR1TSELE (cont. var.) 0.9948 (0.9929,0.9968)  0.9975 (0.994,1.001)   
##                                                                      
## DR1TCAFF (cont. var.) 1.0008 (1.0003,1.0013)  1.0007 (1.0002,1.0013) 
##                                                                      
## DR1TTHEO (cont. var.) 1.0013 (1.0004,1.0022)  1.0015 (1.0004,1.0026) 
##                                                                      
##                       P(Wald's test) P(LR-test)
## age (cont. var.)      0.234          0.234     
##                                                
## sex: 2 vs 1           < 0.001        < 0.001   
##                                                
## educ: ref.=1                         0.007     
##    2                  0.665                    
##    3                  0.018                    
##    4                  0.029                    
##    5                  0.003                    
##                                                
## masts: ref.=1                        < 0.001   
##    2                  0.184                    
##    3                  < 0.001                  
##    4                  0.095                    
##    5                  0.365                    
##    6                  0.637                    
##                                                
## PIR (cont. var.)      < 0.001        < 0.001   
##                                                
## SMQ020: 1 vs 2        0.005          0.005     
##                                                
## ALQ101: 1 vs 2        0.087          0.085     
##                                                
## PAQ665: 1 vs 2        < 0.001        < 0.001   
##                                                
## BMI (cont. var.)      < 0.001        < 0.001   
##                                                
## SBP (cont. var.)      0.957          0.957     
##                                                
## DBP (cont. var.)      0.369          0.364     
##                                                
## DR1TCALC (cont. var.) 0.522          0.523     
##                                                
## DR1TPHOS (cont. var.) 0.804          0.803     
##                                                
## DR1TMAGN (cont. var.) 0.289          0.293     
##                                                
## DR1TIRON (cont. var.) 0.732          0.733     
##                                                
## DR1TZINC (cont. var.) 0.842          0.841     
##                                                
## DR1TCOPP (cont. var.) 0.92           0.92      
##                                                
## DR1TSODI (cont. var.) 0.772          0.772     
##                                                
## DR1TPOTA (cont. var.) 0.018          0.015     
##                                                
## DR1TSELE (cont. var.) 0.163          0.15      
##                                                
## DR1TCAFF (cont. var.) 0.008          0.01      
##                                                
## DR1TTHEO (cont. var.) 0.006          0.006     
##                                                
## Log-likelihood = -1099.482
## No. of observations = 4041
## AIC value = 2258.964
summary_model <- summary(model3)

# Extracting p-values
p_values <- summary_model$coefficients[, "Pr(>|z|)"]

# Sorting p-values and names in ascending order
sorted_p_values <- sort(p_values)
sorted_names <- names(p_values)[order(p_values)]

# Creating a bar plot in ascending order of -log(p-values)
barplot(-log(sorted_p_values), names.arg = sorted_names, horiz = TRUE, col = "blue", las = 2, main = "Important variables - based on p-value")

Correlation coefficients

dat <- subset(df_new, select = c (
                                               DR1TKCAL, DR1TPROT, 
                                               DR1TCARB, DR1TSUGR, DR1TFIBE, 
                                               DR1TTFAT, DR1TSFAT, DR1TMFAT, 
                                               DR1TPFAT, DR1TCHOL, DR1TATOC, 
                                               DR1TATOA, DR1TRET, DR1TVARA, 
                                               DR1TACAR, DR1TBCAR, DR1TCRYP, 
                                               DR1TLYCO, DR1TLZ, DR1TVB1, DR1TVB2, 
                                               DR1TNIAC, DR1TVB6, DR1TFOLA, DR1TFA, 
                                               DR1TFF, DR1TFDFE, DR1TCHL, DR1TVB12, 
                                               DR1TB12A, DR1TVC, DR1TVD, DR1TVK, 
                                               DR1TCALC, DR1TPHOS, DR1TMAGN, DR1TIRON, 
                                               DR1TZINC, DR1TCOPP, DR1TSODI, DR1TPOTA, 
                                               DR1TSELE, DR1TCAFF, DR1TTHEO, DR1TALCO, 
                                               DR1TMOIS, DR1TS040, DR1TS060, DR1TS080, 
                                               DR1TS100, DR1TS120, DR1TS140, DR1TS160, 
                                               DR1TS180, DR1TM161, DR1TM181, DR1TM201, 
                                               DR1TM221, DR1TP182, DR1TP183, DR1TP184, 
                                               DR1TP204, DR1TP205, DR1TP225, DR1TP226))
# Correlation matrix
library(lattice)
## 
## Attaching package: 'lattice'
## The following object is masked from 'package:epiDisplay':
## 
##     dotplot
# rounding to 2 decimal places
corr_mat <- round(cor(dat),2)  
head(corr_mat)
##          DR1TKCAL DR1TPROT DR1TCARB DR1TSUGR DR1TFIBE DR1TTFAT DR1TSFAT
## DR1TKCAL        1       NA       NA       NA       NA       NA       NA
## DR1TPROT       NA        1       NA       NA       NA       NA       NA
## DR1TCARB       NA       NA        1       NA       NA       NA       NA
## DR1TSUGR       NA       NA       NA        1       NA       NA       NA
## DR1TFIBE       NA       NA       NA       NA        1       NA       NA
## DR1TTFAT       NA       NA       NA       NA       NA        1       NA
##          DR1TMFAT DR1TPFAT DR1TCHOL DR1TATOC DR1TATOA DR1TRET DR1TVARA DR1TACAR
## DR1TKCAL       NA       NA       NA       NA       NA      NA       NA       NA
## DR1TPROT       NA       NA       NA       NA       NA      NA       NA       NA
## DR1TCARB       NA       NA       NA       NA       NA      NA       NA       NA
## DR1TSUGR       NA       NA       NA       NA       NA      NA       NA       NA
## DR1TFIBE       NA       NA       NA       NA       NA      NA       NA       NA
## DR1TTFAT       NA       NA       NA       NA       NA      NA       NA       NA
##          DR1TBCAR DR1TCRYP DR1TLYCO DR1TLZ DR1TVB1 DR1TVB2 DR1TNIAC DR1TVB6
## DR1TKCAL       NA       NA       NA     NA      NA      NA       NA      NA
## DR1TPROT       NA       NA       NA     NA      NA      NA       NA      NA
## DR1TCARB       NA       NA       NA     NA      NA      NA       NA      NA
## DR1TSUGR       NA       NA       NA     NA      NA      NA       NA      NA
## DR1TFIBE       NA       NA       NA     NA      NA      NA       NA      NA
## DR1TTFAT       NA       NA       NA     NA      NA      NA       NA      NA
##          DR1TFOLA DR1TFA DR1TFF DR1TFDFE DR1TCHL DR1TVB12 DR1TB12A DR1TVC
## DR1TKCAL       NA     NA     NA       NA      NA       NA       NA     NA
## DR1TPROT       NA     NA     NA       NA      NA       NA       NA     NA
## DR1TCARB       NA     NA     NA       NA      NA       NA       NA     NA
## DR1TSUGR       NA     NA     NA       NA      NA       NA       NA     NA
## DR1TFIBE       NA     NA     NA       NA      NA       NA       NA     NA
## DR1TTFAT       NA     NA     NA       NA      NA       NA       NA     NA
##          DR1TVD DR1TVK DR1TCALC DR1TPHOS DR1TMAGN DR1TIRON DR1TZINC DR1TCOPP
## DR1TKCAL     NA     NA       NA       NA       NA       NA       NA       NA
## DR1TPROT     NA     NA       NA       NA       NA       NA       NA       NA
## DR1TCARB     NA     NA       NA       NA       NA       NA       NA       NA
## DR1TSUGR     NA     NA       NA       NA       NA       NA       NA       NA
## DR1TFIBE     NA     NA       NA       NA       NA       NA       NA       NA
## DR1TTFAT     NA     NA       NA       NA       NA       NA       NA       NA
##          DR1TSODI DR1TPOTA DR1TSELE DR1TCAFF DR1TTHEO DR1TALCO DR1TMOIS
## DR1TKCAL       NA       NA       NA       NA       NA       NA       NA
## DR1TPROT       NA       NA       NA       NA       NA       NA       NA
## DR1TCARB       NA       NA       NA       NA       NA       NA       NA
## DR1TSUGR       NA       NA       NA       NA       NA       NA       NA
## DR1TFIBE       NA       NA       NA       NA       NA       NA       NA
## DR1TTFAT       NA       NA       NA       NA       NA       NA       NA
##          DR1TS040 DR1TS060 DR1TS080 DR1TS100 DR1TS120 DR1TS140 DR1TS160
## DR1TKCAL       NA       NA       NA       NA       NA       NA       NA
## DR1TPROT       NA       NA       NA       NA       NA       NA       NA
## DR1TCARB       NA       NA       NA       NA       NA       NA       NA
## DR1TSUGR       NA       NA       NA       NA       NA       NA       NA
## DR1TFIBE       NA       NA       NA       NA       NA       NA       NA
## DR1TTFAT       NA       NA       NA       NA       NA       NA       NA
##          DR1TS180 DR1TM161 DR1TM181 DR1TM201 DR1TM221 DR1TP182 DR1TP183
## DR1TKCAL       NA       NA       NA       NA       NA       NA       NA
## DR1TPROT       NA       NA       NA       NA       NA       NA       NA
## DR1TCARB       NA       NA       NA       NA       NA       NA       NA
## DR1TSUGR       NA       NA       NA       NA       NA       NA       NA
## DR1TFIBE       NA       NA       NA       NA       NA       NA       NA
## DR1TTFAT       NA       NA       NA       NA       NA       NA       NA
##          DR1TP184 DR1TP204 DR1TP205 DR1TP225 DR1TP226
## DR1TKCAL       NA       NA       NA       NA       NA
## DR1TPROT       NA       NA       NA       NA       NA
## DR1TCARB       NA       NA       NA       NA       NA
## DR1TSUGR       NA       NA       NA       NA       NA
## DR1TFIBE       NA       NA       NA       NA       NA
## DR1TTFAT       NA       NA       NA       NA       NA
# Remove rows with missing values before calculating correlations
dat_complete <- na.omit(dat)
corr_mat <- round(cor(dat_complete), 2)
head(corr_mat)
##          DR1TKCAL DR1TPROT DR1TCARB DR1TSUGR DR1TFIBE DR1TTFAT DR1TSFAT
## DR1TKCAL     1.00     0.76     0.88     0.66     0.55     0.88     0.82
## DR1TPROT     0.76     1.00     0.53     0.31     0.47     0.70     0.63
## DR1TCARB     0.88     0.53     1.00     0.84     0.56     0.66     0.62
## DR1TSUGR     0.66     0.31     0.84     1.00     0.26     0.47     0.47
## DR1TFIBE     0.55     0.47     0.56     0.26     1.00     0.47     0.37
## DR1TTFAT     0.88     0.70     0.66     0.47     0.47     1.00     0.91
##          DR1TMFAT DR1TPFAT DR1TCHOL DR1TATOC DR1TATOA DR1TRET DR1TVARA DR1TACAR
## DR1TKCAL     0.83     0.75     0.53     0.57     0.04    0.39     0.31     0.03
## DR1TPROT     0.67     0.57     0.67     0.50     0.07    0.35     0.33     0.05
## DR1TCARB     0.60     0.55     0.30     0.43     0.04    0.35     0.28     0.05
## DR1TSUGR     0.42     0.37     0.22     0.29     0.04    0.28     0.22     0.03
## DR1TFIBE     0.46     0.45     0.15     0.52     0.08    0.23     0.35     0.18
## DR1TTFAT     0.96     0.86     0.57     0.61     0.02    0.38     0.29     0.01
##          DR1TBCAR DR1TCRYP DR1TLYCO DR1TLZ DR1TVB1 DR1TVB2 DR1TNIAC DR1TVB6
## DR1TKCAL     0.07     0.04     0.26   0.06    0.69    0.61     0.66    0.49
## DR1TPROT     0.13     0.03     0.19   0.10    0.63    0.61     0.74    0.55
## DR1TCARB     0.06     0.07     0.26   0.05    0.65    0.53     0.53    0.42
## DR1TSUGR     0.04     0.06     0.14   0.02    0.35    0.39     0.32    0.29
## DR1TFIBE     0.28     0.16     0.28   0.25    0.56    0.41     0.38    0.38
## DR1TTFAT     0.05     0.01     0.21   0.06    0.57    0.53     0.54    0.36
##          DR1TFOLA DR1TFA DR1TFF DR1TFDFE DR1TCHL DR1TVB12 DR1TB12A DR1TVC
## DR1TKCAL     0.60   0.38   0.55     0.55    0.67     0.43     0.15   0.25
## DR1TPROT     0.51   0.27   0.53     0.46    0.81     0.51     0.10   0.23
## DR1TCARB     0.58   0.44   0.45     0.56    0.43     0.33     0.21   0.30
## DR1TSUGR     0.29   0.23   0.21     0.28    0.27     0.27     0.19   0.29
## DR1TFIBE     0.64   0.29   0.73     0.55    0.36     0.19     0.12   0.38
## DR1TTFAT     0.46   0.27   0.45     0.41    0.61     0.37     0.08   0.16
##          DR1TVD DR1TVK DR1TCALC DR1TPHOS DR1TMAGN DR1TIRON DR1TZINC DR1TCOPP
## DR1TKCAL   0.27   0.17     0.61     0.83     0.71     0.65     0.66     0.58
## DR1TPROT   0.37   0.19     0.56     0.89     0.70     0.58     0.75     0.57
## DR1TCARB   0.21   0.12     0.53     0.64     0.59     0.63     0.52     0.50
## DR1TSUGR   0.20   0.06     0.38     0.41     0.34     0.38     0.34     0.29
## DR1TFIBE   0.13   0.32     0.45     0.59     0.75     0.58     0.50     0.66
## DR1TTFAT   0.24   0.18     0.58     0.76     0.61     0.55     0.60     0.53
##          DR1TSODI DR1TPOTA DR1TSELE DR1TCAFF DR1TTHEO DR1TALCO DR1TMOIS
## DR1TKCAL     0.78     0.73     0.69     0.15     0.24     0.31     0.41
## DR1TPROT     0.79     0.75     0.85     0.07     0.09     0.14     0.35
## DR1TCARB     0.63     0.63     0.50     0.15     0.26     0.10     0.34
## DR1TSUGR     0.36     0.43     0.26     0.18     0.32    -0.01     0.24
## DR1TFIBE     0.47     0.70     0.39    -0.01     0.10     0.00     0.28
## DR1TTFAT     0.73     0.63     0.63     0.13     0.25     0.09     0.29
##          DR1TS040 DR1TS060 DR1TS080 DR1TS100 DR1TS120 DR1TS140 DR1TS160
## DR1TKCAL     0.50     0.49     0.46     0.54     0.30     0.61     0.84
## DR1TPROT     0.36     0.36     0.32     0.40     0.18     0.47     0.66
## DR1TCARB     0.40     0.40     0.37     0.43     0.25     0.47     0.64
## DR1TSUGR     0.34     0.34     0.31     0.34     0.22     0.37     0.47
## DR1TFIBE     0.22     0.20     0.21     0.25     0.14     0.26     0.39
## DR1TTFAT     0.55     0.54     0.50     0.60     0.33     0.67     0.93
##          DR1TS180 DR1TM161 DR1TM181 DR1TM201 DR1TM221 DR1TP182 DR1TP183
## DR1TKCAL     0.81     0.65     0.82     0.54     0.13     0.75     0.62
## DR1TPROT     0.62     0.65     0.65     0.49     0.13     0.56     0.47
## DR1TCARB     0.62     0.42     0.59     0.35     0.07     0.55     0.47
## DR1TSUGR     0.48     0.29     0.42     0.22     0.05     0.37     0.33
## DR1TFIBE     0.34     0.24     0.47     0.27     0.06     0.45     0.41
## DR1TTFAT     0.90     0.73     0.95     0.62     0.15     0.86     0.71
##          DR1TP184 DR1TP204 DR1TP205 DR1TP225 DR1TP226
## DR1TKCAL     0.14     0.49     0.10     0.26     0.11
## DR1TPROT     0.17     0.65     0.23     0.44     0.27
## DR1TCARB     0.09     0.26     0.03     0.12     0.01
## DR1TSUGR     0.04     0.17     0.00     0.07    -0.01
## DR1TFIBE     0.05     0.13     0.02     0.06     0.03
## DR1TTFAT     0.14     0.54     0.08     0.26     0.10
library(reshape2)
## 
## Attaching package: 'reshape2'
## The following object is masked from 'package:tidyr':
## 
##     smiths
# reduce the size of correlation matrix
melted_corr_mat <- melt(corr_mat)
head(melted_corr_mat)
##       Var1     Var2 value
## 1 DR1TKCAL DR1TKCAL  1.00
## 2 DR1TPROT DR1TKCAL  0.76
## 3 DR1TCARB DR1TKCAL  0.88
## 4 DR1TSUGR DR1TKCAL  0.66
## 5 DR1TFIBE DR1TKCAL  0.55
## 6 DR1TTFAT DR1TKCAL  0.88
# plotting the correlation heatmap
library(ggplot2)
ggplot(data = melted_corr_mat, aes(x=Var1, y=Var2, fill=value)) + geom_tile() +
geom_text(aes(Var2, Var1, label = value), color = "black", size = 4)

library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:MASS':
## 
##     select
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(ggcorrplot)

# create corr matrix and
# corresponding p-value matrix
corr_mat <- round(cor(dat_complete),2)
p_mat <- cor_pmat(dat_complete)
 
# plotting the interactive corr heatmap
corr_mat <- ggcorrplot(
  corr_mat, hc.order = TRUE, type = "lower",
  outline.col = "white",
  p.mat = p_mat
)
 
ggplotly(corr_mat)
## Warning in L$marker$color[idx] <- aes2plotly(data, params, "fill")[idx]: number
## of items to replace is not a multiple of replacement length