8  Exercises and a descriptive statistics checklist

Let us put what we covered in the previous chapters into practice with our own hands. The code cells in this chapter are not run automatically. Fill in the blanks (___) and press “Run Code”. Example answers are collapsed below each question.

8.1 Descriptive statistics checklist

Before starting the analysis (models, tests), check at least the following. We also use this list in the exercises.

# What to check Chapter
1 What is one row (a person, a visit, a prescription)? Are there duplicate IDs? Did you align to the unit of analysis? 2
2 Did you check code values, units, and definitions in the codebook (sex codes, days vs. years, diagnostic definitions)? 2
3 Did you look at the distributions of the main variables in figures (skewness, extreme values, rounding, upper limits)? 3
4 Whose values are they (are children or people with prior disease mixed in)? 3, 6
5 Number of and reasons for missing values for each variable; structural missingness (not asked, skipped) 4
6 Did you compare those who remained in the analysis with those who were excluded? Can you report the exclusion flow? 4
7 Whom does the sample represent (sampling design, weights, participation bias)? 5
8 Did you describe the follow-up period, censoring, dropout, number of events, and person-years? 6
9 Did you make Table 1 for the groups being compared and look at imbalance by its size, e.g. the SMD? 7
10 From the descriptive results, did you write down which analyses and which interpretations need caution? All

8.2 Exercise 1: Do people taking antihypertensive drugs die earlier?

Using Framingham baseline data, examine the relationship between taking antihypertensive medication (BPMEDS) and death over 24 years.

8.2.1 1-1. First, a naive comparison

Compute the number of people and the proportion who died, by whether or not they take antihypertensive medication.

base |>
  group_by(BP_meds = BPMEDS) |>
  summarise(n = n(), pct_dead = pct(DEATH))

The proportion who died is 66.0% among the 144 people taking antihypertensive medication, and 33.6% among the 4229 not taking it. The hazard ratio is also about 2.7.

Also, there are 61 people with missing BPMEDS (NA) (proportion dead 52.5%). Note that the proportion who died is high among those with missing values as well.

8.2.2 1-2. Make Table 1

Make a table, with SMDs, comparing age, systolic blood pressure, history of hypertension (PREVHYP), diabetes, and history of coronary heart disease by whether or not people take antihypertensive medication.

base |>
  filter(!is.na(BPMEDS)) |>
  tbl_summary(by = BPMEDS, include = c(AGE, SYSBP, PREVHYP, DIABETES, PREVCHD),
              statistic = all_continuous() ~ "{mean} ({sd})") |>
  add_difference(test = everything() ~ "smd")

People taking antihypertensive medication are a population with large SMDs for every variable:

  • Mean age 56 (50 for those not taking it)
  • Mean systolic blood pressure 165 mmHg (132 for those not taking it)
  • All have hypertension (30% for those not taking it); history of coronary heart disease 13.9% (3.9% for those not taking it)

This is because the people taking the drug are people ill enough to need the drug. This is called confounding by indication. It is one of the confounders to be most careful about when studying drug effects with observational data.

8.2.3 1-3. What happens when you adjust?

Look at how the hazard ratio changes in a Cox regression adjusted for age, sex, and systolic blood pressure.

fit2 <- coxph(Surv(TIMEDTH, DEATH) ~ BPMEDS + AGE + SEX + SYSBP, data = base)

The hazard ratio falls from 2.69 to 1.29. That it is still above 1 is thought to be because a single blood pressure value cannot fully adjust for “the duration, severity, and complications of hypertension severe enough to need antihypertensive drugs” (residual confounding). From this result, you cannot say that “antihypertensive drugs increase death”. The effects of antihypertensive drugs have been studied in randomised controlled trials.

8.3 Exercise 2: The proportion of US adults with high blood pressure

Using NHANES, report “the proportion of US adults with systolic blood pressure of 140 mmHg or higher”.

8.3.1 2-1. Check the target population and missingness

Restrict to those aged 20 or over, and count the number missing systolic blood pressure (BPSysAve) and the number with an examination-centre weight (WTMEC2YR) of 0.

