knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE)

library(haven)    # reads the CDC's SAS transport (.XPT) file
library(dplyr)
library(ggplot2)

# The 2024 BRFSS file (LLCP2024.XPT) must be in the same folder as this .Rmd file
data_file <- "LLCP2024.XPT"

# Read only the column names first, to count how many variables the full dataset has
all_variables <- names(read_xpt(data_file, n_max = 0))

# Import only the columns needed for this project (the full file is very large)
brfss_raw <- read_xpt(data_file, col_select = c(`_RFSMOK3`, `_MICHD`, `_AGE_G`))

A. Introduction

Research question: Is the proportion of adults with heart disease higher among current smokers than among non-smokers?

For this project I am using the 2024 Behavioral Risk Factor Surveillance System (BRFSS) from the Centers for Disease Control and Prevention (CDC). The BRFSS is a yearly telephone survey that asks U.S. adults (18 and older) about their health, habits, and use of preventive health services. Each case (row) in the dataset is one adult who answered the survey. The full 2024 file has 457,670 respondents and 301 variables, covering things like general health, chronic conditions, exercise, alcohol use, and demographics. Most of these variables are not needed for my question, so I focus on three of them:

  • _RFSMOK3 (current smoker): a variable the CDC calculates from the smoking questions. It shows whether a person currently smokes cigarettes every day or some days (1 = No, 2 = Yes, 9 = Don’t know/Refused/Missing). In this project, “non-smokers” means everyone who is not a current smoker, so it includes former smokers and people who have never smoked.
  • _MICHD (heart disease): whether a person has ever been told by a health professional that they had a heart attack or coronary heart disease (1 = Yes, 2 = No). Blank values are missing.
  • _AGE_G (age group): the respondent’s age in six groups (18–24, 25–34, 35–44, 45–54, 55–64, 65+). I only use this one to explore whether age affects the results.

The data can be accessed on the CDC’s BRFSS 2024 Survey Data page: https://www.cdc.gov/brfss/annual_data/annual_2024.html.

B. Data Analysis

To answer my research question, I first explore the raw data to see how each variable is coded and how many responses are missing. Next, I clean the data by renaming the variables, removing the missing and “don’t know/refused” responses, and turning the number codes into readable labels. Then I calculate the percentage of people with heart disease in each smoking group and show it in a bar graph. Since older adults are more likely to have heart disease, I also make a grouped bar graph that compares the two smoking groups within each age group. This helps show whether age might be affecting the overall comparison.

# Exploratory data analysis: structure, summary, and coding of the raw variables
dim(brfss_raw)
## [1] 457670      3
glimpse(brfss_raw)
## Rows: 457,670
## Columns: 3
## $ `_MICHD`   <dbl> 2, 1, 2, 2, 2, 2, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 2, 2, 2,…
## $ `_AGE_G`   <dbl> 6, 6, 5, 6, 4, 4, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5,…
## $ `_RFSMOK3` <dbl> 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
summary(brfss_raw)
##      _MICHD          _AGE_G         _RFSMOK3    
##  Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:2.000   1st Qu.:3.000   1st Qu.:1.000  
##  Median :2.000   Median :5.000   Median :1.000  
##  Mean   :1.906   Mean   :4.386   Mean   :1.663  
##  3rd Qu.:2.000   3rd Qu.:6.000   3rd Qu.:1.000  
##  Max.   :2.000   Max.   :6.000   Max.   :9.000  
##  NAs    :5206
table(brfss_raw$`_RFSMOK3`, useNA = "ifany")
## 
##      1      2      9 
## 378554  47094  32022
table(brfss_raw$`_MICHD`, useNA = "ifany")
## 
##      1      2   <NA> 
##  42338 410126   5206
# Clean the data: rename, remove missing/unknown responses, and add readable labels
brfss <- brfss_raw %>%
  rename(smoker_code = `_RFSMOK3`,
         heart_code  = `_MICHD`,
         age_code    = `_AGE_G`) %>%
  filter(smoker_code %in% c(1, 2),
         heart_code  %in% c(1, 2)) %>%
  mutate(smoking_status = factor(ifelse(smoker_code == 2, "Current smoker", "Non-smoker"),
                                 levels = c("Current smoker", "Non-smoker")),
         heart_disease  = ifelse(heart_code == 1, "Yes", "No"),
         age_group      = factor(age_code, levels = 1:6,
                                 labels = c("18-24", "25-34", "35-44",
                                            "45-54", "55-64", "65+"))) %>%
  select(smoking_status, heart_disease, age_group)

