# Lab 5: Survey Data Analysis

## Overview

This lab introduces the essential principles of **survey data analysis**. Public health
data often comes from complex surveys like NHANES, which don't sample people randomly —
they use a strategic design with **weights, strata, and clusters** so the sample
represents the entire U.S. population. Ignoring these features can badly bias your results.

Using data from Flegal et al. (2016), you will work through the difference between a naive
analysis and a methodologically sound survey analysis: creating a survey design object,
generating weighted descriptive statistics, and fitting survey-weighted regression models
to replicate published findings. Your TA will walk through the worked solution during the
session.

This is the workflow you will reuse in **P4** on your own locked paper.

## Materials

- **Exercise instructions:** [Survey Data Analysis](https://ehsanx.github.io/EpiMethods/surveydataE.html)
- **Worked solution:** [The R codes](https://ehsanx.github.io/EpiMethods/surveydataEsolution.html)

**Before you come to lab**, install the package this exercise needs:

```r
install.packages("survey")
```

## Your task

1. Follow along as the TA explains the worked solution.
2. Run the R Markdown file yourself, as a group, on your own laptop.
3. Put your **group name and the first names of everyone present** in the `author:`
   field at the top of the file.

4. Add `sessionInfo()` in a final code chunk.
5. 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.

## Deliverable

- **One file per group:** the knitted PDF or HTML.
- **Due:** end of the lab session (Thu Oct 15).

## Grading: Complete / Incomplete

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.

---

## Where this lab fits

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 6 — Complex survey design (weights, strata, PSU)](https://ehsanx.github.io/SPPH604-2026W/lectures/Week6_complex_survey_design.html) | Tuesday showed why a complex survey is not a simple random sample, and what weights, strata and PSUs are actually doing. This lab makes the contrast concrete: a naive unweighted fit beside a design-aware one, with the attenuation and the CI widening tabulated side by side. |
| **Slide deck** | [Week 6 deck](https://ehsanx.github.io/SPPH604-2026W/lectures/slides/Week6_survey_slides.html) | The same material as slides, with speaker notes. Press `S` for notes, `F` for fullscreen. |
| **Your increment** | [P4 — Design-aware estimate](https://ehsanx.github.io/SPPH604-2026W/practice/P4_design_aware_estimate.html) | Apply the same workflow to *your* paper’s headline estimate: declare and justify the weight you chose, report the naive-versus-weighted contrast, and write the one-line design statement your paper omitted. |
| **Worked example** | [P4 example](https://ehsanx.github.io/SPPH604-2026W/examples/P4_design_aware/P4_design_aware_submission.html) — [its code](https://ehsanx.github.io/SPPH604-2026W/examples/P4_design_aware/P4_code.html) | A completed P4: weight declared and justified, naive-versus-weighted contrast reported, and the one-line design statement written. |
| **Milestone** | [M1 — Replication and interrogation](https://ehsanx.github.io/SPPH604-2026W/milestones/M1_assignment.html) | P4 enters M1 as **Design-aware estimate**. P4 is optional and ungraded with nothing to submit; M1 is where it is assessed. |