c(n = nrow(adults),
  BP_missing = sum(is.na(adults$BPSysAve)),
  MEC_weight_zero = sum(adults$WTMEC2YR == 0))

Of the 11778 people, 926 are missing blood pressure. Of these, 400 did not come to the examination centre (interview only), so their examination-centre weight is 0. For items measured at the examination centre, such as blood pressure, use the examination-centre weight (WTMEC2YR), not the interview weight (WTINT2YR).

8.3.2 2-2. Estimate without and with weights

design <- svydesign(ids = ~SDMVPSU, strata = ~SDMVSTRA, weights = ~WT, nest = TRUE,
                    data = nhanes |> mutate(WT = WTMEC2YR / 2, htn = BPSysAve >= 140))

Unweighted: 16.1%; weighted: 12.9% (95% confidence interval 11.9–13.9%). NHANES oversamples groups with higher blood pressure, such as older people and Black people, so the unweighted value is an overestimate.

8.3.3 2-3. Write the report

Based on the descriptions so far, try writing the result in 2–3 sentences. What should you add?

Of the 11778 NHANES 2009–2012 participants aged 20 or over, we analysed the 10852 with blood pressure measurements. The proportion with systolic blood pressure of 140 mmHg or higher, estimated using the survey weights, was 12.9% (95% confidence interval 11.9–13.9%).

Things worth adding:

  • Definition: the average of multiple readings at a single examination, classified by systolic blood pressure alone (diastolic blood pressure and use of antihypertensive drugs are not considered). The definition differs from “prevalence of hypertension”
  • Exclusions: 926 missing blood pressure (of whom 400 did not come to the examination centre)
  • Age distribution: about 3% at ages 20–39 versus about 29% at ages 60 and over (weighted) — it differs greatly by age

8.4 Exercise 3: Review questions

NoteQuestion 1

You are about to report “the mean BMI of examinees is 23.5” from 1 million rows of health check-up data. What should you check first?

What one row is (one row per person, or one row per visit?). People who attend every year are counted many times, and the values are skewed towards people with many visits (older people, regular attenders) (Chapter 2).

NoteQuestion 2

In hospital admission data, “the mean length of stay was 18 days”. Can you call this number “the typical length of stay” as it is?

Length of stay tends to have a right-skewed distribution (a small number of very long stays), so the mean is larger than the typical value. Look at a histogram and describe with the median (IQR) (Chapter 3).

NoteQuestion 3

The output of a regression model showed “n = 3,200 (the original data had 10,000 people)”. What do you check?

Missingness in which variables excluded whom. Check that a particular group has not disappeared wholesale because of structural missingness (skipped questions), by comparing the characteristics of those who remained and those who were excluded (Chapter 4).

NoteQuestion 4

In a patient registry for a disease (5 specialist hospitals), “the 5-year survival rate for this disease was 85%”. Can you use this number when explaining to patients in general?

Patients referred to and registered at specialist hospitals may differ from patients in general in severity and care-seeking behaviour. Describe what kind of population the registered patients are (age, severity, referral source, period of registration) and consider to whom the results apply (Chapter 5).

NoteQuestion 5

In an observational study of 100,000 people, every variable in Table 1 had p < 0.001. Can you say the two groups are “very different”?

No. With many people, p-values become small even for very small differences. Judge by the size of the difference, such as the SMD (Chapter 7).

8.5 Closing

Descriptive statistics are not the “opening act” of an analysis but the foundation for reading the results of an analysis correctly.

  • Chapter 1: crude comparisons can reverse because of differences in the groups’ backgrounds
  • Chapter 2: if you do not check who one row is, you count the same person many times
  • Chapter 3: look at the distribution before the mean
  • Chapter 4: dropping missing values can mean analysing a different population
  • Chapter 5: the sample is not the population itself
  • Chapter 6: those left at the end of follow-up are the healthy ones
  • Chapter 7: Table 1 before comparing groups; judge imbalance by size, not by p-values

With your own data too, before running a model, try going through this hands-on’s checklist one item at a time.