2024-02-03

Slide 2 - Plotly

BMI of Diabetics by Age

Slide 3 - Plotly Code

Code used to plot previous slide

## https://www.kaggle.com/datasets/iammustafatz/diabetes-prediction-dataset/data ##

hline <- function(y = 0, color = "red") {
  list(type = "line", x0 = 0, x1 = 1, xref = "paper", y0 = y, y1 = y,
       line = list(color = color, dash = "dot"))
}

mod = lm(bmi ~ age, data = DAB)
x = DAB$age; y = DAB$bmi

slide1 <- plot_ly(DAB, x = x, y = y) %>%
          add_trace(y = ~y, type = "scatter", mode = "markers",
                    marker = list(color = "blue", opacity = .5, size = 6, 
          line = list(color = "black", width = 1)), name = "BMI vs Age") %>%
          add_lines(x = x, y = fitted(mod), name="Linear Regression",
                    mode = "lines", line = list(width = 2, dash = "line",
                           color = "orange")) %>%
          layout(shapes = list(hline(30)), title = "Diabetics: Age vs BMI",
                 xaxis = list(title = 'Age (years)'), 
                 yaxis = list(title = 'BMI (Obesity > 30)'),
                 legend = list(orientation = "h"))

slide1

Slide 4 - Math Text 1

Obesity rate of Diabetics by Age Group

The average BMI of a person with diabetes 60 and older was: 30.97 with 44.46% (of 4,932) having obesity.

The average BMI of a person with diabetes in their 50s was 33.55 with 59.87% (of 1,859) having obesity.

The average BMI of a person with diabetes in their 40s was 34.14 with 57.66% (of 999) having obesity.

The average BMI of a person with diabetes in their 30s was 34.75 with 63.53% (of 436) having obesity.

The average BMI of a person with diabetes in their 20s was 30.22 with 38.1% (of 168) having obesity.

The average BMI of a person with diabetes under the age of 20 was 23.11 with 9.43% (of 106) having obesity.

Slide 5 - GGPlot1

Morbid Obesity

Slide 6 - GGPlot1 Code

morbid <- health %>%
        filter(bmi >= 40, age >= 18)

morbidBox <- morbid %>%
        select(diabetes,age) %>%
        arrange(diabetes) %>%
        group_by(diabetes)

morbidBox$diabetes[morbidBox$diabetes == 0] <- "Non-Diabetic"
morbidBox$diabetes[morbidBox$diabetes == 1] <- "Diabetic"

m + coord_flip() + theme(axis.title.y=element_blank(), axis.text.y = element_blank(),
                         axis.ticks.y = element_blank(),
                         legend.position="bottom", legend.title = element_blank()) + 
    ggtitle("Adults with Morbid Obesity By Age") + scale_y_continuous(name = "Age", 
                                       breaks = seq(min(morbidBox$age+2), max(morbidBox$age), by = 10))

Slide 7 - Math Text 2.

Morbid Obesity Cont.

Of those with Morbid Obesity 1,194 had diabetes and 3,334 did not.
The rate of diabetes amongst those with morbid obesity was 26.37%

427 of 1,327 Morbidly Obese Men were Diabetic. (32.18%)
767 of 3,201 Morbidly Obese Women were Diabetic. (23.96%)

\[X = \text{Morbidity}\] \[M \subset X\] \[F \subset X\] \[\text {Where M: is a subset of Morbidity amongst Males} \] \[\text {Where: F is a subset of Morbidity amongst Females} \]

Slide 8 - GGPlot 2.

Stacked Graph of BMIs across age Groups

Slide 9

Linear Regression \[\sum_{i=1}^{n} (y_{i}-\overline{y})^2 = \sum_{i=1}^{n} (\hat{y}_{i}-\overline{y})^2 + \sum_{i=1}^{n} (y_{i}-\hat{y})^2\]

\[\text{Where:}\] \[\sum_{i=1}^{n} (y_{i}-\overline{y})^2 = \text{sum of squares}\]