Overweight and obesity are defined as abnormal or excessive fat accumulation that presents a risk to health. Once considered a problem only in high-income countries, overweight and obesity are now dramatically on the rise in low- and middle-income countries, particularly in urban settings. The vast majority of overweight or obese children live in developing countries, where the rate of increase has been more than 30% higher than that of developed countries. [1] The following work will examine the relationship between the level of body fat, age, and body dimensions.
The “bodyfat.csv” is a body fat prediction dataset provided by Roger W. Johnson from the Department of Mathematics & Computer Science at the South Dakota School of Mines & Technology[2]. It contains 252 observations with 15 attributes, each corresponding to one man. The attributes represent variables related to the body dimensions of each patient. These variables are: Density determined from underwater weighing, Percent body fat from Siri’s (1956) equation, Age (years), Weight (lbs), Height (inches), Neck circumference (cm), Chest circumference (cm), Abdomen 2 circumference (cm), Hip circumference (cm), Thigh circumference (cm), Knee circumference (cm), Ankle circumference (cm), Biceps (extended) circumference (cm), Forearm circumference (cm), Wrist circumference (cm). The measurement standards used are apparently those listed in Benhke and Wilmore (1974), pp. 45-48. For example, the abdomen 2 circumference is measured “laterally, at the level of the iliac crests, and anteriorly, at the umbilicus.
head(x,10)
## Density BodyFat Age Weight Height Neck Chest Abdomen Hip Thigh Knee Ankle
## 1 1.0708 12.3 23 154.25 67.75 36.2 93.1 85.2 94.5 59.0 37.3 21.9
## 2 1.0853 6.1 22 173.25 72.25 38.5 93.6 83.0 98.7 58.7 37.3 23.4
## 3 1.0414 25.3 22 154.00 66.25 34.0 95.8 87.9 99.2 59.6 38.9 24.0
## 4 1.0751 10.4 26 184.75 72.25 37.4 101.8 86.4 101.2 60.1 37.3 22.8
## 5 1.0340 28.7 24 184.25 71.25 34.4 97.3 100.0 101.9 63.2 42.2 24.0
## 6 1.0502 20.9 24 210.25 74.75 39.0 104.5 94.4 107.8 66.0 42.0 25.6
## 7 1.0549 19.2 26 181.00 69.75 36.4 105.1 90.7 100.3 58.4 38.3 22.9
## 8 1.0704 12.4 25 176.00 72.50 37.8 99.6 88.5 97.1 60.0 39.4 23.2
## 9 1.0900 4.1 25 191.00 74.00 38.1 100.9 82.5 99.9 62.9 38.3 23.8
## 10 1.0722 11.7 23 198.25 73.50 42.1 99.6 88.6 104.1 63.1 41.7 25.0
## Biceps Forearm Wrist
## 1 32.0 27.4 17.1
## 2 30.5 28.9 18.2
## 3 28.8 25.2 16.6
## 4 32.4 29.4 18.2
## 5 32.2 27.7 17.7
## 6 35.7 30.6 18.8
## 7 31.9 27.8 17.7
## 8 30.5 29.0 18.8
## 9 35.9 31.1 18.2
## 10 35.6 30.0 19.2
There is no need to perform data cleaning because the dataset does not contain any missing values.
x[!complete.cases(x), ]
## [1] Density BodyFat Age Weight Height Neck Chest Abdomen Hip
## [10] Thigh Knee Ankle Biceps Forearm Wrist
## <0 wierszy> (lub 'row.names' o zerowej długości)
The dataset was also checked for outliers.
summary(x)
## Density BodyFat Age Weight
## Min. :0.995 Min. : 0.00 Min. :22.00 Min. :118.5
## 1st Qu.:1.041 1st Qu.:12.47 1st Qu.:35.75 1st Qu.:159.0
## Median :1.055 Median :19.20 Median :43.00 Median :176.5
## Mean :1.056 Mean :19.15 Mean :44.88 Mean :178.9
## 3rd Qu.:1.070 3rd Qu.:25.30 3rd Qu.:54.00 3rd Qu.:197.0
## Max. :1.109 Max. :47.50 Max. :81.00 Max. :363.1
## Height Neck Chest Abdomen
## Min. :29.50 Min. :31.10 Min. : 79.30 Min. : 69.40
## 1st Qu.:68.25 1st Qu.:36.40 1st Qu.: 94.35 1st Qu.: 84.58
## Median :70.00 Median :38.00 Median : 99.65 Median : 90.95
## Mean :70.15 Mean :37.99 Mean :100.82 Mean : 92.56
## 3rd Qu.:72.25 3rd Qu.:39.42 3rd Qu.:105.38 3rd Qu.: 99.33
## Max. :77.75 Max. :51.20 Max. :136.20 Max. :148.10
## Hip Thigh Knee Ankle Biceps
## Min. : 85.0 Min. :47.20 Min. :33.00 Min. :19.1 Min. :24.80
## 1st Qu.: 95.5 1st Qu.:56.00 1st Qu.:36.98 1st Qu.:22.0 1st Qu.:30.20
## Median : 99.3 Median :59.00 Median :38.50 Median :22.8 Median :32.05
## Mean : 99.9 Mean :59.41 Mean :38.59 Mean :23.1 Mean :32.27
## 3rd Qu.:103.5 3rd Qu.:62.35 3rd Qu.:39.92 3rd Qu.:24.0 3rd Qu.:34.33
## Max. :147.7 Max. :87.30 Max. :49.10 Max. :33.9 Max. :45.00
## Forearm Wrist
## Min. :21.00 Min. :15.80
## 1st Qu.:27.30 1st Qu.:17.60
## Median :28.70 Median :18.30
## Mean :28.66 Mean :18.23
## 3rd Qu.:30.00 3rd Qu.:18.80
## Max. :34.90 Max. :21.40
We can observe that most values in the dataset fall within reasonable limits. However, an exception is noted for the “body fat” attribute, where the minimum value is recorded as 0%. Given that a body fat percentage of 0% is biologically impossible, all rows with a body fat value lower than 4% will be deleted. The threshold of 4% was chosen as a cutoff point because maintaining a body fat percentage as low as 4% for 100 days is considered a world record for natural conditions. [3]
x <- x[x$BodyFat > 4, ]
summary(x$BodyFat)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 4.10 13.50 19.50 19.62 25.30 47.50
str(x)
## 'data.frame': 245 obs. of 15 variables:
## $ Density: num 1.07 1.09 1.04 1.08 1.03 ...
## $ BodyFat: num 12.3 6.1 25.3 10.4 28.7 20.9 19.2 12.4 4.1 11.7 ...
## $ Age : int 23 22 22 26 24 24 26 25 25 23 ...
## $ Weight : num 154 173 154 185 184 ...
## $ Height : num 67.8 72.2 66.2 72.2 71.2 ...
## $ Neck : num 36.2 38.5 34 37.4 34.4 39 36.4 37.8 38.1 42.1 ...
## $ Chest : num 93.1 93.6 95.8 101.8 97.3 ...
## $ Abdomen: num 85.2 83 87.9 86.4 100 94.4 90.7 88.5 82.5 88.6 ...
## $ Hip : num 94.5 98.7 99.2 101.2 101.9 ...
## $ Thigh : num 59 58.7 59.6 60.1 63.2 66 58.4 60 62.9 63.1 ...
## $ Knee : num 37.3 37.3 38.9 37.3 42.2 42 38.3 39.4 38.3 41.7 ...
## $ Ankle : num 21.9 23.4 24 22.8 24 25.6 22.9 23.2 23.8 25 ...
## $ Biceps : num 32 30.5 28.8 32.4 32.2 35.7 31.9 30.5 35.9 35.6 ...
## $ Forearm: num 27.4 28.9 25.2 29.4 27.7 30.6 27.8 29 31.1 30 ...
## $ Wrist : num 17.1 18.2 16.6 18.2 17.7 18.8 17.7 18.8 18.2 19.2 ...
As observed, 7 observations were rejected during the process of eliminating rows with a body fat value lower than 4%.
Since all values in the dataset are already numerical, there is no need for discretization or conversion of non-numerical values.
str(x)
## 'data.frame': 245 obs. of 15 variables:
## $ Density: num 1.07 1.09 1.04 1.08 1.03 ...
## $ BodyFat: num 12.3 6.1 25.3 10.4 28.7 20.9 19.2 12.4 4.1 11.7 ...
## $ Age : int 23 22 22 26 24 24 26 25 25 23 ...
## $ Weight : num 154 173 154 185 184 ...
## $ Height : num 67.8 72.2 66.2 72.2 71.2 ...
## $ Neck : num 36.2 38.5 34 37.4 34.4 39 36.4 37.8 38.1 42.1 ...
## $ Chest : num 93.1 93.6 95.8 101.8 97.3 ...
## $ Abdomen: num 85.2 83 87.9 86.4 100 94.4 90.7 88.5 82.5 88.6 ...
## $ Hip : num 94.5 98.7 99.2 101.2 101.9 ...
## $ Thigh : num 59 58.7 59.6 60.1 63.2 66 58.4 60 62.9 63.1 ...
## $ Knee : num 37.3 37.3 38.9 37.3 42.2 42 38.3 39.4 38.3 41.7 ...
## $ Ankle : num 21.9 23.4 24 22.8 24 25.6 22.9 23.2 23.8 25 ...
## $ Biceps : num 32 30.5 28.8 32.4 32.2 35.7 31.9 30.5 35.9 35.6 ...
## $ Forearm: num 27.4 28.9 25.2 29.4 27.7 30.6 27.8 29 31.1 30 ...
## $ Wrist : num 17.1 18.2 16.6 18.2 17.7 18.8 17.7 18.8 18.2 19.2 ...
Dimension reduction is a component of data preparation. However, for the purpose of this work, this part has been moved to new chapter.
dim(x)
## [1] 245 15
Data set has 15 columns, and there is a potential for high correlation among them. This is not uncommon, as individuals with larger neck dimensions may also exhibit larger values in other body dimensions.
correletion <- cor(x, method="pearson")
corrplot(correletion)
In the above plot, a strong positive correlation is evident between weight and most body dimensions, except for height. An interesting observation is the ankle circumference, which shows only positive correlations with other dimensions.This is because as we get fatter, our ankles do not grow as much as other parts of the body. Age does not display significant correlations with the other columns. Density exhibits a notably negative correlation with body fat, as expected since fat has lower density than muscles. Additionally, density demonstrates negative correlations with other body dimensions.
A KMO value above 0.6 generally suggests that the dataset is suitable for dimensionality reduction through PCA, as it implies an adequate amount of common variance among the variables. Let’s check it.
KMO(correletion)
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = correletion)
## Overall MSA = 0.9
## MSA for each item =
## Density BodyFat Age Weight Height Neck Chest Abdomen Hip Thigh
## 0.80 0.81 0.41 0.88 0.59 0.95 0.93 0.93 0.92 0.92
## Knee Ankle Biceps Forearm Wrist
## 0.95 0.94 0.95 0.94 0.93
The Kaiser-Meyer Olkin (KMO) test value of 0.91 is higher than 0.6, which indicates that Principal Component Analysis (PCA) is considered useful for these variables.
cortest.bartlett(correletion)
## $chisq
## [1] 1845.135
##
## $p.value
## [1] 1.020457e-315
##
## $df
## [1] 105
With Bartlett’s test giving a p-value of 1.020457e-315 (which is less than 0.01), we can conclude that there is significant interrelationship among the variables.
pca <- prcomp(x, center = TRUE, scale = TRUE)
pca
## Standard deviations (1, .., p=15):
## [1] 2.9513337 1.4122250 1.0522220 0.8395423 0.8137458 0.7227764 0.5616165
## [8] 0.5187916 0.4757907 0.4346460 0.3700645 0.2836213 0.2114447 0.1566078
## [15] 0.1103813
##
## Rotation (n x k) = (15 x 15):
## PC1 PC2 PC3 PC4 PC5
## Density -0.22860941 -0.44753918 -0.149502867 -0.19813933 0.1832968742
## BodyFat 0.23465216 0.44351346 0.127985241 0.19511379 -0.1847599411
## Age 0.01657684 0.42963854 -0.705508044 -0.02780693 0.1482937463
## Weight 0.32800087 -0.08300032 0.023528581 0.08072780 0.0004868477
## Height 0.06822680 -0.44756165 -0.301698278 0.59704773 -0.5482017446
## Neck 0.28789299 -0.06939735 -0.196510456 -0.18573337 -0.0994884423
## Chest 0.30846104 0.10676976 -0.063224973 -0.01638528 -0.0494452735
## Abdomen 0.31088376 0.20534963 -0.002462774 0.11679347 -0.0278117815
## Hip 0.31249046 -0.02380156 0.173078468 0.08558830 0.1035490728
## Thigh 0.29318879 -0.09577320 0.323524403 -0.02635289 0.0821307608
## Knee 0.28784443 -0.12109064 0.002634591 0.15250819 0.1983069311
## Ankle 0.20785188 -0.24683048 -0.025150590 0.24263333 0.6263712908
## Biceps 0.28065354 -0.11072468 0.046176839 -0.31785797 -0.1319377777
## Forearm 0.22858146 -0.17756566 -0.040170749 -0.54877123 -0.3245092524
## Wrist 0.25455820 -0.15399258 -0.436259242 -0.13481870 0.1574324531
## PC6 PC7 PC8 PC9 PC10
## Density -0.312396283 0.01932902 -0.04589263 0.22633515 0.070815761
## BodyFat 0.285901379 -0.01184542 0.01095899 -0.20735837 -0.045550714
## Age -0.061757022 0.25523848 0.20725566 0.23208164 -0.111515737
## Weight -0.163163446 -0.04556564 -0.07174404 0.13540957 0.100126087
## Height 0.071489449 0.02713831 0.10125117 0.04476605 -0.001169248
## Neck -0.205298295 -0.44582091 -0.14342716 -0.07882090 -0.731342467
## Chest -0.135873500 -0.24807212 -0.16360854 0.44543762 0.347477729
## Abdomen -0.149338018 -0.09062153 -0.13680488 0.16832086 0.152226277
## Hip -0.265650341 0.08272499 -0.09708449 0.06541966 0.165127183
## Thigh -0.213265067 0.16451224 0.08904223 -0.16939801 -0.151870638
## Knee -0.103765706 0.69031333 -0.02556298 -0.01286399 -0.247503816
## Ankle 0.567974929 -0.24390495 0.08678313 0.19005979 -0.092443622
## Biceps 0.001394980 -0.07597996 0.85257159 0.01518219 0.120334580
## Forearm 0.502780242 0.28749658 -0.30878817 0.21159698 0.003224109
## Wrist 0.002507764 -0.06827370 -0.15999383 -0.69595010 0.396290348
## PC11 PC12 PC13 PC14 PC15
## Density 0.04512111 0.01449984 0.063703940 -0.003317179 -0.6997209199
## BodyFat -0.04502566 -0.01251253 -0.161541848 -0.031940882 -0.7094195437
## Age 0.31762328 0.06833333 -0.092928318 -0.044501860 0.0157106661
## Weight 0.01899402 -0.17079560 -0.119496819 -0.878002434 0.0393593916
## Height 0.12878017 0.06540836 -0.008386310 0.089346262 0.0007848912
## Neck -0.09380352 -0.09102108 -0.039249569 0.090008761 -0.0038520089
## Chest -0.35926668 0.43378619 -0.310896540 0.213519191 0.0364224871
## Abdomen 0.07118885 -0.09113486 0.849092914 0.095792164 -0.0501974085
## Hip 0.38703021 -0.56556694 -0.347274035 0.380211568 0.0239832988
## Thigh 0.49270859 0.64619150 0.007263767 -0.011009665 -0.0050503074
## Knee -0.53096892 -0.03115279 0.039945986 0.077560438 -0.0021473107
## Ankle 0.08537133 0.01278730 0.026570358 0.036814948 -0.0151567373
## Biceps -0.14065364 -0.12126176 0.060395799 0.048621469 -0.0231599064
## Forearm 0.17439152 -0.03272865 0.032211151 0.006270872 0.0038243104
## Wrist -0.05658074 0.04913747 0.008104924 0.028156521 0.0084070601
summary(pca)
## Importance of components:
## PC1 PC2 PC3 PC4 PC5 PC6 PC7
## Standard deviation 2.9513 1.4122 1.05222 0.83954 0.81375 0.72278 0.56162
## Proportion of Variance 0.5807 0.1330 0.07381 0.04699 0.04415 0.03483 0.02103
## Cumulative Proportion 0.5807 0.7137 0.78746 0.83445 0.87860 0.91342 0.93445
## PC8 PC9 PC10 PC11 PC12 PC13 PC14
## Standard deviation 0.51879 0.47579 0.43465 0.37006 0.28362 0.21144 0.15661
## Proportion of Variance 0.01794 0.01509 0.01259 0.00913 0.00536 0.00298 0.00164
## Cumulative Proportion 0.95239 0.96749 0.98008 0.98921 0.99457 0.99755 0.99919
## PC15
## Standard deviation 0.11038
## Proportion of Variance 0.00081
## Cumulative Proportion 1.00000
fviz_screeplot(pca, addlabels = TRUE)
In the above graph, it is illustrated that 58% of all variability is explained by PC1, 13% by PC2, and 7% by PC3. Cumulatively, these first three principal components explain almost 79% of the total variance in the dataset.
plot(summary(pca)$importance[3,]*100, type = "l", xlab="Number of components", ylab="Aggregate variance explained [%]")
In the above graph we find confirmation of what was observed in the previous graph. As each additional principal term is included, the explained variance increases, eventually reaching 100%. Specifically, focusing on the first three components, they explain almost 80% of the total variance in the dataset.
fviz_eig(pca, choice = "eigenvalue", ncp = 22, addlabels = TRUE)
The scree plot shows the relationship between the eigenvalues and the number of factors. According to the criterion mentioned in the article “Selecting the appropriate number of components or factors in PCA and EFA” [4], only the number of factors with eigenvalues greater than 1.00 should be included in the analysis. In this case, the first, second and third components meet this criterion and should be included in the analysis.
fviz_pca_var(pca)
The graph above shows the effect of all variables on the first and
second components, explaining 71,4% of the total variance.
Density
stands out with a negative influence on both the first and second
components, aligning with the earlier noted correlation. Its direction
is distinct from that of other variables.
Age has a minimal impact
on the first component but shows a positive influence on the second
component. Similarly, height has little influence on the first component
but negatively impacts the second component. Body fat exhibits a
positive influence on both the first and second components.
Other
variables related to body dimensions have a positive influence on the
first component and a smaller impact on the second component. They are
all grouped together. This confirms what we saw before, indicating a
strong correlation among them.
It is worth noting that density and
body fat have opposing influences. This is not a coincidence. In this
dataset, body fat was calculated based on density and is in the
denominator of the equation.
fviz_contrib(pca, "var",1)
In the above chart, we can observe confirmation of what we saw previously. Weight and body dimensions have the most significant impact on the first component.
fviz_contrib(pca, "var",2)
In this graph we see that 4 variables (age, height, density, body fat) have distinctive influence on second component.
fviz_contrib(pca, "var",3)
In this graph, it is evident that four variables age, height, density and body fat have a distinctive influence on the third component.
As observed, the first component is primarily associated with body weight and dimensions, while the second component is influenced by age, height, density, and body fat (representing general statistics). The third componentis linked to age, wrist circumference, and thigh circumference.
pcaR<-principal(x, nfactors=3, rotate="varimax")
pcaR
## Principal Components Analysis
## Call: principal(r = x, nfactors = 3, rotate = "varimax")
## Standardized loadings (pattern matrix) based upon correlation matrix
## RC1 RC2 RC3 h2 u2 com
## Density -0.27 -0.89 -0.13 0.88 0.121 1.2
## BodyFat 0.30 0.88 0.15 0.89 0.110 1.3
## Age -0.07 0.22 0.93 0.92 0.078 1.1
## Weight 0.89 0.39 -0.07 0.95 0.049 1.4
## Height 0.52 -0.52 0.02 0.54 0.459 2.0
## Neck 0.83 0.26 0.15 0.77 0.226 1.3
## Chest 0.74 0.54 0.13 0.86 0.144 1.9
## Abdomen 0.67 0.68 0.13 0.93 0.074 2.1
## Hip 0.78 0.49 -0.17 0.88 0.115 1.8
## Thigh 0.74 0.45 -0.36 0.88 0.117 2.1
## Knee 0.82 0.28 -0.07 0.75 0.249 1.3
## Ankle 0.70 0.02 -0.12 0.50 0.501 1.1
## Biceps 0.78 0.30 -0.11 0.71 0.287 1.3
## Forearm 0.71 0.12 -0.07 0.52 0.480 1.1
## Wrist 0.85 0.02 0.33 0.82 0.178 1.3
##
## RC1 RC2 RC3
## SS loadings 7.06 3.48 1.27
## Proportion Var 0.47 0.23 0.08
## Cumulative Var 0.47 0.70 0.79
## Proportion Explained 0.60 0.29 0.11
## Cumulative Proportion 0.60 0.89 1.00
##
## Mean item complexity = 1.5
## Test of the hypothesis that 3 components are sufficient.
##
## The root mean square of the residuals (RMSR) is 0.05
## with the empirical chi square 119.27 with prob < 2.4e-05
##
## Fit based upon off diagonal values = 0.99
print(loadings(pcaR), digits=3, cutoff=0.4, sort=TRUE)
##
## Loadings:
## RC1 RC2 RC3
## Weight 0.891
## Height 0.522 -0.518
## Neck 0.827
## Chest 0.740 0.540
## Hip 0.781 0.494
## Thigh 0.744 0.446
## Knee 0.816
## Ankle 0.695
## Biceps 0.782
## Forearm 0.708
## Wrist 0.846
## Density -0.887
## BodyFat 0.883
## Abdomen 0.671 0.677
## Age 0.931
##
## RC1 RC2 RC3
## SS loadings 7.060 3.482 1.270
## Proportion Var 0.471 0.232 0.085
## Cumulative Var 0.471 0.703 0.787
Assigning an “umbrella name” to each rotated component, we can
categorize them as follows:
The first component can be labeled as
“Body Dimension”.
The second component can be labeled as “General
Statistics(density, body fat, and body dimensions)”.
The third
component can be labeled as “Age”.
pcaR$complexity
## Density BodyFat Age Weight Height Neck Chest Abdomen
## 1.238288 1.287790 1.126936 1.385532 2.002027 1.269126 1.901691 2.075332
## Hip Thigh Knee Ankle Biceps Forearm Wrist
## 1.807118 2.144887 1.253696 1.062811 1.332175 1.072603 1.291862
We can see complexity for height, abdomen, thigh is higher than other variables, it likely indicates that these variables contribute variations to the dataset compared to the other variables.
pcaR$uniqueness
## Density BodyFat Age Weight Height Neck Chest
## 0.12057295 0.10995423 0.07838029 0.04854618 0.45918038 0.22570397 0.14406249
## Abdomen Hip Thigh Knee Ankle Biceps Forearm
## 0.07404723 0.11513333 0.11708052 0.24905617 0.50148256 0.28710354 0.48021908
## Wrist
## 0.17755574
We can see uniqueness for height, ankle, biceps and forearm is higher than other variables. It means that these variables carry additional information in relation to other variables in the model. Higher uniqueness suggests that these variables contribute unique information not captured from the other variables.
plot(pcaR$complexity, pcaR$uniqueness, xlim=c(0, 3), ylim=c(0, 0.6))
text(pcaR$complexity, pcaR$uniqueness, labels = names(pcaR$uniqueness), cex = 0.8, pos = 3, col = "blue")
set<-data.frame(complex=pcaR$complexity, unique=pcaR$uniqueness)
set.worst<-set[set$complex>1.5 & set$unique>0.3,]
set.worst
## complex unique
## Height 2.002027 0.4591804
The variables we refer to as ‘worst variables’ are those that have high uniqueness and complexity. In the case of this dataset, height is such a variable. It contributes a significant amount of unique information to the dataset and has a substantial impact on the variation present.
[1] https://www.who.int/health-topics/obesity#tab=tab_1
[2] https://www.kaggle.com/datasets/fedesoriano/body-fat-prediction-dataset
[3]https://www.worldrecordacademy.org/medical/worlds-first-person-to-maintain-less-than-four-per-cent-body-fat-for-100-days-naturally-guk-young-lee-218223
[4]https://hosted.jalt.org/test/bro_30.htm