# Youth Risk Behavior Surveillance System (NLS)

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 NLS microdata by simply specifying `"nls"`

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

`lodown`

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

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

## Analysis Examples with the `survey`

library

Construct a complex sample survey design:

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

### Variable Recoding

Add new columns to the data set:

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

### Weighted Counts

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

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

### Descriptive Statistics

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

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

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

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

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

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

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

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

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

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

### Subsetting

Restrict the survey design to youths who ever drank alcohol:

`sub_nls_design <- subset( nls_design , qn41 == 1 )`

Calculate the mean (average) of this subset:

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

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

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

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

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

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

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

Perform a survey-weighted generalized linear model:

```
glm_result <-
svyglm(
bmipct ~ never_rarely_wore_bike_helmet + q2 ,
nls_design
)
summary( glm_result )
```

## 0.36 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 NLS users, this code replicates previously-presented examples:

```
library(srvyr)
nls_srvyr_design <- as_survey( nls_design )
```

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

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