# National Study on Drug Use and Health (NSDUH)

The National Study on Drug Use and Health measures the prevalence and correlates of drug use in the United States.

One table with one row per sampled respondent.

A complex sample survey designed to generalize to the civilian, noninstitutionalized population of the United States aged 12 and older.

Released periodically since 1979 and annually since 1990.

Administered by the Substance Abuse and Mental Health Services Administration.

## Simplified Download and Importation

The R `lodown`

package easily downloads and imports all available NSDUH microdata by simply specifying `"nsduh"`

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

`lodown`

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

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

## Analysis Examples with the `survey`

library

Construct a complex sample survey design:

```
library(survey)
nsduh_df <-
readRDS( file.path( path.expand( "~" ) , "NSDUH" , "2016 main.rds" ) )
variables_to_keep <-
c( 'verep' , 'vestr' , 'analwt_c' , 'health' , 'cigtry' , 'cocage' ,
'mjever' , 'coutyp4' , 'preg' )
nsduh_df <- nsduh_df[ variables_to_keep ] ; gc()
nsduh_design <-
svydesign(
id = ~ verep ,
strata = ~ vestr ,
data = nsduh_df ,
weights = ~ analwt_c ,
nest = TRUE
)
```

### Variable Recoding

Add new columns to the data set:

```
nsduh_design <-
update(
nsduh_design ,
one = 1 ,
health =
factor(
health ,
levels = 1:5 ,
labels = c( "excellent" , "very good" , "good" ,
"fair" , "poor" )
) ,
age_tried_first_cigarette = ifelse( cigtry > 99 , NA , cigtry ) ,
age_tried_cocaine = ifelse( cocage > 99 , NA , cocage ) ,
ever_used_marijuana = as.numeric( mjever == 1 ) ,
county_type =
factor(
coutyp4 ,
levels = 1:3 ,
labels = c( "large metro" , "small metro" , "nonmetro" )
)
)
```

### Unweighted Counts

Count the unweighted number of records in the survey sample, overall and by groups:

```
sum( weights( nsduh_design , "sampling" ) != 0 )
svyby( ~ one , ~ county_type , nsduh_design , unwtd.count )
```

### Weighted Counts

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

```
svytotal( ~ one , nsduh_design )
svyby( ~ one , ~ county_type , nsduh_design , svytotal )
```

### Descriptive Statistics

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

```
svymean( ~ age_tried_first_cigarette , nsduh_design , na.rm = TRUE )
svyby( ~ age_tried_first_cigarette , ~ county_type , nsduh_design , svymean , na.rm = TRUE )
```

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

```
svymean( ~ health , nsduh_design , na.rm = TRUE )
svyby( ~ health , ~ county_type , nsduh_design , svymean , na.rm = TRUE )
```

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

```
svytotal( ~ age_tried_first_cigarette , nsduh_design , na.rm = TRUE )
svyby( ~ age_tried_first_cigarette , ~ county_type , nsduh_design , svytotal , na.rm = TRUE )
```

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

```
svytotal( ~ health , nsduh_design , na.rm = TRUE )
svyby( ~ health , ~ county_type , nsduh_design , svytotal , na.rm = TRUE )
```

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

```
svyquantile( ~ age_tried_first_cigarette , nsduh_design , 0.5 , na.rm = TRUE )
svyby(
~ age_tried_first_cigarette ,
~ county_type ,
nsduh_design ,
svyquantile ,
0.5 ,
ci = TRUE ,
keep.var = TRUE ,
na.rm = TRUE
)
```

Estimate a ratio:

```
svyratio(
numerator = ~ age_tried_first_cigarette ,
denominator = ~ age_tried_cocaine ,
nsduh_design ,
na.rm = TRUE
)
```

### Subsetting

Restrict the survey design to individuals who are pregnant:

`sub_nsduh_design <- subset( nsduh_design , preg == 1 )`

Calculate the mean (average) of this subset:

`svymean( ~ age_tried_first_cigarette , sub_nsduh_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( ~ age_tried_first_cigarette , nsduh_design , na.rm = TRUE )
coef( this_result )
SE( this_result )
confint( this_result )
cv( this_result )
grouped_result <-
svyby(
~ age_tried_first_cigarette ,
~ county_type ,
nsduh_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( nsduh_design )`

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

`svyvar( ~ age_tried_first_cigarette , nsduh_design , na.rm = TRUE )`

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

```
# SRS without replacement
svymean( ~ age_tried_first_cigarette , nsduh_design , na.rm = TRUE , deff = TRUE )
# SRS with replacement
svymean( ~ age_tried_first_cigarette , nsduh_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( ~ ever_used_marijuana , nsduh_design ,
method = "likelihood" , na.rm = TRUE )
```

### Regression Models and Tests of Association

Perform a design-based t-test:

`svyttest( age_tried_first_cigarette ~ ever_used_marijuana , nsduh_design )`

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

```
svychisq(
~ ever_used_marijuana + health ,
nsduh_design
)
```

Perform a survey-weighted generalized linear model:

```
glm_result <-
svyglm(
age_tried_first_cigarette ~ ever_used_marijuana + health ,
nsduh_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 NSDUH users, this code replicates previously-presented examples:

```
library(srvyr)
nsduh_srvyr_design <- as_survey( nsduh_design )
```

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

```
nsduh_srvyr_design %>%
summarize( mean = survey_mean( age_tried_first_cigarette , na.rm = TRUE ) )
nsduh_srvyr_design %>%
group_by( county_type ) %>%
summarize( mean = survey_mean( age_tried_first_cigarette , na.rm = TRUE ) )
```