# Reproducing the NHANES analysis

## Contents
- research-brief.md: English interpretation and limitations.
- analysis-specification.md and specification-clarification.md: pre-estimation rules and the documented correction to the expected number of PSUs per stratum.
- nhanes-analysis.R: complete analysis, including optional official downloads when inputs are absent.
- inputs/: 24 original CDC XPT files and retained HTML documentation.
- results/: CSV data tables, dictionaries, source manifests, software session information, replay log, comparison reference and validation results.
- association-figure.png and association-figure.pdf: general-purpose 13-by-6-inch figure, PNG at 300 dpi and vector PDF. No journal-specific compliance is claimed.
- archive-manifest.json: SHA-256 checksums of every other archive member.

## Environment and execution
The analysis ran through native Notebook in the existing case6-nhanes-gcc14-final2 environment, with R 4.4.3, survey 4.4.2 and haven 2.5.5. No packages were reinstalled and the application was not modified.

Extract the archive to a new directory. Activate an R environment with those versions and make the extracted directory the working directory. In the R console or a bound native R Notebook, run:

```r
source("nhanes-analysis.R", encoding="UTF-8")
```

The script reads retained inputs first and requires no network when all 24 XPTs are present. If an input is absent it downloads the corresponding official CDC file; obtain any runtime network permissions first. Verify retained inputs against source-manifest.csv and archive-manifest.json before running. The script writes fresh results and figures in that extracted directory, so use a new copy to preserve the delivered outputs.

On Windows, direct Rscript execution requires the environment's runtime/DLL paths to be initialized. The original investigation used supported native Notebook binding instead of an uninitialized Rscript process. An exact session path is not required for reuse.

## Reproducibility check
The exact published script text was evaluated in a separate R environment inside the bound native Notebook, from retained inputs. Primary standardized estimates, odds ratios, sensitivity standardized estimates and cohort flow matched the original run (tolerance 1e-10). See results/replay-validation.csv. This is a same-runtime computational rerun, not an independent scientific replication or a native Reproduction-feature receipt.

Source XPT hashes use MD5 for identity checking, not security claims. The archive additionally supplies SHA-256 hashes. Results are deterministic; no random resampling seed is needed for the stratified delete-one-PSU jackknife.

## Main tables
- cohort-flow.csv, missingness.csv, missingness-profiles.csv: selection accounting.
- diabetes-prevalence.csv, weighted-characteristics.csv: descriptive estimates.
- odds-ratios.csv, standardized-estimates.csv: primary comparisons.
- sensitivity-odds-ratios.csv, sensitivity-standardized.csv: matched-definition checks.
- design-audit.csv, variance-check.csv, model-diagnostics.csv, cell-audit.csv: numerical checks.
- source-manifest.csv, codebook-manifest.csv, variable-dictionary.csv: provenance and measurements.

Model codes: U unweighted crude; W survey-weighted crude; D demographic/cycle adjustment; S adds education, income and smoking; B adds BMI. Model rows are cumulative. All primary models use the same 18,241 adults.

Proportions and differences in CSVs are on the 0–1 scale; multiply by 100 for percentages and percentage points. Standardized table SE_transformed is on the logit scale for prevalence and the probability-difference scale for differences. Degrees of freedom and confidence limits are supplied. S-model standardized sensitivities and W/S/B sensitivity ORs are included.

## Limits
Read the brief before interpreting estimates. The results are historical, cross-sectional associations, not causal effects or current-US prevalence. Complete-case missingness and measurement error are not fully resolved by survey weights. This package does not access or depend on earlier Case6 outputs.
