Methods guide
How to use NHANES survey weights in R
NHANES is a complex, multistage probability sample, so an honest analysis uses the survey weights and the design variables. This guide shows how to pick the weight, combine cycles and set up the design in R with the survey package, following the NCHS tutorials and guidelines.
Updated
What NHANES is
The National Health and Nutrition Examination Survey (NHANES) is run by the National Center for Health Statistics (NCHS). It combines interviews about health, diet, and personal, social and economic characteristics with visits to a mobile exam center (MEC) for dental exams and health and body measurements. NCHS has run it without interruption since 1999, which it calls continuous NHANES, and about 5,000 adults and children take part each year (NCHS, 2024).
Public data are released in two-year cycles. Participants are chosen with a complex, multistage probability design (counties, then segments, households and individuals) meant to represent the civilian, noninstitutionalized population of the United States. Some groups of public health interest are sampled in larger numbers on purpose: for example, the oversample of non-Hispanic Asian persons began in 2011-2012, while the August 2021-August 2023 cycle had no oversampling by race and Hispanic origin (NCHS, n.d.-d).
Why the survey weights matter
Each NHANES weight accounts for the design, including the oversampling, for survey nonresponse and for post-stratification to match total population counts. Weighted, the sample represents the U.S. civilian noninstitutionalized population; unweighted, it does not. Non-Hispanic Black persons, for example, make up 21.4% of the unweighted sample but 11.9% of the weighted sample (NCHS, n.d.-f).
| Group | Weighted estimate | Unweighted estimate |
|---|---|---|
| Adults aged 18 and over | 32.1% | 35.9% |
| Hispanic adults aged 18 and over | 23.1% | 33.4% |
The unweighted figure for all adults is 3.8 percentage points too high, and for Hispanic adults it is more than 10 points too high. NCHS's guidelines say analyses "should use appropriate survey weights and specify which weights were used", and that unweighted analyses, or treating NHANES as a convenience sample, are generally not recommended because the results do not generalize to the U.S. population (NCHS, 2026).
Choosing the right weight
NHANES has several weights because not everyone completes every part of the survey. The rule from the NCHS weighting tutorial: "You must use the weight of the smallest subpopulation that includes all the variables you want to include in your analysis." Check where each of your variables was collected, and use the weight for the one collected from the fewest people (NCHS, n.d.-f).
| Weight | Variable | Use it when |
|---|---|---|
| Interview | WTINT2YR (WTINT4YR for 1999-2002) | Every variable comes from the household interview. |
| MEC exam | WTMEC2YR (WTMEC4YR for 1999-2002) | Any variable comes from the MEC exam, including questionnaires given during the MEC session. |
| Subsample | For example, fasting WTSAF2YR (WTSAF4YR), dietary day one WTDRD1, dietary two-day WTDR2D | Any variable comes from a subsample. These weights are on that component's data file. |
The tutorial's own examples: an analysis of race and Hispanic origin, poverty and a previous diabetes diagnosis, all from the interview, uses the interview weight. Add high blood pressure from the MEC and it needs the MEC exam weight. Add fasting triglycerides from the morning fasting subsample and it needs the fasting subsample weight (NCHS, n.d.-f). Read each data file's documentation too: NCHS's sample code uses the MEC weight for the depression screener because that file's analytic notes say to (NCHS, n.d.-a).
Subpopulation analysis needs every observation with a non-zero value for the weight you use, so keep all of those records (NCHS, n.d.-e). In R, svydesign() does not accept missing values in the design variables, weights included (Lumley, n.d.-b).
Combining NHANES cycles
To pool cycles from 2001-2002 onward, NCHS says new multi-year weights can be computed by dividing the two-year weights by the number of two-year cycles pooled. If 1999-2000 is in the pool, start from the four-year weights NCHS provides for 1999-2002 (such as WTMEC4YR) and add the two-year weights for the other cycles. The cycle is identified by SDDSRVYR (1 = 1999-2000, 2 = 2001-2002, and so on) (NCHS, n.d.-f).
| Years pooled | Combined weight |
|---|---|
| 2001-2004 | 1/2 x WTMEC2YR |
| 2001-2006 | 1/3 x WTMEC2YR |
| 2001-2010 | 1/5 x WTMEC2YR |
| 1999-2004 | 2/3 x WTMEC4YR for 1999-2002; 1/3 x WTMEC2YR for 2003-2004 |
| 2015-March 2020 | 2/5.2 x WTMEC2YR for 2015-2016; 3.2/5.2 x WTMECPRP for 2017-March 2020 |
In each formula, a weight is multiplied by the share of the pooled period that its file covers. In R:
# pooled: the stacked DEMO files for the cycles, which include SDDSRVYR.
# 2001-2002 onward: divide each 2-year weight by the number of 2-year cycles pooled.
# Example: three cycles, 2005-2006 to 2009-2010 (SDDSRVYR 4, 5 and 6).
pooled$WTMEC6YR <- pooled$WTMEC2YR / 3
# Pooling 1999-2000: start from the 4-year weight NCHS provides for 1999-2002
# (SDDSRVYR 1 and 2). Example: 1999-2004, the NCHS formula for six years.
pooled$WTMEC6YR <- ifelse(pooled$SDDSRVYR %in% c(1, 2),
2/3 * pooled$WTMEC4YR, # 1999-2002
1/3 * pooled$WTMEC2YR) # 2003-2004NCHS generally does not recommend combining the August 2021-August 2023 cycle with other cycles, given the 1.5-year gap after the 2017-March 2020 cycle and the disruptions to health care, employment and education during the COVID-19 pandemic (NCHS, n.d.-f). When you pool years, also check whether laboratory methods changed over the period: where NCHS found an effect from an equipment change, it published bridging equations in the documentation (NCHS, 2026).
The design variables: SDMVPSU and SDMVSTRA
The true NHANES strata and primary sampling units (PSUs) are not released, to protect participants. Instead, each cycle's demographic file carries masked variance units: the stratum SDMVSTRA and the PSU SDMVPSU. NCHS says they should be used for all analyses of the public data, and that they give variances close to those of the true design. NCHS recommends Taylor series linearization for variance estimation (NCHS, n.d.-e).
Leaving the design variables out overstates precision, which can make subgroup differences look significant when they are not (NCHS, 2026). In R, nest = TRUE is required: "The nest=TRUE option must be used for continuous NHANES data", because a unique PSU is identified by the combination of the stratum and PSU variables (NCHS, n.d.-e). With nest = TRUE, svydesign() relabels cluster ids so they nest within strata (Lumley, n.d.-b).
The design's degrees of freedom are the number of PSUs minus the number of strata. Most two-year public releases have 15 (30 PSUs minus 15 strata). For a subgroup, count only the PSUs and strata that contain its observations; many packages do not make this correction, so check how yours computes it (NCHS, n.d.-e; NCHS, 2018).
A complete svydesign example in R
This example follows NCHS's own R code for its data brief on depression in adults, 2013-2016 (NCHS, n.d.-a): it reads two cycles, pools the MEC weight, defines the design on every record and then takes the analysis population from the design. It needs the survey package and foreign, which ships with R.
library(survey)
# NCHS's own sample code sets this option for strata left with a single PSU.
options(survey.lonely.psu = "adjust")
# Download one SAS transport (.xpt) file from the NHANES site and read it.
read_nhanes <- function(url) {
file <- tempfile(fileext = ".xpt")
download.file(url, file, mode = "wb")
foreign::read.xport(file)
}
site <- "https://wwwn.cdc.gov/Nchs/Data/Nhanes/Public"
keep <- c("SEQN", "RIAGENDR", "RIDAGEYR", "SDMVSTRA", "SDMVPSU", "WTMEC2YR")
items <- sprintf("DPQ0%d0", 1:9) # DPQ010 to DPQ090, the nine screener items
# Two cycles: 2013-2014 (H files) and 2015-2016 (I files).
demo <- rbind(read_nhanes(paste0(site, "/2013/DataFiles/DEMO_H.XPT"))[keep],
read_nhanes(paste0(site, "/2015/DataFiles/DEMO_I.xpt"))[keep])
dpq <- rbind(read_nhanes(paste0(site, "/2013/DataFiles/DPQ_H.xpt"))[c("SEQN", items)],
read_nhanes(paste0(site, "/2015/DataFiles/DPQ_I.xpt"))[c("SEQN", items)])
# Keep every demographic record, so the design keeps every PSU and stratum.
nhanes <- merge(demo, dpq, by = "SEQN", all.x = TRUE)
# Codes 7 (refused) and 9 (don't know) become missing, as in NCHS's code.
nhanes[items] <- lapply(nhanes[items], function(x) ifelse(x >= 7, NA, x))
nhanes$score <- rowSums(nhanes[items])
nhanes$depression <- as.numeric(nhanes$score >= 10)
nhanes$sex <- factor(nhanes$RIAGENDR, levels = 1:2, labels = c("Men", "Women"))
nhanes$age_group <- cut(nhanes$RIDAGEYR, breaks = c(19, 39, 59, Inf),
labels = c("20-39", "40-59", "60 and over"))
# The depression screener uses the MEC exam weight. Two cycles pooled: divide by 2.
nhanes$weight_2013_2016 <- nhanes$WTMEC2YR / 2
# The analysis population: adults aged 20 and over with a valid score.
nhanes$in_analysis <- nhanes$RIDAGEYR >= 20 & !is.na(nhanes$score)
# Define the design on the full file, then take the subpopulation from the design.
design <- svydesign(ids = ~SDMVPSU, strata = ~SDMVSTRA, weights = ~weight_2013_2016,
nest = TRUE, data = nhanes)
adults <- subset(design, in_analysis)
svymean(~depression, adults) # weighted proportion and its SE
svyciprop(~depression, adults, method = "beta") # Korn-Graubard type interval
svyby(~depression, ~sex, adults, svymean) # by sex
degf(adults) # design degrees of freedomNCHS's sample code was written for R 3.5.2 and survey 3.35.1 (NCHS, n.d.-c), so check the documentation for the versions you run.
Subpopulation analysis: subset the design, not the data
Never drop records before running the analysis. In a subgroup, the number of people in each PSU is itself random. If you delete everyone else first, the variance formula treats that number as fixed and understates the variability. Read in the full file, keep an indicator for the subgroup and use your software's subpopulation feature: in R, call subset() on the survey design object, not on the data frame (NCHS, n.d.-e).
# Wrong: dropping rows before the design is defined. The software then treats the
# subgroup's size in each PSU as fixed, and the standard errors come out too small.
wrong <- svydesign(ids = ~SDMVPSU, strata = ~SDMVSTRA, weights = ~weight_2013_2016,
nest = TRUE, data = nhanes[nhanes$in_analysis, ])
# Right: keep the full file in the design and subset the design object.
women <- subset(adults, sex == "Women")
svymean(~depression, women)Regression with svyglm
svyglm() fits a model to the design object, so a subpopulation is handled the same way. For a binary outcome, the survey documentation recommends family = quasibinomial(), which gives the same estimates and standard errors as binomial() without a warning about non-integer counts. By default the residual degrees of freedom are worked out from degf(), the design's degrees of freedom. The documentation notes that this follows Korn and Graubard, is correct for PSU-level covariates and can be very conservative for individual-level ones (Lumley, n.d.-c).
fit <- svyglm(depression ~ sex + age_group, design = adults, family = quasibinomial())
summary(fit)
exp(coef(fit)) # odds ratiosMultiple testing
NHANES makes it easy to test many outcomes and subgroups, and each extra test raises the chance that something looks significant by chance alone. The NCHS pages cited here do not set a rule for adjusting for multiple comparisons, so this part is general practice rather than NCHS guidance: report how many tests you ran, and if you adjust, say which method.
In R, p.adjust() takes a vector of p-values. Its documentation notes that Holm's method dominates the unmodified Bonferroni correction, and that the "BH" method controls the false discovery rate (R Core Team, n.d.).
# Three pairwise age-group comparisons among adults, in the style of NCHS's sample code.
pairs <- list(c("20-39", "40-59"), c("20-39", "60 and over"), c("40-59", "60 and over"))
p <- sapply(pairs, function(groups)
svyttest(depression ~ age_group, subset(adults, age_group %in% groups))$p.value)
p.adjust(p, method = "holm")Is the estimate reliable enough to report?
NCHS flags a mean as unreliable when its relative standard error is 30% or more (NCHS, n.d.-b; NCHS, 2018). For proportions it applies the NCHS Data Presentation Standards: suppress an estimate based on fewer than 30 people or an effective sample size under 30, judge the Korn-Graubard confidence interval by its absolute and relative width, and flag estimates with fewer than 8 degrees of freedom for statistical review (NCHS, n.d.-b; Parker et al., 2017). In R, svyciprop() with method = "beta" computes an interval based on Korn and Graubard's method (Lumley, n.d.-a).
Do not estimate the number of people with a condition by summing the weights of those who have it. Exclusions and missing data make that sum an underestimate (NCHS, 2026; NCHS, n.d.-f).
Checklist before you submit
These points follow the NCHS guidelines for high quality analyses, which journal editors and reviewers are asked to look for (NCHS, 2026), with the details from the NCHS tutorials above.
- Read the documentation for every data file you use, including its weights, design variables, skip patterns and analytic notes, and follow the analytic guidance for each cycle.
- Use the weight of the smallest subsample that holds all your variables, and name that weight in your methods.
- When you pool cycles, build the combined weight as NCHS describes. NCHS generally does not recommend pooling August 2021-August 2023 with other cycles.
- Define the design on the full file with
SDMVPSU,SDMVSTRA, the weight andnest = TRUE. - Take subpopulations from the design object with subset(), never by dropping rows first.
- Account for skip patterns: state which questions you used and how you defined each denominator, and check that sample sizes and estimates are plausible.
- For laboratory trends, document whether methods stayed the same, and apply the bridging equations NCHS publishes where they exist.
- Check each estimate against the NCHS reliability standards before you report it.
- Do not sum weights to estimate how many people have a condition.
Does Corvid analyze NHANES?
Not yet. Corvid is an AI research agent for health research, and today its analyses use CDC PLACES county health data, with literature from PubMed. NHANES support is planned, and we have not set a date. The rules on this page are the ones that support has to follow. To hear when it is ready, join the waitlist, or read how Corvid works.
This guide covers R only. We have not checked a Python library for NHANES variance estimation to the same standard, so we leave Python out rather than guess.
References
- Lumley, T. (n.d.-a). svyciprop: Confidence intervals for proportions. survey package reference manual, CRAN. https://search.r-project.org/CRAN/refmans/survey/html/svyciprop.html
- Lumley, T. (n.d.-b). svydesign: Survey sample analysis. survey package reference manual, CRAN. https://search.r-project.org/CRAN/refmans/survey/html/svydesign.html
- Lumley, T. (n.d.-c). svyglm: Survey-weighted generalised linear models. survey package reference manual, CRAN. https://search.r-project.org/CRAN/refmans/survey/html/svyglm.html
- National Center for Health Statistics. (2018, December 14). National Health and Nutrition Examination Survey: Analytic guidelines, 2011-2014 and 2015-2016. Centers for Disease Control and Prevention. https://wwwn.cdc.gov/Nchs/data/nhanes/analyticguidelines/11-16-analytic-guidelines.pdf
- National Center for Health Statistics. (2024). About NHANES. Centers for Disease Control and Prevention. https://www.cdc.gov/nchs/nhanes/about/index.html
- National Center for Health Statistics. (2026, January 26). Guidelines for high quality analyses of NHANES data. Centers for Disease Control and Prevention. https://wwwn.cdc.gov/nchs/nhanes/QualityAnalysesGuidelines.aspx
- National Center for Health Statistics. (n.d.-a). Example R code to replicate NCHS Data Brief No. 303 [R script]. Centers for Disease Control and Prevention. https://wwwn.cdc.gov/nchs/data/Tutorials/Code/DB303_R.r
- National Center for Health Statistics. (n.d.-b). NHANES tutorials: Reliability of estimates module. Centers for Disease Control and Prevention. https://wwwn.cdc.gov/nchs/nhanes/tutorials/ReliabilityOfEstimates.aspx
- National Center for Health Statistics. (n.d.-c). NHANES tutorials: Sample code module. Centers for Disease Control and Prevention. https://wwwn.cdc.gov/nchs/nhanes/tutorials/SampleCode.aspx
- National Center for Health Statistics. (n.d.-d). NHANES tutorials: Sample design module. Centers for Disease Control and Prevention. https://wwwn.cdc.gov/nchs/nhanes/tutorials/sampledesign.aspx
- National Center for Health Statistics. (n.d.-e). NHANES tutorials: Variance estimation module. Centers for Disease Control and Prevention. https://wwwn.cdc.gov/nchs/nhanes/tutorials/VarianceEstimation.aspx
- National Center for Health Statistics. (n.d.-f). NHANES tutorials: Weighting module. Centers for Disease Control and Prevention. https://wwwn.cdc.gov/nchs/nhanes/tutorials/weighting.aspx
- Parker, J. D., Talih, M., Malec, D. J., et al. (2017). National Center for Health Statistics data presentation standards for proportions (Vital and Health Statistics, Series 2, No. 175). National Center for Health Statistics. https://www.cdc.gov/nchs/data/series/sr_02/sr02_175.pdf
- R Core Team. (n.d.). p.adjust: Adjust p-values for multiple comparisons. R stats package reference manual. https://search.r-project.org/R/refmans/stats/html/p.adjust.html