Youth Risk Behavior Surveillance System (YRBSS)
The Youth Risk Behavior Surveillance System is the high school edition of the Behavioral Risk Factor Surveillance System (BRFSS), a scientific study of good kids who do bad things.
One table with one row per sampled youth respondent.
A complex sample survey designed to generalize to all public and private school students in grades 9-12 in the United States.
Released biennially since 1993.
Administered by the Centers for Disease Control and Prevention.
Simplified Download and Importation
The R lodown
package easily downloads and imports all available YRBSS microdata by simply specifying "yrbss"
with an output_dir =
parameter in the lodown()
function. Depending on your internet connection and computer processing speed, you might prefer to run this step overnight.
library(lodown)
lodown( "yrbss" , output_dir = file.path( path.expand( "~" ) , "YRBSS" ) )
lodown
also provides a catalog of available microdata extracts with the get_catalog()
function. After requesting the YRBSS catalog, you could pass a subsetted catalog through the lodown()
function in order to download and import specific extracts (rather than all available extracts).
library(lodown)
# examine all available YRBSS microdata files
yrbss_cat <-
get_catalog( "yrbss" ,
output_dir = file.path( path.expand( "~" ) , "YRBSS" ) )
# 2015 only
yrbss_cat <- subset( yrbss_cat , year == 2015 )
# download the microdata to your local computer
yrbss_cat <- lodown( "yrbss" , yrbss_cat )
Analysis Examples with the survey
library
Construct a complex sample survey design:
library(survey)
yrbss_df <- readRDS( file.path( path.expand( "~" ) , "YRBSS" , "2015 main.rds" ) )
yrbss_design <-
svydesign(
~ psu ,
strata = ~ stratum ,
data = yrbss_df ,
weights = ~ weight ,
nest = TRUE
)
Variable Recoding
Add new columns to the data set:
yrbss_design <-
update(
yrbss_design ,
q2 = q2 ,
never_rarely_wore_bike_helmet = as.numeric( qn8 == 1 ) ,
ever_smoked_marijuana = as.numeric( qn47 == 1 ) ,
ever_tried_to_quit_cigarettes = as.numeric( q36 > 2 ) ,
smoked_cigarettes_past_year = as.numeric( q36 > 1 )
)
Unweighted Counts
Count the unweighted number of records in the survey sample, overall and by groups:
sum( weights( yrbss_design , "sampling" ) != 0 )
svyby( ~ one , ~ ever_smoked_marijuana , yrbss_design , unwtd.count )
Weighted Counts
Count the weighted size of the generalizable population, overall and by groups:
svytotal( ~ one , yrbss_design )
svyby( ~ one , ~ ever_smoked_marijuana , yrbss_design , svytotal )
Descriptive Statistics
Calculate the mean (average) of a linear variable, overall and by groups:
svymean( ~ bmipct , yrbss_design , na.rm = TRUE )
svyby( ~ bmipct , ~ ever_smoked_marijuana , yrbss_design , svymean , na.rm = TRUE )
Calculate the distribution of a categorical variable, overall and by groups:
svymean( ~ q2 , yrbss_design , na.rm = TRUE )
svyby( ~ q2 , ~ ever_smoked_marijuana , yrbss_design , svymean , na.rm = TRUE )
Calculate the sum of a linear variable, overall and by groups:
svytotal( ~ bmipct , yrbss_design , na.rm = TRUE )
svyby( ~ bmipct , ~ ever_smoked_marijuana , yrbss_design , svytotal , na.rm = TRUE )
Calculate the weighted sum of a categorical variable, overall and by groups:
svytotal( ~ q2 , yrbss_design , na.rm = TRUE )
svyby( ~ q2 , ~ ever_smoked_marijuana , yrbss_design , svytotal , na.rm = TRUE )
Calculate the median (50th percentile) of a linear variable, overall and by groups:
svyquantile( ~ bmipct , yrbss_design , 0.5 , na.rm = TRUE )
svyby(
~ bmipct ,
~ ever_smoked_marijuana ,
yrbss_design ,
svyquantile ,
0.5 ,
ci = TRUE ,
keep.var = TRUE ,
na.rm = TRUE
)
Estimate a ratio:
svyratio(
numerator = ~ ever_tried_to_quit_cigarettes ,
denominator = ~ smoked_cigarettes_past_year ,
yrbss_design ,
na.rm = TRUE
)
Subsetting
Restrict the survey design to youths who ever drank alcohol:
sub_yrbss_design <- subset( yrbss_design , qn41 == 1 )
Calculate the mean (average) of this subset:
svymean( ~ bmipct , sub_yrbss_design , na.rm = TRUE )
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( ~ bmipct , yrbss_design , na.rm = TRUE )
coef( this_result )
SE( this_result )
confint( this_result )
cv( this_result )
grouped_result <-
svyby(
~ bmipct ,
~ ever_smoked_marijuana ,
yrbss_design ,
svymean ,
na.rm = TRUE
)
coef( grouped_result )
SE( grouped_result )
confint( grouped_result )
cv( grouped_result )
Calculate the degrees of freedom of any survey design object:
degf( yrbss_design )
Calculate the complex sample survey-adjusted variance of any statistic:
svyvar( ~ bmipct , yrbss_design , na.rm = TRUE )
Include the complex sample design effect in the result for a specific statistic:
# SRS without replacement
svymean( ~ bmipct , yrbss_design , na.rm = TRUE , deff = TRUE )
# SRS with replacement
svymean( ~ bmipct , yrbss_design , na.rm = TRUE , deff = "replace" )
Compute confidence intervals for proportions using methods that may be more accurate near 0 and 1. See ?svyciprop
for alternatives:
svyciprop( ~ never_rarely_wore_bike_helmet , yrbss_design ,
method = "likelihood" , na.rm = TRUE )
Regression Models and Tests of Association
Perform a design-based t-test:
svyttest( bmipct ~ never_rarely_wore_bike_helmet , yrbss_design )
Perform a chi-squared test of association for survey data:
svychisq(
~ never_rarely_wore_bike_helmet + q2 ,
yrbss_design
)
Perform a survey-weighted generalized linear model:
glm_result <-
svyglm(
bmipct ~ never_rarely_wore_bike_helmet + q2 ,
yrbss_design
)
summary( glm_result )
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 YRBSS users, this code replicates previously-presented examples:
library(srvyr)
yrbss_srvyr_design <- as_survey( yrbss_design )
Calculate the mean (average) of a linear variable, overall and by groups:
yrbss_srvyr_design %>%
summarize( mean = survey_mean( bmipct , na.rm = TRUE ) )
yrbss_srvyr_design %>%
group_by( ever_smoked_marijuana ) %>%
summarize( mean = survey_mean( bmipct , na.rm = TRUE ) )
Replication Example
This snippet replicates the “never/rarely wore bicycle helmet” row of PDF page 29 of this CDC analysis software document.
unwtd.count( ~ never_rarely_wore_bike_helmet , yrbss_design )
svytotal( ~ one , subset( yrbss_design , !is.na( never_rarely_wore_bike_helmet ) ) )
svymean( ~ never_rarely_wore_bike_helmet , yrbss_design , na.rm = TRUE )
svyciprop( ~ never_rarely_wore_bike_helmet , yrbss_design , na.rm = TRUE , method = "beta" )