-
Notifications
You must be signed in to change notification settings - Fork 449
/
nis.Rmd
383 lines (268 loc) · 10.8 KB
/
nis.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# National Immunization Survey (NIS) {-}
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) <a href="https://github.com/asdfree/nis/actions"><img src="https://github.com/asdfree/nis/actions/workflows/r.yml/badge.svg" alt="Github Actions Badge"></a>
The vaccination coverage rate tracker for national, state, and selected local areas.
* 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 annually since 1995, plus an adolescent (13-17 years) sample since 2008.
* Administered by the [Centers for Disease Control and Prevention](http://www.cdc.gov/).
---
## Recommended Reading {-}
Four Example Strengths & Limitations:
✔️ [Both parents and medical providers interviewed](https://www.cdc.gov/nis/media/pdfs/2024/09/NIS_Child_IHQ_ENG_508_2024Q3.pdf)
✔️ [Detailed health insurance questions](https://www.cdc.gov/nis/media/pdfs/2024/11/NISChildQuestionnaireQ42024_508.pdf#page=80)
❌ [Low household response rates and only half-completed provider data during 2019-2023](https://doi.org/10.15585/mmwr.mm7338a3)
❌ [Although national estimates are precise, estimates for state and local areas should be interpreted with caution because their sample sizes are smaller, confidence intervals wider than national estimates](https://www.cdc.gov/nis/media/pdfs/2024/11/NISTEENPUF23DUG.pdf#page=82)
<br>
Three Example Findings:
1. [In 2014 in the general population in Ohio, vaccination coverage with at least one dose or at least two doses of MMR among young children and adolescents was 96% and 88%, respectively](https://doi.org/10.1056/nejmoa1602295).
2. [Completion of a 7-vaccine series by 19 months of age increased from 52% in 2011 to 59% in 2021](https://doi.org/10.1001/jamanetworkopen.2024.6440).
3. [HPV vaccination initiation by age 13 rose from 27% to 70% among those born in 1999 versus 2009](https://doi.org/10.1016/j.vaccine.2024.126560).
<br>
Two Methodology Documents:
> [About NIS](https://www.cdc.gov/nis/about/)
> [National Immunization Survey-Child: A User's Guide for the 2023 Public-Use Data File](https://www.cdc.gov/nis/media/pdfs/2024/11/NISPUF23DUG.pdf)
<br>
One Haiku:
```{r}
# i hear babies cry
# protesting lungs of iron
# a wonderful world
```
---
## Download, Import, Preparation {-}
Download the 2023 fixed-width file:
```{r eval = FALSE , results = "hide" }
dat_tf <- tempfile()
dat_url <- "https://www.cdc.gov/nis/media/files/2024/11/NISPUF23.DAT"
download.file( dat_url , dat_tf , mode = 'wb' )
```
Edit then execute the import script provided by the CDC:
```{r eval = FALSE , results = "hide" }
library(Hmisc)
r_tf <- tempfile()
r_script_url <- "https://ftp.cdc.gov/pub/Vaccines_NIS/NISPUF23.R"
r_input_lines <- readLines( r_script_url )
# do not let the script do the save()
r_input_lines <- gsub( "^save\\(" , "# save(" , r_input_lines )
# redirect the path to the flat file to the local save location of `dat_tf`
r_input_lines <- gsub( '\\"path\\-to\\-file\\/(.*)\\.DAT\\"' , "dat_tf" , r_input_lines )
# save the edited script locally
writeLines( r_input_lines , r_tf )
# run the edited script
source( r_tf , echo = TRUE )
# rename the resultant data.frame object
nis_df <- NISPUF23
names( nis_df ) <- tolower( names( nis_df ) )
nis_df[ , 'one' ] <- 1
```
### Save Locally \ {-}
Save the object at any point:
```{r eval = FALSE , results = "hide" }
# nis_fn <- file.path( path.expand( "~" ) , "NIS" , "this_file.rds" )
# saveRDS( nis_df , file = nis_fn , compress = FALSE )
```
Load the same object:
```{r eval = FALSE , results = "hide" }
# nis_df <- readRDS( nis_fn )
```
### Survey Design Definition {-}
Construct a complex sample survey design:
```{r eval = FALSE , results = "hide" }
library(survey)
options( survey.lonely.psu = "adjust" )
nis_design <-
svydesign(
id = ~ seqnumhh ,
strata = ~ stratum ,
weights = ~ provwt_c ,
data = subset( nis_df , provwt_c > 0 )
)
```
### Variable Recoding {-}
Add new columns to the data set:
```{r eval = FALSE , results = "hide" }
nis_design <-
update(
nis_design ,
first_fed_formula =
ifelse( bf_formr20 %in% 888 , NA , bf_formr20 ) ,
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 )
)
)
```
---
## Analysis Examples with the `survey` library \ {-}
### Unweighted Counts {-}
Count the unweighted number of records in the survey sample, overall and by groups:
```{r eval = FALSE , results = "hide" }
sum( weights( nis_design , "sampling" ) != 0 )
svyby( ~ one , ~ state , nis_design , unwtd.count )
```
### Weighted Counts {-}
Count the weighted size of the generalizable population, overall and by groups:
```{r eval = FALSE , results = "hide" }
svytotal( ~ one , nis_design )
svyby( ~ one , ~ state , nis_design , svytotal )
```
### Descriptive Statistics {-}
Calculate the mean (average) of a linear variable, overall and by groups:
```{r eval = FALSE , results = "hide" }
svymean( ~ first_fed_formula , nis_design , na.rm = TRUE )
svyby( ~ first_fed_formula , ~ state , nis_design , svymean , na.rm = TRUE )
```
Calculate the distribution of a categorical variable, overall and by groups:
```{r eval = FALSE , results = "hide" }
svymean( ~ sex , nis_design , na.rm = TRUE )
svyby( ~ sex , ~ state , nis_design , svymean , na.rm = TRUE )
```
Calculate the sum of a linear variable, overall and by groups:
```{r eval = FALSE , results = "hide" }
svytotal( ~ first_fed_formula , nis_design , na.rm = TRUE )
svyby( ~ first_fed_formula , ~ state , nis_design , svytotal , na.rm = TRUE )
```
Calculate the weighted sum of a categorical variable, overall and by groups:
```{r eval = FALSE , results = "hide" }
svytotal( ~ sex , nis_design , na.rm = TRUE )
svyby( ~ sex , ~ state , nis_design , svytotal , na.rm = TRUE )
```
Calculate the median (50th percentile) of a linear variable, overall and by groups:
```{r eval = FALSE , results = "hide" }
svyquantile( ~ first_fed_formula , nis_design , 0.5 , na.rm = TRUE )
svyby(
~ first_fed_formula ,
~ state ,
nis_design ,
svyquantile ,
0.5 ,
ci = TRUE , na.rm = TRUE
)
```
Estimate a ratio:
```{r eval = FALSE , results = "hide" }
svyratio(
numerator = ~ bf_exclr06 ,
denominator = ~ bf_endr06 ,
nis_design ,
na.rm = TRUE
)
```
### Subsetting {-}
Restrict the survey design to toddlers up to date on polio shots:
```{r eval = FALSE , results = "hide" }
sub_nis_design <- subset( nis_design , p_utdpol == 1 )
```
Calculate the mean (average) of this subset:
```{r eval = FALSE , results = "hide" }
svymean( ~ first_fed_formula , 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:
```{r eval = FALSE , results = "hide" }
this_result <- svymean( ~ first_fed_formula , nis_design , na.rm = TRUE )
coef( this_result )
SE( this_result )
confint( this_result )
cv( this_result )
grouped_result <-
svyby(
~ first_fed_formula ,
~ state ,
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:
```{r eval = FALSE , results = "hide" }
degf( nis_design )
```
Calculate the complex sample survey-adjusted variance of any statistic:
```{r eval = FALSE , results = "hide" }
svyvar( ~ first_fed_formula , nis_design , na.rm = TRUE )
```
Include the complex sample design effect in the result for a specific statistic:
```{r eval = FALSE , results = "hide" }
# SRS without replacement
svymean( ~ first_fed_formula , nis_design , na.rm = TRUE , deff = TRUE )
# SRS with replacement
svymean( ~ first_fed_formula , 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:
```{r eval = FALSE , results = "hide" }
svyciprop( ~ dtap_3p , nis_design ,
method = "likelihood" )
```
### Regression Models and Tests of Association {-}
Perform a design-based t-test:
```{r eval = FALSE , results = "hide" }
svyttest( first_fed_formula ~ dtap_3p , nis_design )
```
Perform a chi-squared test of association for survey data:
```{r eval = FALSE , results = "hide" }
svychisq(
~ dtap_3p + sex ,
nis_design
)
```
Perform a survey-weighted generalized linear model:
```{r eval = FALSE , results = "hide" }
glm_result <-
svyglm(
first_fed_formula ~ dtap_3p + sex ,
nis_design
)
summary( glm_result )
```
---
## Replication Example {-}
This example matches the statistics and standard errors from [Data User's Guide Table 4](https://www.cdc.gov/nis/media/pdfs/2024/11/NISPUF23DUG.pdf#page=36):
```{r eval = FALSE , results = "hide" }
results <-
svyby(
~ p_utd431h314_rout_s ,
~ raceethk ,
nis_design ,
svymean
)
coefficients <- results[ , "p_utd431h314_rout_sUTD" , drop = FALSE ]
standard_errors <- results[ , "se.p_utd431h314_rout_sUTD" , drop = FALSE ]
stopifnot( round( coefficients[ "HISPANIC" , ] , 3 ) == .674 )
stopifnot( round( coefficients[ "NON-HISPANIC WHITE ONLY" , ] , 3 ) == .716 )
stopifnot( round( coefficients[ "NON-HISPANIC BLACK ONLY" , ] , 3 ) == .666 )
stopifnot( round( standard_errors[ "HISPANIC" , ] , 3 ) == .017 )
stopifnot( round( standard_errors[ "NON-HISPANIC WHITE ONLY" , ] , 3 ) == .008 )
stopifnot( round( standard_errors[ "NON-HISPANIC BLACK ONLY" , ] , 3 ) == .023 )
```
---
## Analysis Examples with `srvyr` \ {-}
The R `srvyr` library calculates summary statistics from survey data, such as the mean, total or quantile using [dplyr](https://github.com/tidyverse/dplyr/)-like syntax. [srvyr](https://github.com/gergness/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](https://cran.r-project.org/web/packages/srvyr/vignettes/srvyr-vs-survey.html) details the available features. As a starting point for NIS users, this code replicates previously-presented examples:
```{r eval = FALSE , results = "hide" }
library(srvyr)
nis_srvyr_design <- as_survey( nis_design )
```
Calculate the mean (average) of a linear variable, overall and by groups:
```{r eval = FALSE , results = "hide" }
nis_srvyr_design %>%
summarize( mean = survey_mean( first_fed_formula , na.rm = TRUE ) )
nis_srvyr_design %>%
group_by( state ) %>%
summarize( mean = survey_mean( first_fed_formula , na.rm = TRUE ) )
```