nrow(brfss)                  # respondents left after cleaning
## [1] 421082
table(brfss$smoking_status)  # size of each group
## 
## Current smoker     Non-smoker 
##          46404         374678

After cleaning, 421,082 respondents have answers for both smoking status and heart disease. I removed 36,588 responses that were missing or coded as “don’t know/refused.”

# Number and percentage of people with heart disease in each smoking group
hd_summary <- brfss %>%
  group_by(smoking_status) %>%
  summarise(total             = n(),
            with_heart_disease = sum(heart_disease == "Yes"),
            percent           = round(mean(heart_disease == "Yes") * 100, 2))

hd_summary
## # A tibble: 2 × 4
##   smoking_status  total with_heart_disease percent
##   <fct>           <int>              <int>   <dbl>
## 1 Current smoker  46404               5869    12.6
## 2 Non-smoker     374678              33718     9
# Bar graph: percentage with heart disease by smoking status
ggplot(hd_summary, aes(x = smoking_status, y = percent, fill = smoking_status)) +
  geom_col(width = 0.6) +
  geom_text(aes(label = paste0(percent, "%")), vjust = -0.5) +
  scale_fill_manual(values = c("Current smoker" = "#C0392B", "Non-smoker" = "#2E86C1")) +
  labs(title = "Percentage of Adults with Heart Disease by Smoking Status",
       subtitle = "2024 BRFSS",
       x = "Smoking Status",
       y = "Percent with Heart Disease (%)") +
  theme_minimal() +
  theme(legend.position = "none")

# Grouped bar graph: percentage with heart disease by age group and smoking status
hd_by_age <- brfss %>%
  group_by(age_group, smoking_status) %>%
  summarise(percent = mean(heart_disease == "Yes") * 100, .groups = "drop")

ggplot(hd_by_age, aes(x = age_group, y = percent, fill = smoking_status)) +
  geom_col(position = "dodge") +
  scale_fill_manual(values = c("Current smoker" = "#C0392B", "Non-smoker" = "#2E86C1")) +
  labs(title = "Heart Disease by Age Group and Smoking Status",
       subtitle = "2024 BRFSS",
       x = "Age Group",
       y = "Percent with Heart Disease (%)",
       fill = "Smoking Status") +
  theme_minimal()

In the first bar graph, 12.65% of current smokers have heart disease, compared to 9% of non-smokers. In the second graph, heart disease goes up a lot with age for both groups, and current smokers have a higher percentage of heart disease than non-smokers in 6 of the 6 age groups.

C. Statistical Analysis

To test my research question, I use a difference in proportions test (two-proportion z-test), because both variables are categorical with two levels (current smoker vs. non-smoker, and heart disease yes vs. no). The test is one-sided because I expect the proportion of heart disease to be higher among current smokers. I use a significance level of \(\alpha = 0.05\).

Let \(p_1\) be the proportion of current smokers who have heart disease, and \(p_2\) be the proportion of non-smokers who have heart disease.

\[H_0: p_1 = p_2\] \[H_A: p_1 > p_2\]

  • Null hypothesis (\(H_0\)): The proportion of adults with heart disease is the same for current smokers and non-smokers.
  • Alternative hypothesis (\(H_A\)): The proportion of adults with heart disease is higher for current smokers than for non-smokers.
