cassionData Analysis

Exercise · Intermediate

The weight that was never applied

A colleague's analysis script produces four estimates from the household survey. Every one is computed correctly and every one is wrong, in four different ways. Find each, fix it, and quantify what it cost.

R60 min

The script below was written by a colleague under deadline and its four numbers are already in a draft report. Nothing in it errors, every figure is a plausible percentage, and all four are wrong.

Your job is to find out how wrong, in points, for each.

The files

household-survey-2025.v1.csv — 996 household interviews. household-survey-frame-2025.v1.csv — the 470-area sampling frame the survey was drawn from, with the selection and response record for the 75 selected areas.

The script

library(dplyr)
library(readr)
library(survey)

survey <- read_csv("household-survey-2025.v1.csv")
frame  <- read_csv("household-survey-frame-2025.v1.csv")

# 1. Headline food insecurity
survey |> summarise(food_insecure = mean(food_insecure == "true"))

# 2. Improved water access, with a confidence interval
design <- svydesign(ids = ~household_id, weights = NULL, data = survey)
svymean(~I(improved_water_source == "true"), design)

# 3. Acute malnutrition among children under five
survey |>
  filter(!is.na(child_muac_mm)) |>
  summarise(gam = mean(child_muac_mm < 125))

# 4. Food insecurity among displaced households in rural remote areas
survey |>
  filter(stratum == "rural-remote", displacement_status == "displaced") |>
  summarise(n = n(), rate = mean(food_insecure == "true"))

The task

For each of the four estimates:

  1. Say what is wrong, in one sentence, naming the concept rather than the line of code.
  2. Recompute it correctly, showing the code.
  3. Report the cost, as the difference between the wrong figure and the right one, in percentage points or in interval width.

Produce a four-row table with those three columns and a fourth naming which lesson of the course the fault belongs to.

What each one needs

The faults are different and none is a typo.

  • Estimate 1 ignores something the frame supplies.
  • Estimate 2 builds a design object that describes a survey nobody ran. Two arguments are wrong and they fail in opposite directions — one moves the point estimate, the other moves the interval.
  • Estimate 3 uses a denominator that is not the population it claims, and needs a multiplication the script never does. It also inherits a data quality problem the dataset’s known issues describe.
  • Estimate 4 is the subtle one. It is arithmetically fine and should not be published at all; say why, with numbers.

Two checks you can use

Reconstructed weights must sum to 56,428, the households the frame holds. If yours do not, fix that before computing anything else.

Correctly estimated, food insecurity is 29.1% and improved water access is 69.8%.

The questions to answer in prose

Three sentences each.

1. Estimate 2’s design object gets both the weights and the clustering wrong. Say which of the two moves the point estimate and which moves the interval, and which of the two errors would be harder for a reviewer to notice.

2. Estimate 3 is a proportion computed over children who were measured. Name the two separate corrections it needs, and say which direction each moves the figure.

3. Estimate 4 will be quoted in the report as a finding about displaced households in remote areas. Give the number of households and the number of clusters behind it, and write the sentence you would put in the table instead.

What to hand in

An R script producing the four-row fault table and a second table with the corrected estimates, each carrying its denominator, its design effect and its 95% confidence interval. Both printed and written to outputs/.

How to know you are done

Every corrected estimate comes off a svydesign object with ids, strata and weights all set, and your weights sum to the frame total. One of your four corrected rows is a suppression rather than a number, and it says why.