In this lab you will learn how epidemiologists access and prepare large survey datasets in R, using NHANES as the example: importing, merging, cleaning, and summarizing. Your TA will walk through the worked solution during the session.
The goal of this lab is to get your toolchain working end to end. By the time you leave the room, you should be able to open an R Markdown file, run it, and produce a finished document.
Follow along as the TA explains the worked solution.
Run the R Markdown file yourself, as a group, on your own laptop.
Put your group name and the first names of everyone
present in the author: field at the top of the
file.
Add sessionInfo() in a final code chunk.
Knit to PDF or HTML and submit that one file before the lab ends.
No written explanations are required. If you get stuck, ask the TA in the room — that is what the session is for.
You receive Complete if the document knitted without errors, your group name and members are in it, and it was submitted before the lab ended. Only members present in the room receive credit.
This lab is one step in a weekly chain: Tuesday’s lecture sets up the method, Thursday’s lab runs it on fixed teaching data, and your increment applies it to the paper your group locked at M0.
| Document | How this lab connects | |
|---|---|---|
| This week’s lecture | Week 2 — NHANES data sources; reading Methods critically | Tuesday read the demonstration paper’s Methods section as the first
act of reproduction, and gave you the six questions to ask of any
Methods section. It also previewed this lab’s code directly —
nhanes("DEMO_H"), full_join(..., by = "SEQN"),
the cycle loop and bind_rows(). This lab runs it: several
NHANES cycles downloaded, the raw topic files read, and everything
merged on SEQN into one row per person. |
| Slide deck | Week 2 deck | The same material as slides, with speaker notes. Press
S for notes, F for fullscreen. |
| Lock your paper | M0 — Feasibility memo | Use this week’s template and the M0 criteria to shortlist two or three candidate NHANES papers of your own. You lock one at M0 in Week 3. |
| Worked example | M0 example | A completed feasibility memo, so you can see how much evidence each M0 criterion actually needs. |
| Next increment | P1 — Analytic cohort | P1 begins in Week 3, once your paper is locked, and applies L2 rather than this lab. There are six labs and five increments: L1 is the one that feeds M0 instead. |
| Milestone | M1 — Replication and interrogation | Only through the paper you lock at M0. Nothing you build today is submitted for M1. |
| Every later lab | — | L1’s merge is the substrate for the whole term. Table 1, confounding, interaction, survey weights and missing data all run on the table you build today, so a clean merge now saves you five weeks of debugging. |