Introduction
This analysis explores the relationship between diabetes prevalence and two factors: smoking status and obesity status. We will test two hypotheses using different statistical frameworks.

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
# Load necessary libraries
library(dplyr)
library(ggplot2)

Data Preparation

First, we load the dataset.

dataset <-read_delim("C:/Users/Akshay Dembra/Downloads/Stats_Selected_Dataset/diabetes_binary_5050split_health_indicators_BRFSS2015_1.csv" , delim = ",")
## Rows: 70692 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (22): Diabetes_binary, HighBP, HighChol, CholCheck, BMI, Smoker, Stroke,...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(dataset)

Hypothesis 1: Smoking Status and Diabetes Prevalence

Null Hypothesis (H0): There is no difference in diabetes prevalence between smokers and non-smokers.

Neyman-Pearson Framework

Minimum Effect Size: 0.1 (chosen based on practical significance)

Neyman-Pearson Framework and Alternative Hypothesis

In the Neyman-Pearson framework, hypothesis testing involves both a null hypothesis ($H_0$) and an alternative hypothesis ($H_1$). The null hypothesis typically represents a statement of no effect or no difference, while the alternative hypothesis is the opposite, suggesting that there is an effect or a difference.

Null Hypothesis ($H_0$): What I am testing for, such as “There is no association between high blood pressure and diabetes.”

Alternative Hypothesis ($H_1$): This would be “There is an association between high blood pressure and diabetes.”

Selection of Alpha and Power Levels

Why I chose specific alpha (significance level) and power levels for my test:

Alpha Level (α): This is the probability of rejecting the null hypothesis when it is true (Type I error). Commonly, α is set at 0.05, meaning there is a 5% risk of concluding that an effect exists when it actually does not.

Power Level: This is the probability of correctly rejecting the null hypothesis when it is false (1 - Type II error). A power of 0.8 (80%) is often used, indicating a reasonable chance of detecting an effect if there is one.

For instance, if the consequences of a Type I error are severe, I might choose a lower alpha.

Sample Size Calculation

# Calculate sample size needed for adequate power
library(pwr)
effect_size <- 0.1
alpha <- 0.05
power <- 0.8

sample_size <- pwr.2p.test(h = effect_size, sig.level = alpha, power = power)$n
sample_size
## [1] 1569.772

Perform the Test

# Subset data by smoking status
smokers <- dataset %>% filter(Smoker == 1)
non_smokers <- dataset %>% filter(Smoker == 0)

# Proportion of diabetes in each group
p1 <- mean(smokers$Diabetes_binary)
p2 <- mean(non_smokers$Diabetes_binary)

# Perform two-proportion z-test
prop.test(x = c(sum(smokers$Diabetes_binary), sum(non_smokers$Diabetes_binary)),
          n = c(nrow(smokers), nrow(non_smokers)),
          alternative = "two.sided")
## 
##  2-sample test for equality of proportions with continuity correction
## 
## data:  c(sum(smokers$Diabetes_binary), sum(non_smokers$Diabetes_binary)) out of c(nrow(smokers), nrow(non_smokers))
## X-squared = 522.48, df = 1, p-value < 2.2e-16
## alternative hypothesis: two.sided
## 95 percent confidence interval:
##  0.07872292 0.09348572
## sample estimates:
##    prop 1    prop 2 
## 0.5451813 0.4590769

Insight Gathered

The test results indicate whether we reject or fail to reject the null hypothesis based on the p-value compared to the alpha level.

Visualization for Hypothesis 1

ggplot(dataset, aes(x = factor(Smoker), fill = factor(Diabetes_binary))) +
  geom_bar(position = "fill") +
  labs(title = "Diabetes Prevalence by Smoking Status",
       x = "Smoking Status", y = "Proportion of Diabetes") +
  scale_fill_discrete(name = "Diabetes")

Hypothesis 2: Obesity Status and Diabetes Prevalence

Null Hypothesis (H0): There is no difference in diabetes prevalence between obese and non-obese individuals.

Fisher’s Significance Testing Framework

Perform the Test

# Subset data by obesity status (BMI > 30 considered obese)
obese <- dataset %>% filter(BMI > 30)
non_obese <- dataset %>% filter(BMI <= 30)

# Create contingency table
table_obesity <- table(dataset$Diabetes_binary, dataset$BMI > 30)

# Perform chi-square test
chisq.test(table_obesity)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  table_obesity
## X-squared = 5252.7, df = 1, p-value < 2.2e-16

Insight Gathered

The p-value from the chi-square test will determine if we reject or fail to reject the null hypothesis.

Visualization for Hypothesis 2

ggplot(dataset, aes(x = factor(BMI > 30), fill = factor(Diabetes_binary))) +
  geom_bar(position = "fill") +
  labs(title = "Diabetes Prevalence by Obesity Status",
       x = "Obesity Status", y = "Proportion of Diabetes") +
  scale_fill_discrete(name = "Diabetes")

Interpretation of Results

Interpreting the results of statistical tests:

P-values: A p-value less than α suggests that you reject the null hypothesis in favor of the alternative hypothesis. For example, if you find a p-value of 0.03 with α set at 0.05, this indicates statistical significance.

Conclusion: This analysis provides insights into how smoking and obesity are associated with diabetes prevalence. Further research could explore other factors or interactions between variables.