# Counts for the test (order: current smokers first, non-smokers second)
x <- hd_summary$with_heart_disease   # number with heart disease in each group
n <- hd_summary$total                # total in each group

test_result <- prop.test(x = x, n = n, alternative = "greater", correct = FALSE)
test_result
## 
##  2-sample test for equality of proportions without continuity correction
## 
## data:  x out of n
## X-squared = 645.28, df = 1, p-value < 2.2e-16
## alternative hypothesis: greater
## 95 percent confidence interval:
##  0.03383229 1.00000000
## sample estimates:
##     prop 1     prop 2 
## 0.12647617 0.08999194
# Pull out the key numbers from the test
p1_hat  <- x[1] / n[1]
p2_hat  <- x[2] / n[2]
diff    <- p1_hat - p2_hat
z_stat  <- sign(diff) * sqrt(test_result$statistic)
p_value <- test_result$p.value
alpha   <- 0.05

data.frame(p1_hat  = round(p1_hat, 4),
           p2_hat  = round(p2_hat, 4),
           difference = round(diff, 4),
           z = round(unname(z_stat), 2),
           p_value = format.pval(p_value, digits = 3, eps = 1e-16))
##   p1_hat p2_hat difference    z p_value
## 1 0.1265   0.09     0.0365 25.4  <1e-16

Interpretation: The sample proportion of heart disease is 0.1265 for current smokers (\(\hat{p}_1\)) and 0.09 for non-smokers (\(\hat{p}_2\)), a difference of 3.65 percentage points. The test statistic is z = 25.4 and the p-value is less than 0.0001. Since the p-value is less than alpha (0.05), I reject the null hypothesis. There is strong evidence that the proportion of adults with heart disease is higher among current smokers than among non-smokers.

Because the sample is so large, even a small difference can be statistically significant. That is why it is also important to look at the size of the difference (3.65 percentage points) and not just the p-value.

D. Conclusion and Future Directions

My analysis found that current smokers had a higher rate of heart disease (12.65%) than non-smokers (9%), and the two-proportion test showed that this difference is statistically significant. This supports my original prediction and matches what health experts have said about smoking and heart health. The age group graph adds important context: heart disease is much more common in older adults, and current smokers had higher rates than non-smokers in 6 of the 6 age groups. This shows that age plays a big role and that the overall comparison does not tell the whole story.

These results are important because heart disease is one of the leading causes of death in the United States, and smoking is a habit people can change. However, the BRFSS is an observational survey, so my results show an association between smoking and heart disease, not proof that smoking causes it. Other factors, like age, diet, exercise, and income, could also affect the results. The data is also self-reported, so some people may not report their smoking or health history accurately. In the future, researchers could split non-smokers into former smokers and people who have never smoked (using the _SMOKER3 variable), since former smokers may have quit after already developing heart problems. They could also control for age and other risk factors such as high blood pressure, diabetes, and BMI, use the BRFSS survey weights so the results represent the whole U.S. adult population, and compare several years of data to see if the pattern changes over time.

E. References

Centers for Disease Control and Prevention. (2025). Behavioral Risk Factor Surveillance System survey data, 2024. U.S. Department of Health and Human Services. https://www.cdc.gov/brfss/annual_data/annual_2024.html

Centers for Disease Control and Prevention. (2025). Summary matrix of calculated variables (CV) in the 2024 data file. https://www.cdc.gov/brfss/annual_data/2024/summary_matrix_24.html

Wickham, H., Miller, E., & Smith, D. (2023). haven: Import and export ‘SPSS’, ‘Stata’ and ‘SAS’ files [R package]. https://haven.tidyverse.org/

Wickham, H., François, R., Henry, L., Müller, K., & Vaughan, D. (2023). dplyr: A grammar of data manipulation [R package]. https://dplyr.tidyverse.org/

Wickham, H. (2016). ggplot2: Elegant graphics for data analysis. Springer-Verlag New York. https://ggplot2.tidyverse.org/