# National Immunization Survey (NIS)

*Contributed by Joe Walsh <jtwalsh@protonmail.com>*

The National Immunization Survey tracks childhood vaccination rates at the state-level.

One table with one row per sampled toddler.

A complex sample survey designed to generalize to children aged 19-35 months in the United States.

Released biennially since 1995.

Administered by the Centers for Disease Control and Prevention.

## Simplified Download and Importation

The R `lodown`

package easily downloads and imports all available NIS microdata by simply specifying `"nis"`

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

`lodown`

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

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

## Analysis Examples with the `survey`

library

Construct a complex sample survey design:

```
options( survey.lonely.psu = "adjust" )
library(survey)
nis_df <- readRDS( file.path( path.expand( "~" ) , "NIS" , "2015 main.rds" ) )
nis_design <-
svydesign(
id = ~ seqnumhh ,
strata = ~ stratum ,
weights = ~ provwt_d ,
data = subset( nis_df , provwt_d > 0 )
)
```

### Variable Recoding

Add new columns to the data set:

```
nis_design <-
update(
nis_design ,
state_name =
factor(
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")
) ,
sex =
factor(
ifelse( sex %in% 1:2 , sex , NA ) ,
labels = c( "male" , "female" )
) ,
dtap_3p =
as.numeric(
( p_numdah >= 3 ) |
( p_numdhi >= 3 ) |
( p_numdih >= 3 ) |
( p_numdta >= 3 ) |
( p_numdtp >= 3 )
) ,
dtap_4p =
as.numeric(
( p_numdah >= 4 ) |
( p_numdhi >= 4 ) |
( p_numdih >= 4 ) |
( p_numdta >= 4 ) |
( p_numdtp >= 4 )
)
)
```

### Unweighted Counts

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

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

### Weighted Counts

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

```
svytotal( ~ one , nis_design )
svyby( ~ one , ~ state_name , nis_design , svytotal )
```

### Descriptive Statistics

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

```
svymean( ~ p_nuhepx , nis_design , na.rm = TRUE )
svyby( ~ p_nuhepx , ~ state_name , nis_design , svymean , na.rm = TRUE )
```

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

```
svymean( ~ sex , nis_design , na.rm = TRUE )
svyby( ~ sex , ~ state_name , nis_design , svymean , na.rm = TRUE )
```

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

```
svytotal( ~ p_nuhepx , nis_design , na.rm = TRUE )
svyby( ~ p_nuhepx , ~ state_name , nis_design , svytotal , na.rm = TRUE )
```

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

```
svytotal( ~ sex , nis_design , na.rm = TRUE )
svyby( ~ sex , ~ state_name , nis_design , svytotal , na.rm = TRUE )
```

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

```
svyquantile( ~ p_nuhepx , nis_design , 0.5 , na.rm = TRUE )
svyby(
~ p_nuhepx ,
~ state_name ,
nis_design ,
svyquantile ,
0.5 ,
ci = TRUE ,
keep.var = TRUE ,
na.rm = TRUE
)
```

Estimate a ratio:

```
svyratio(
numerator = ~ childnm ,
denominator = ~ bf_endr06 ,
nis_design ,
na.rm = TRUE
)
```

### Subsetting

Restrict the survey design to toddlers up to date on polio shots:

`sub_nis_design <- subset( nis_design , p_utdpol == 1 )`

Calculate the mean (average) of this subset:

`svymean( ~ p_nuhepx , sub_nis_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( ~ p_nuhepx , nis_design , na.rm = TRUE )
coef( this_result )
SE( this_result )
confint( this_result )
cv( this_result )
grouped_result <-
svyby(
~ p_nuhepx ,
~ state_name ,
nis_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( nis_design )`

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

`svyvar( ~ p_nuhepx , nis_design , na.rm = TRUE )`

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

```
# SRS without replacement
svymean( ~ p_nuhepx , nis_design , na.rm = TRUE , deff = TRUE )
# SRS with replacement
svymean( ~ p_nuhepx , nis_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( ~ dtap_3p , nis_design ,
method = "likelihood" )
```

### Regression Models and Tests of Association

Perform a design-based t-test:

`svyttest( p_nuhepx ~ dtap_3p , nis_design )`

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

```
svychisq(
~ dtap_3p + sex ,
nis_design
)
```

Perform a survey-weighted generalized linear model:

```
glm_result <-
svyglm(
p_nuhepx ~ dtap_3p + sex ,
nis_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 NIS users, this code replicates previously-presented examples:

```
library(srvyr)
nis_srvyr_design <- as_survey( nis_design )
```

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

```
nis_srvyr_design %>%
summarize( mean = survey_mean( p_nuhepx , na.rm = TRUE ) )
nis_srvyr_design %>%
group_by( state_name ) %>%
summarize( mean = survey_mean( p_nuhepx , na.rm = TRUE ) )
```