National Health Interview Survey (NHIS)
The National Health Interview Survey (NHIS) is America’s most detailed household survey of health status and medical experience.
A main table with one row for each person within each sampled household, mergeable other tables like the sample child table with a more detailed questionnaire for only one child (when available) within each sampled household.
A complex sample survey designed to generalize to the civilian non-institutionalized population of the United States.
Released annually since 1963, the most recent major re-design in 1997.
Administered by the Centers for Disease Control and Prevention.
Simplified Download and Importation
The R lodown
package easily downloads and imports all available NHIS microdata by simply specifying "nhis"
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( "nhis" , output_dir = file.path( path.expand( "~" ) , "NHIS" ) )
lodown
also provides a catalog of available microdata extracts with the get_catalog()
function. After requesting the NHIS 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 NHIS microdata files
nhis_cat <-
get_catalog( "nhis" ,
output_dir = file.path( path.expand( "~" ) , "NHIS" ) )
# 2016 only
nhis_cat <- subset( nhis_cat , year == 2016 )
# download the microdata to your local computer
nhis_cat <- lodown( "nhis" , nhis_cat )
Analysis Examples with the survey
library
Construct a multiply-imputed, complex sample survey design:
options( survey.lonely.psu = "adjust" )
library(survey)
library(mitools)
nhis_personsx_df <-
readRDS( file.path( path.expand( "~" ) , "NHIS" , "2016/personsx.rds" ) )
nhis_income_list <-
readRDS( file.path( path.expand( "~" ) , "NHIS" , "2016/incmimp.rds" ) )
merge_variables <- c( "hhx" , "fmx" , "fpx" )
nhis_personsx_df[ merge_variables ] <-
sapply( nhis_personsx_df[ merge_variables ] , as.numeric )
inc_vars_to_keep <-
c(
merge_variables ,
setdiff(
names( nhis_income_list[[ 1 ]] ) ,
names( nhis_personsx_df )
)
)
# personsx variables to keep
vars_to_keep <-
c( merge_variables , "ppsu" , "pstrat" , "wtfa" ,
'phstat' , 'sex' , 'hospno' , 'age_p' , 'hinotmyr' , 'notcov' )
nhis_personsx_df <- nhis_personsx_df[ vars_to_keep ]
nhis_personsx_list <-
lapply( nhis_income_list ,
function( w ){
w <- w[ inc_vars_to_keep ]
w[ merge_variables ] <- sapply( w[ merge_variables ] , as.numeric )
result <- merge( nhis_personsx_df , w )
stopifnot( nrow( result ) == nrow( nhis_personsx_df ) )
result
} )
# personsx design
nhis_design <-
svydesign(
id = ~ppsu ,
strata = ~pstrat ,
nest = TRUE ,
weights = ~wtfa ,
data = imputationList( nhis_personsx_list )
)
rm( nhis_personsx_list ) ; gc()
nhis_samadult_df <-
readRDS( file.path( path.expand( "~" ) , "NHIS" , "2016/samadult.rds" ) )
nhis_samadult_df[ merge_variables ] <-
sapply( nhis_samadult_df[ merge_variables ] , as.numeric )
samadult_vars_to_keep <-
c(
merge_variables ,
setdiff(
names( nhis_samadult_df ) ,
names( nhis_personsx_df )
)
)
nhis_personsx_samadult_df <-
merge( nhis_personsx_df , nhis_samadult_df[ samadult_vars_to_keep ] )
stopifnot( nrow( nhis_personsx_samadult_df ) == nrow( nhis_samadult_df ) )
rm( nhis_personsx_df , nhis_samadult_df ) ; gc()
nhis_samadult_list <-
lapply( nhis_income_list ,
function( w ){
w <- w[ inc_vars_to_keep ]
w[ merge_variables ] <- sapply( w[ merge_variables ] , as.numeric )
result <- merge( nhis_personsx_samadult_df , w )
stopifnot( nrow( result ) == nrow( nhis_personsx_samadult_df ) )
result
} )
rm( nhis_income_list , nhis_personsx_samadult_df ) ; gc()
# sample adult design (commented out)
# nhis_samadult_design <-
# svydesign(
# id = ~ppsu ,
# strata = ~pstrat ,
# nest = TRUE ,
# weights = ~wtfa_sa ,
# data = imputationList( nhis_samadult_list )
# )
rm( nhis_samadult_list ) ; gc()
Variable Recoding
Add new columns to the data set:
nhis_design <-
update(
nhis_design ,
one = 1 ,
poverty_category =
factor(
findInterval( povrati3 , 1:4 ) ,
labels =
c( "below poverty" , "100-199%" , "200-299%" , "300-399%" , "400%+" )
) ,
fair_or_poor_reported_health =
ifelse( phstat %in% 1:5 , as.numeric( phstat >= 4 ) , NA ) ,
sex = factor( sex , labels = c( "male" , "female" ) ) ,
hospno = ifelse( hospno > 366 , NA , hospno )
)
Unweighted Counts
Count the unweighted number of records in the survey sample, overall and by groups:
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:
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:
MIcombine( with( nhis_design , svymean( ~ age_p ) ) )
MIcombine( with( nhis_design ,
svyby( ~ age_p , ~ poverty_category , svymean )
) )
Calculate the distribution of a categorical variable, overall and by groups:
MIcombine( with( nhis_design , svymean( ~ sex ) ) )
MIcombine( with( nhis_design ,
svyby( ~ sex , ~ poverty_category , svymean )
) )
Calculate the sum of a linear variable, overall and by groups:
MIcombine( with( nhis_design , svytotal( ~ age_p ) ) )
MIcombine( with( nhis_design ,
svyby( ~ age_p , ~ poverty_category , svytotal )
) )
Calculate the weighted sum of a categorical variable, overall and by groups:
MIcombine( with( nhis_design , svytotal( ~ sex ) ) )
MIcombine( with( nhis_design ,
svyby( ~ sex , ~ poverty_category , svytotal )
) )
Calculate the median (50th percentile) of a linear variable, overall and by groups:
MIcombine( with( nhis_design ,
svyquantile(
~ age_p ,
0.5 , se = TRUE
) ) )
MIcombine( with( nhis_design ,
svyby(
~ age_p , ~ poverty_category , svyquantile ,
0.5 , se = TRUE ,
keep.var = TRUE , ci = TRUE
) ) )
Estimate a ratio:
MIcombine( with( nhis_design ,
svyratio( numerator = ~ hinotmyr , denominator = ~ hospno , na.rm = TRUE )
) )
Subsetting
Restrict the survey design to uninsured:
sub_nhis_design <- subset( nhis_design , notcov == 1 )
Calculate the mean (average) of this subset:
MIcombine( with( sub_nhis_design , svymean( ~ age_p ) ) )
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 <-
MIcombine( with( nhis_design ,
svymean( ~ age_p )
) )
coef( this_result )
SE( this_result )
confint( this_result )
cv( this_result )
grouped_result <-
MIcombine( with( nhis_design ,
svyby( ~ age_p , ~ 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:
degf( nhis_design$designs[[1]] )
Calculate the complex sample survey-adjusted variance of any statistic:
MIcombine( with( nhis_design , svyvar( ~ age_p ) ) )
Include the complex sample design effect in the result for a specific statistic:
# SRS without replacement
MIcombine( with( nhis_design ,
svymean( ~ age_p , deff = TRUE )
) )
# SRS with replacement
MIcombine( with( nhis_design ,
svymean( ~ age_p , deff = "replace" )
) )
Compute confidence intervals for proportions using methods that may be more accurate near 0 and 1. See ?svyciprop
for alternatives:
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:
MIsvyttest( age_p ~ fair_or_poor_reported_health , nhis_design )
Perform a chi-squared test of association for survey data:
MIsvychisq( ~ fair_or_poor_reported_health + sex , nhis_design )
Perform a survey-weighted generalized linear model:
glm_result <-
MIcombine( with( nhis_design ,
svyglm( age_p ~ fair_or_poor_reported_health + sex )
) )
summary( glm_result )