# Youth Risk Behavior Surveillance System (NCVS)

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 NCVS microdata by simply specifying `"ncvs"`

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( "ncvs" , output_dir = file.path( path.expand( "~" ) , "NCVS" ) )
```

`lodown`

also provides a catalog of available microdata extracts with the `get_catalog()`

function. After requesting the NCVS 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 NCVS microdata files
ncvs_cat <-
get_catalog( "ncvs" ,
output_dir = file.path( path.expand( "~" ) , "NCVS" ) )
# 2015 only
ncvs_cat <- subset( ncvs_cat , year == 2015 )
# download the microdata to your local computer
lodown( "ncvs" , ncvs_cat )
```

## Analysis Examples with the `survey`

library

Construct a complex sample survey design:

```
library(survey)
ncvs_df <- readRDS( file.path( path.expand( "~" ) , "NCVS" , "2015 main.rds" ) )
ncvs_design <-
svydesign(
~ psu ,
strata = ~ stratum ,
data = ncvs_df ,
weights = ~ weight ,
nest = TRUE
)
```

### Variable Recoding

Add new columns to the data set:

```
ncvs_design <-
update(
ncvs_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( ncvs_design , "sampling" ) != 0 )
svyby( ~ one , ~ ever_smoked_marijuana , ncvs_design , unwtd.count )
```

### Weighted Counts

Count the weighted size of the generalizable population, overall and by groups:

```
svytotal( ~ one , ncvs_design )
svyby( ~ one , ~ ever_smoked_marijuana , ncvs_design , svytotal )
```

### Descriptive Statistics

Calculate the mean (average) of a linear variable, overall and by groups:

```
svymean( ~ bmipct , ncvs_design , na.rm = TRUE )
svyby( ~ bmipct , ~ ever_smoked_marijuana , ncvs_design , svymean , na.rm = TRUE )
```

Calculate the distribution of a categorical variable, overall and by groups:

```
svymean( ~ q2 , ncvs_design , na.rm = TRUE )
svyby( ~ q2 , ~ ever_smoked_marijuana , ncvs_design , svymean , na.rm = TRUE )
```

Calculate the sum of a linear variable, overall and by groups:

```
svytotal( ~ bmipct , ncvs_design , na.rm = TRUE )
svyby( ~ bmipct , ~ ever_smoked_marijuana , ncvs_design , svytotal , na.rm = TRUE )
```

Calculate the weighted sum of a categorical variable, overall and by groups:

```
svytotal( ~ q2 , ncvs_design , na.rm = TRUE )
svyby( ~ q2 , ~ ever_smoked_marijuana , ncvs_design , svytotal , na.rm = TRUE )
```

Calculate the median (50th percentile) of a linear variable, overall and by groups:

```
svyquantile( ~ bmipct , ncvs_design , 0.5 , na.rm = TRUE )
svyby(
~ bmipct ,
~ ever_smoked_marijuana ,
ncvs_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 ,
ncvs_design ,
na.rm = TRUE
)
```

### Subsetting

Restrict the survey design to youths who ever drank alcohol:

`sub_ncvs_design <- subset( ncvs_design , qn41 == 1 )`

Calculate the mean (average) of this subset:

`svymean( ~ bmipct , sub_ncvs_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 , ncvs_design , na.rm = TRUE )
coef( this_result )
SE( this_result )
confint( this_result )
cv( this_result )
grouped_result <-
svyby(
~ bmipct ,
~ ever_smoked_marijuana ,
ncvs_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( ncvs_design )`

Calculate the complex sample survey-adjusted variance of any statistic:

`svyvar( ~ bmipct , ncvs_design , na.rm = TRUE )`

Include the complex sample design effect in the result for a specific statistic:

```
# SRS without replacement
svymean( ~ bmipct , ncvs_design , na.rm = TRUE , deff = TRUE )
# SRS with replacement
svymean( ~ bmipct , ncvs_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 , ncvs_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 , ncvs_design )`

Perform a chi-squared test of association for survey data:

```
svychisq(
~ never_rarely_wore_bike_helmet + q2 ,
ncvs_design
)
```

Perform a survey-weighted generalized linear model:

```
glm_result <-
svyglm(
bmipct ~ never_rarely_wore_bike_helmet + q2 ,
ncvs_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 NCVS users, this code replicates previously-presented examples:

```
library(srvyr)
ncvs_srvyr_design <- as_survey( ncvs_design )
```

Calculate the mean (average) of a linear variable, overall and by groups:

```
ncvs_srvyr_design %>%
summarize( mean = survey_mean( bmipct , na.rm = TRUE ) )
ncvs_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" )
```