Body Fat Prediction App

Winnie M.
2020/12/16

Introduction

The purpose of the App is to predict bodyfat ratio with one's weight and height using the 'bodyfat' data set.

How it works

  1. Create the data input and output User Interface (UI) in ui.R

    • Read weight and height from the input side panel
    • Display the calculations and plot in the main output panel
  2. Create the data computing function in server.R

    • Read the bodyfat data set
    • Compute body-mass index (BMI) in the data set using formula (i.e. weight / height ^ 2)
    • Fit a linear model with BMI as input and bodyfat as output to find the coefficients
    • Use the inputs and coefficients to calculate the prediction

Bodyfat Data Set

# Read the dataset and remove outlier
bodyfat <- read.csv("http://staff.pubhealth.ku.dk/~tag/Teaching/share/data/Bodyfat.csv")
bodyfat <- bodyfat[,-1]; bodyfat <- bodyfat[-42,]

## Change the unit of inputs and compute BMI
bodyfat$BMI <- bodyfat$Weight*0.4536 / (bodyfat$Height*0.0254)^2

dim(bodyfat)
[1] 251  15
head(bodyfat[,c(3:4,15)])
  Weight Height      BMI
1 154.25  67.75 23.62720
2 173.25  72.25 23.33475
3 154.00  66.25 24.66917
4 184.75  72.25 24.88367
5 184.25  71.25 25.51781
6 210.25  74.75 26.45570

Slide With Plot

# Fit the linear model
fit.lm <- lm(bodyfat~BMI, data=bodyfat)
fit.lm$coef
(Intercept)         BMI 
 -22.859366    1.652687 

plot of chunk unnamed-chunk-3