-
Notifications
You must be signed in to change notification settings - Fork 449
/
nhis.Rmd
393 lines (285 loc) · 10.8 KB
/
nhis.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
382
383
384
385
386
387
388
389
390
391
# National Health Interview Survey (NHIS) {-}
[![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/nhis/actions"><img src="https://github.com/asdfree/nhis/actions/workflows/r.yml/badge.svg" alt="Github Actions Badge"></a>
America's most detailed household survey of health status and medical experience.
* One table with one row per sampled adult (18+) within each sampled household, one table with one row per sample child (when available, same family not required), multiply-imputed income tables.
* A complex sample survey designed to generalize to the U.S. civilian non-institutionalized population.
* Released annually since 1963, the most recent major re-design in 2019.
* Conducted by the [National Center for Health Statistics](https://www.cdc.gov/nchs/) at the [Centers for Disease Control](http://www.cdc.gov/).
---
## Recommended Reading {-}
Four Example Strengths & Limitations:
✔️ [PRICSSA](https://ftp.cdc.gov/pub/Health_Statistics/NCHS/Dataset_Documentation/NHIS/2022/2022-NHIS-PRICSSA-508.pdf)
✔️ [Annual and rotating core questionnaires allow trend analysis](https://www.cdc.gov/nchs/data/nhis/Sample-Questionnaire-Brochure.pdf#page=3)
❌ [High rate of missingness for family income questions](https://ftp.cdc.gov/pub/Health_Statistics/NCHS/Dataset_Documentation/NHIS/2022/NHIS2022-imputation-techdoc-508.pdf)
❌ [2019 redesign interviews only one adult and one child (if present) per household](https://ftp.cdc.gov/pub/Health_Statistics/NCHS/Survey_Questionnaires/NHIS/2022/advance-letter-2022.pdf)
<br>
Three Example Findings:
1. [In 2022, 14% of US seniors met both aerobic and muscle-strengthening physical activity guidelines](https://www.cdc.gov/nchs/data/nhsr/nhsr215.pdf).
2. [Adults living alone in 2021 reported feelings of depression more often than those living with others](https://www.cdc.gov/nchs/data/nhsr/nhsr199.pdf).
3. [Among US adults aged 18+ in 2022, 3% were categorized as having severe anxiety symptoms](https://www.ncbi.nlm.nih.gov/books/NBK609621/).
<br>
Two Methodology Documents:
> [2022 Survey Description](https://ftp.cdc.gov/pub/Health_Statistics/NCHS/Dataset_Documentation/NHIS/2022/srvydesc-508.pdf)
> [Wikipedia Entry](https://en.wikipedia.org/wiki/National_Health_Interview_Survey)
<br>
One Haiku:
```{r}
# excellent health poor
# wealth. "sup, doc?" bugs, daft bills, free
# laughs best medicine
```
---
## Function Definitions {-}
Define a function to download, unzip, and import each comma-separated value file:
```{r eval = FALSE , results = "hide" }
nhis_csv_import <-
function( this_url ){
this_tf <- tempfile()
download.file( this_url , this_tf , mode = 'wb' )
unzipped_files <- unzip( this_tf , exdir = tempdir() )
this_csv <- grep( '\\.csv$' , unzipped_files , value = TRUE )
this_df <- read.csv( this_csv )
file.remove( c( this_tf , unzipped_files ) )
names( this_df ) <- tolower( names( this_df ) )
this_df
}
```
---
## Download, Import, Preparation {-}
Download and import the sample adult interview and imputed income files:
```{r eval = FALSE , results = "hide" }
nhis_df <-
nhis_csv_import(
"https://ftp.cdc.gov/pub/Health_Statistics/NCHS/Datasets/NHIS/2021/adult21csv.zip"
)
imputed_income_df <-
nhis_csv_import(
"https://ftp.cdc.gov/pub/Health_Statistics/NCHS/Datasets/NHIS/2021/adultinc21csv.zip"
)
```
### Save Locally \ {-}
Save the object at any point:
```{r eval = FALSE , results = "hide" }
# nhis_fn <- file.path( path.expand( "~" ) , "NHIS" , "this_file.rds" )
# saveRDS( nhis_df , file = nhis_fn , compress = FALSE )
```
Load the same object:
```{r eval = FALSE , results = "hide" }
# nhis_df <- readRDS( nhis_fn )
```
### Survey Design Definition {-}
Construct a multiply-imputed, complex sample survey design:
Reshape the imputed income data.frame into a list based on the implicate number:
```{r eval = FALSE , results = "hide" }
imputed_income_list <- split( imputed_income_df , imputed_income_df[ , 'impnum_a' ] )
```
Remove overlapping columns except the merge variable:
```{r eval = FALSE , results = "hide" }
variables_to_remove <-
setdiff( intersect( names( nhis_df ) , names( imputed_income_df ) ) , 'hhx' )
nhis_df <- nhis_df[ , !( names( nhis_df ) %in% variables_to_remove ) ]
```
Merge each implicate onto the sample adult table:
```{r eval = FALSE , results = "hide" }
nhis_list <-
lapply( imputed_income_list ,
function( w ){
this_df <- merge( nhis_df , w )
stopifnot( nrow( this_df ) == nrow( nhis_df ) )
this_df
} )
```
Define the design:
```{r eval = FALSE , results = "hide" }
library(survey)
library(mitools)
nhis_design <-
svydesign(
id = ~ ppsu ,
strata = ~ pstrat ,
nest = TRUE ,
weights = ~ wtfa_a ,
data = imputationList( nhis_list )
)
```
### Variable Recoding {-}
Add new columns to the data set:
```{r eval = FALSE , results = "hide" }
nhis_design <-
update(
nhis_design ,
one = 1 ,
poverty_category =
factor(
findInterval( povrattc_a , c( 1 , 2 , 4 ) ) ,
labels =
c( "below poverty" , "100-199%" , "200-399%" , "400%+" )
) ,
fair_or_poor_reported_health =
ifelse( phstat_a %in% 1:5 , as.numeric( phstat_a >= 4 ) , NA ) ,
sex_a = factor( sex_a , levels = 1:2 , labels = c( "male" , "female" ) ) ,
annual_premium_first_plan = ifelse( hicostr1_a > 40000 , NA , hicostr1_a )
)
```
---
## 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" }
MIcombine( with( nhis_design , svyby( ~ one , ~ one , unwtd.count ) ) )
MIcombine( with( nhis_design , svyby( ~ one , ~ poverty_category , unwtd.count ) ) )
```
### Weighted Counts {-}
Count the weighted size of the generalizable population, overall and by groups:
```{r eval = FALSE , results = "hide" }
MIcombine( with( nhis_design , svytotal( ~ one ) ) )
MIcombine( with( nhis_design ,
svyby( ~ one , ~ poverty_category , svytotal )
) )
```
### Descriptive Statistics {-}
Calculate the mean (average) of a linear variable, overall and by groups:
```{r eval = FALSE , results = "hide" }
MIcombine( with( nhis_design , svymean( ~ agep_a ) ) )
MIcombine( with( nhis_design ,
svyby( ~ agep_a , ~ poverty_category , svymean )
) )
```
Calculate the distribution of a categorical variable, overall and by groups:
```{r eval = FALSE , results = "hide" }
MIcombine( with( nhis_design , svymean( ~ sex_a ) ) )
MIcombine( with( nhis_design ,
svyby( ~ sex_a , ~ poverty_category , svymean )
) )
```
Calculate the sum of a linear variable, overall and by groups:
```{r eval = FALSE , results = "hide" }
MIcombine( with( nhis_design , svytotal( ~ agep_a ) ) )
MIcombine( with( nhis_design ,
svyby( ~ agep_a , ~ poverty_category , svytotal )
) )
```
Calculate the weighted sum of a categorical variable, overall and by groups:
```{r eval = FALSE , results = "hide" }
MIcombine( with( nhis_design , svytotal( ~ sex_a ) ) )
MIcombine( with( nhis_design ,
svyby( ~ sex_a , ~ poverty_category , svytotal )
) )
```
Calculate the median (50th percentile) of a linear variable, overall and by groups:
```{r eval = FALSE , results = "hide" }
MIcombine( with( nhis_design ,
svyquantile(
~ agep_a ,
0.5 , se = TRUE
) ) )
MIcombine( with( nhis_design ,
svyby(
~ agep_a , ~ poverty_category , svyquantile ,
0.5 , se = TRUE ,
ci = TRUE
) ) )
```
Estimate a ratio:
```{r eval = FALSE , results = "hide" }
MIcombine( with( nhis_design ,
svyratio( numerator = ~ annual_premium_first_plan , denominator = ~ agep_a , na.rm = TRUE )
) )
```
### Subsetting {-}
Restrict the survey design to uninsured:
```{r eval = FALSE , results = "hide" }
sub_nhis_design <- subset( nhis_design , notcov_a == 1 )
```
Calculate the mean (average) of this subset:
```{r eval = FALSE , results = "hide" }
MIcombine( with( sub_nhis_design , svymean( ~ agep_a ) ) )
```
### 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 <-
MIcombine( with( nhis_design ,
svymean( ~ agep_a )
) )
coef( this_result )
SE( this_result )
confint( this_result )
cv( this_result )
grouped_result <-
MIcombine( with( nhis_design ,
svyby( ~ agep_a , ~ poverty_category , svymean )
) )
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( nhis_design$designs[[1]] )
```
Calculate the complex sample survey-adjusted variance of any statistic:
```{r eval = FALSE , results = "hide" }
MIcombine( with( nhis_design , svyvar( ~ agep_a ) ) )
```
Include the complex sample design effect in the result for a specific statistic:
```{r eval = FALSE , results = "hide" }
# SRS without replacement
MIcombine( with( nhis_design ,
svymean( ~ agep_a , deff = TRUE )
) )
# SRS with replacement
MIcombine( with( nhis_design ,
svymean( ~ agep_a , 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" }
# MIsvyciprop( ~ fair_or_poor_reported_health , nhis_design ,
# method = "likelihood" , na.rm = TRUE )
```
### Regression Models and Tests of Association {-}
Perform a design-based t-test:
```{r eval = FALSE , results = "hide" }
# MIsvyttest( agep_a ~ fair_or_poor_reported_health , nhis_design )
```
Perform a chi-squared test of association for survey data:
```{r eval = FALSE , results = "hide" }
# MIsvychisq( ~ fair_or_poor_reported_health + sex_a , nhis_design )
```
Perform a survey-weighted generalized linear model:
```{r eval = FALSE , results = "hide" }
glm_result <-
MIcombine( with( nhis_design ,
svyglm( agep_a ~ fair_or_poor_reported_health + sex_a )
) )
summary( glm_result )
```
---
## Replication Example {-}
This example matches statistics and standard errors within 0.01% from [Figure 3](https://www.cdc.gov/nchs/data/databriefs/db470-tables.pdf#3) of this [Characteristics of Adults Aged 18–64 Who Did Not Take Medication as Prescribed to Reduce Costs](https://www.cdc.gov/nchs/products/databriefs/db470.htm) Data Brief:
```{r eval = FALSE , results = "hide" }
results <-
MIcombine(
with(
subset( nhis_design , agep_a < 65 ) ,
svyby(
~ as.numeric( rxsk12m_a == 1 | rxls12m_a == 1 | rxdl12m_a == 1 ) ,
~ poverty_category ,
svymean ,
na.rm = TRUE
)
)
)
stopifnot(
all(
as.numeric( round( coef( results ) , 3 ) ) == c( 0.145 , 0.138 , 0.099 , 0.039 )
)
)
stopifnot(
all(
as.numeric( round( SE( results ) , 5 ) ) - c( 0.0126 , 0.0098 , 0.0062 , 0.0031 ) < 0.0001
)
)
```