Behavioral Risk Factor Surveillance System (BRFSS)
A health behavior telephone interview survey with enough sample size to examine all fifty states.
One table with one row per telephone respondent.
A complex survey designed to generalize to the civilian non-institutional adult population of the U.S.
Released annually since 1984 but all states did not participate until 1994.
Administered by the Centers for Disease Control and Prevention.
Please skim before you begin:
A haiku regarding this microdata:
Download, Import, Preparation
Download and import the national file:
library(haven)
zip_tf <- tempfile()
zip_url <- "https://www.cdc.gov/brfss/annual_data/2023/files/LLCP2023XPT.zip"
download.file( zip_url , zip_tf , mode = 'wb' )
brfss_tbl <- read_xpt( zip_tf )
brfss_df <- data.frame( brfss_tbl )
names( brfss_df ) <- tolower( names( brfss_df ) )
brfss_df[ , 'one' ] <- 1
Save Locally
Save the object at any point:
# brfss_fn <- file.path( path.expand( "~" ) , "BRFSS" , "this_file.rds" )
# saveRDS( brfss_df , file = brfss_fn , compress = FALSE )
Load the same object:
Survey Design Definition
Construct a complex sample survey design:
library(survey)
options( survey.lonely.psu = "adjust" )
variables_to_keep <-
c( 'one' , 'x_psu' , 'x_ststr' , 'x_llcpwt' , 'genhlth' , 'medcost1' ,
'x_state' , 'x_age80' , 'physhlth' , 'menthlth' , 'x_hlthpl1' )
brfss_df <- brfss_df[ variables_to_keep ]
brfss_national_design <-
svydesign(
id = ~ x_psu ,
strata = ~ x_ststr ,
data = brfss_df ,
weight = ~ x_llcpwt ,
nest = TRUE
)
Since large linearized survey designs execute slowly, a replication design might be preferrable for exploratory analysis. Coefficients (such as means and medians) do not change, standard errors and confidence intervals differ slightly. The initial conversion with as.svrepdesign
requires an extended period of processing time (perhaps run once overnight), subsequent analyses will finish much faster:
# brfss_replication_design <-
# as.svrepdesign(
# brfss_national_design ,
# type = 'bootstrap'
# )
# system.time( print( svymean( ~ x_age80 , brfss_national_design ) ) )
# system.time( print( svymean( ~ x_age80 , brfss_replication_design ) ) )
In this example, limit the national design to only Alaska for quicker processing:
Variable Recoding
Add new columns to the data set:
brfss_design <-
update(
brfss_design ,
fair_or_poor_health = ifelse( genhlth %in% 1:5 , as.numeric( genhlth > 3 ) , NA ) ,
no_doc_visit_due_to_cost =
factor(
medcost1 ,
levels = c( 1 , 2 , 7 , 9 ) ,
labels = c( "yes" , "no" , "dk" , "rf" )
) ,
physhlth_days_not_good =
ifelse( physhlth <= 30 , physhlth ,
ifelse( physhlth == 88 , 0 , NA ) ) ,
menthlth_days_not_good =
ifelse( menthlth <= 30 , menthlth ,
ifelse( menthlth == 88 , 0 , NA ) ) ,
state_name =
factor(
x_state ,
levels =
c(1, 2, 4, 5, 6, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 44, 45, 46, 47, 48, 49, 50, 51, 53, 54,
55, 56, 66, 72, 78) ,
labels =
c("ALABAMA", "ALASKA", "ARIZONA", "ARKANSAS", "CALIFORNIA",
"COLORADO", "CONNECTICUT", "DELAWARE", "DISTRICT OF COLUMBIA",
"FLORIDA", "GEORGIA", "HAWAII", "IDAHO", "ILLINOIS", "INDIANA",
"IOWA", "KANSAS", "KENTUCKY", "LOUISIANA", "MAINE", "MARYLAND",
"MASSACHUSETTS", "MICHIGAN", "MINNESOTA", "MISSISSIPPI",
"MISSOURI", "MONTANA", "NEBRASKA", "NEVADA", "NEW HAMPSHIRE",
"NEW JERSEY", "NEW MEXICO", "NEW YORK", "NORTH CAROLINA",
"NORTH DAKOTA", "OHIO", "OKLAHOMA", "OREGON", "PENNSYLVANIA",
"RHODE ISLAND", "SOUTH CAROLINA", "SOUTH DAKOTA", "TENNESSEE",
"TEXAS", "UTAH", "VERMONT", "VIRGINIA", "WASHINGTON",
"WEST VIRGINIA", "WISCONSIN", "WYOMING", "GUAM", "PUERTO RICO",
"U.S. VIRGIN ISLANDS")
)
)
Analysis Examples with the survey
library
Unweighted Counts
Count the unweighted number of records in the survey sample, overall and by groups:
Descriptive Statistics
Calculate the mean (average) of a linear variable, overall and by groups:
Calculate the distribution of a categorical variable, overall and by groups:
svymean( ~ no_doc_visit_due_to_cost , brfss_design , na.rm = TRUE )
svyby( ~ no_doc_visit_due_to_cost , ~ state_name , brfss_design , svymean , na.rm = TRUE )
Calculate the sum of a linear variable, overall and by groups:
Calculate the weighted sum of a categorical variable, overall and by groups:
svytotal( ~ no_doc_visit_due_to_cost , brfss_design , na.rm = TRUE )
svyby( ~ no_doc_visit_due_to_cost , ~ state_name , brfss_design , svytotal , na.rm = TRUE )
Calculate the median (50th percentile) of a linear variable, overall and by groups:
svyquantile( ~ x_age80 , brfss_design , 0.5 )
svyby(
~ x_age80 ,
~ state_name ,
brfss_design ,
svyquantile ,
0.5 ,
ci = TRUE
)
Estimate a ratio:
Subsetting
Restrict the survey design to persons without health insurance:
Calculate the mean (average) of this subset:
Measures of Uncertainty
Extract the coefficient, standard error, confidence interval, and coefficient of variation from any descriptive statistics function result, overall and by groups:
this_result <- svymean( ~ x_age80 , brfss_design )
coef( this_result )
SE( this_result )
confint( this_result )
cv( this_result )
grouped_result <-
svyby(
~ x_age80 ,
~ state_name ,
brfss_design ,
svymean
)
coef( grouped_result )
SE( grouped_result )
confint( grouped_result )
cv( grouped_result )
Calculate the degrees of freedom of any survey design object:
Calculate the complex sample survey-adjusted variance of any statistic:
Include the complex sample design effect in the result for a specific statistic:
# SRS without replacement
svymean( ~ x_age80 , brfss_design , deff = TRUE )
# SRS with replacement
svymean( ~ x_age80 , brfss_design , deff = "replace" )
Compute confidence intervals for proportions using methods that may be more accurate near 0 and 1. See ?svyciprop
for alternatives:
Regression Models and Tests of Association
Perform a design-based t-test:
Perform a chi-squared test of association for survey data:
Perform a survey-weighted generalized linear model:
glm_result <-
svyglm(
x_age80 ~ fair_or_poor_health + no_doc_visit_due_to_cost ,
brfss_design
)
summary( glm_result )
Replication Example
This example matches Alaska’s confidence intervals from the BRFSS Prevalence & Trends Data:
result <-
svymean(
~ no_doc_visit_due_to_cost ,
subset(
brfss_design ,
no_doc_visit_due_to_cost %in%
c( 'yes' , 'no' )
) ,
na.rm = TRUE
)
stopifnot( round( coef( result )[1] , 3 ) == 0.111 )
stopifnot( round( confint( result )[ 1 , 1 ] , 3 ) == 0.098 )
stopifnot( round( confint( result )[ 1 , 2 ] , 3 ) == 0.123 )
Analysis Examples with srvyr
The R srvyr
library calculates summary statistics from survey data, such as the mean, total or quantile using dplyr-like syntax. srvyr allows for the use of many verbs, such as summarize
, group_by
, and mutate
, the convenience of pipe-able functions, the tidyverse
style of non-standard evaluation and more consistent return types than the survey
package. This vignette details the available features. As a starting point for BRFSS users, this code replicates previously-presented examples:
Calculate the mean (average) of a linear variable, overall and by groups: