library(decoupage)
eas <- readRDS("data/gmb24_ea_polygons.rds") |>
inner_join(readRDS("data/gmb24_eas.rds"), by = "ea_id") |>
mutate(urban = urban_rural == "Urban")
placed <- populate_frame(eas, households = "households", id = "ea_id",
district = "district", region = "lga",
urban = "urban", place = "clustered", seed = 1)6 Virtual surveys
A sample design is a prediction. It says that the households it selects, once interviewed, will give estimates with a stated precision. The prediction rests on assumptions: a design effect carried over from the last round, response rates, a frame whose counts are right. When an assumption fails, the survey finds out after fieldwork, when nothing can be changed.
A virtual survey tests the prediction before fieldwork. It fields the design many times on a synthetic population whose true values are known, and measures what the survey would deliver. The idea is old, in ecology, meteorology and Bayesian modeling among other fields (Chapter 1). Survey methodologists call it a design-based simulation and use it to compare estimators. The virtual survey applies the idea to one design, on the frame it will be drawn from.
The name also avoids a confusion. Census offices run a dress rehearsal before a census, and survey programs a pilot, both real operations in the field. A virtual survey sends no one to the field. It complements the pilot, which tests the questionnaire and the logistics, by testing the sample.
This chapter builds the synthetic Gambia on which Parts II and III run their virtual surveys, checks it against the 2019-20 report, and shows how to read the results. It also shows a check that failed, and what the failure taught.
6.1 What a virtual survey needs
A virtual survey needs three things. The first is a population on the real frame, with households in every EA and an outcome for every person. The second is the design, declared in samplyr exactly as it will be fielded. The third is the procedure the survey will use to compute its estimates and their standard errors. The virtual survey draws the design, applies the procedure, and compares the estimates with the population’s true values.
The population is the hard part. A population that is too easy, where households of an EA are no more alike than households across the country, makes every design look good. A population that is too hard makes every design look bad. The population must reproduce what the last round found, and the 2019-20 report says what that is. Its sampling errors give, for each LGA, how much clustering cost in precision.
6.2 Building the synthetic Gambia
The population is built in three steps with the decoupage package. The code is shown but not run here, because placing 311,113 households takes about four minutes. The full script is in sim/gambia/ of the book’s repository.
The first step places households in the EAs of the frame. Each EA receives exactly the households of its count, grouped in villages around a few centers, and each household receives 1 plus a Poisson number of persons, five on average.
The second step gives every person an outcome, here whether a woman uses a modern contraceptive method. sim_outcome() draws it from a latent variable, a continuous score, and a woman uses a modern method when her score is above zero.
Person \(k\) of household \(j\) in EA \(i\) of LGA \(l\) has the latent score \[ y^*_{k} = \mu_l + a_i + h(d_i) \, b_i + c_j + e_k, \] and uses a modern method when \(y^*_{k} > 0\). The terms \(a_i\), \(c_j\) and \(e_k\) are normal with variances \(\sigma^2_a\), \(\sigma^2_c\) and \(1 - \sigma^2_a - \sigma^2_c\). A second EA effect \(b_i\) has variance \(\sigma^2_b\) and is weighted by \(h(d_i)\), a number between 0 and 1 that falls with the household density \(d_i\) of the EA. The term \(\mu_l\) sets the level of the LGA.
The EA terms make the women of an EA more alike than women drawn at random. This is what makes a cluster sample less precise than a simple random sample of the same size, the design effect of Chapter 4. The weight \(h(d)\) makes sparse villages more homogeneous than towns. It equals \(1 / (1 + (d / d_0)^{1/s})\) with \(d_0 = 50\) households per square kilometer and \(s = 0.7\), so it is near 1 in a village of 10 households per square kilometer and near 0 in a town of 1,000.
placed$population$households$ea_extra <- b[placed$assignment] *
h[placed$assignment]
mcpr <- sim_outcome(placed, "mcpr", family = "binary", prevalence = 0.5,
components = c(ea = 0.035, household = 0.10,
person = 0.865),
effects = c(lga_effects, ea_extra = sqrt(0.15)),
seed = 2)b holds one normal draw per EA, h the density weight of each EA, and lga_effects the LGA effects of the third step.
The third step sets the levels. The LGA effects \(\mu_l\) are solved by a few iterations so that the mCPR of each LGA’s married women equals the 2019-20 estimate. Within each LGA, women are flagged as married at the rate per household of Table A.5. The result is stored in the book’s data.
gmb_synthetic <- readRDS("data/gmb_synthetic.rds")
sapply(gmb_synthetic[c("clusters", "households", "married_women")], nrow)
#> clusters households married_women
#> 5003 311113 397488The population has 311,113 households in 5,003 clusters, and 397,488 married women. It is a list of three linked tables. A cluster row carries the columns of the frame that a design stratifies, sorts and sizes on. A household row names its cluster, and a married woman row names her household and holds her outcome, 1 for a user of a modern method.
head(gmb_synthetic$clusters, 3)
#> lga urban_rural cluster district ward
#> 1 Banjul Urban 1021001 Banjul Central New Town East
#> 2 Banjul Urban 1021002 Banjul Central New Town East
#> 3 Banjul Urban 1021003 Banjul Central New Town East
#> households eas
#> 1 81 1
#> 2 55 1
#> 3 91 1
head(gmb_synthetic$households, 3)
#> # A tibble: 3 × 2
#> household cluster
#> <int> <chr>
#> 1 1 1011001
#> 2 2 1011001
#> 3 3 1011001
head(gmb_synthetic$married_women, 3)
#> # A tibble: 3 × 2
#> household mcpr
#> <int> <int>
#> 1 5 0
#> 2 6 1
#> 3 6 0
gmb_synthetic$parameters
#> ea household extra d0
#> 0.035 0.100 0.150 50.000The last line holds the three variance shares, 0.035, 0.10 and 0.15, and the midpoint \(d_0\) of 50 households per square kilometer. None of them is in any report. They were chosen by the check of the next section.
6.3 The predictive check
The 2019-20 design is known from Appendix A of its report. It selected the EAs of Table A.3 in 14 strata by systematic PPS, 25 households in each, with the response rates of Table A.5. Drawn on the synthetic Gambia, it should give DEFTs like those the report published. If it gives much larger ones, the synthetic EAs are too homogeneous; if it gives smaller ones, they are not homogeneous enough.
inputs <- read.csv("data/gmb_dhs2019_lga.csv")
table_a3 <- bind_rows(
mutate(inputs, lga, urban_rural = "Urban", n = eas_urban, .keep = "none"),
mutate(inputs, lga, urban_rural = "Rural", n = eas_rural, .keep = "none")
) |>
filter(n > 0)
design_2019 <- sampling_design("DHS 2019-20") |>
add_stage("Clusters") |>
stratify_by(lga, urban_rural) |>
cluster_by(cluster) |>
draw(n = table_a3, method = "pps_systematic", mos = households,
control = c(district, ward)) |>
add_stage("Households") |>
draw(n = 25, method = "systematic")
response <- mutate(inputs, lga, household = completed, person = women_rr,
.keep = "none")
check <- virtual_survey(design_2019, gmb_synthetic, response, reps = 1000,
seed = 11)Each replicate gives a DEFT for each LGA, as Appendix B would have printed it. The check places the published DEFT within the 1,000 simulated ones.
published <- mutate(inputs, .domain = lga, published = mcpr_deft,
.keep = "none")
deft_spread <- function(virtual) {
attr(virtual, "replicates") |>
filter(.domain != "National") |>
mutate(deft = se / sqrt(est * (1 - est) / n)) |>
left_join(published, by = ".domain") |>
summarise(published = first(published),
low = quantile(deft, 0.05), median = median(deft),
high = quantile(deft, 0.95),
percentile = mean(deft <= first(published)),
.by = .domain)
}
spread <- deft_spread(check)
spread |>
mutate(across(where(is.numeric), \(x) round(x, 2)))
#> .domain published low median high percentile
#> 1 Banjul 1.02 0.92 1.14 1.35 0.19
#> 2 Basse 1.65 1.23 1.58 2.00 0.61
#> 3 Brikama 1.09 1.04 1.49 2.31 0.08
#> 4 Janjanbureh 1.87 1.18 1.56 1.89 0.94
#> 5 Kanifing 1.25 0.93 1.13 1.36 0.80
#> 6 Kerewan 1.49 1.22 1.55 1.93 0.41
#> 7 Kuntaur 1.53 1.36 1.73 2.21 0.18
#> 8 Mansakonko 1.57 1.08 1.47 1.80 0.69Every published DEFT lies between the 5th and the 95th percentile of its simulated spread. The design that produced the 2019-20 sampling errors would produce errors like them on the synthetic Gambia, LGA by LGA. The spreads are wide. Brikama’s simulated DEFT runs from 1.04 to 2.31, which says how little one published DEFT pins down. Chapter 8 shows what that costs a plan.
The national RSE does not match as well. The report gives 3.9%, and the virtual survey 4.8% in the median replicate. The difference comes from the frame, not the population. The 2019-20 sample was allocated on the 2013 frame, where Brikama held 37% of the households. On the 2024 frame it holds 48%. The same allocation then gives Brikama’s households larger weights, and the national estimate loses more precision to unequal weights. Kish’s factor measures that loss (Kish 1965).
table_a1 <- read.csv("data/gmb_dhs2019_frame.csv") |>
rename(N = households)
frame_2024 <- gmb_synthetic$clusters |>
summarise(N = sum(households), .by = c(lga, urban_rural))
kish <- function(frame) {
strata <- inner_join(frame, table_a3, by = c("lga", "urban_rural"))
as.numeric(design_effect(strata = data.frame(N = strata$N, n = strata$n)))
}
c(frame_2013 = kish(table_a1), frame_2024 = kish(frame_2024))
#> frame_2013 frame_2024
#> 1.440832 2.281835The weighting loss rises from 1.44 to 2.28, which multiplies the national standard error by 1.26. Applied to the published 3.9%, that gives 4.9%, close to the virtual survey. The check also shows something about the next round. An allocation designed on an old frame loses precision when the population has moved, and Chapter 15 returns to it.
6.4 A check that failed
The first version of the synthetic Gambia had no density. The second EA effect was carried by rural EAs only, so every rural EA was more homogeneous than every urban one. The rule reproduced the pattern of Appendix B (low DEFTs in Banjul and Kanifing, high ones in the rural LGAs), and it seemed enough. The same check on that population gives this.
residence <- readRDS("data/gmb_synthetic_residence.rds")
check_residence <- virtual_survey(design_2019, residence, response, reps = 1000,
seed = 11)
bind_rows(residence = deft_spread(check_residence),
density = deft_spread(check), .id = "model") |>
filter(.domain %in% c("Brikama", "Kuntaur")) |>
mutate(across(where(is.numeric), \(x) round(x, 2)))
#> model .domain published low median high percentile
#> 1 residence Brikama 1.09 1.12 1.76 3.03 0.04
#> 2 residence Kuntaur 1.53 1.50 1.93 2.45 0.07
#> 3 density Brikama 1.09 1.04 1.49 2.31 0.08
#> 4 density Kuntaur 1.53 1.36 1.73 2.21 0.18Under the residence rule, Brikama’s published DEFT falls at the 4th percentile of its spread, and Kuntaur’s at the 7th. A DEFT as low as Brikama’s would come up in about one survey in 23. Either the 2019-20 survey was unlucky in Brikama, or the synthetic Brikama is wrong.
The answer was in the frame. Brikama’s rural EAs are not villages like those of the other rural strata. They lie around the towns of the coast, and their household density is ten times that of rural EAs elsewhere.
readRDS("data/gmb24_ea_polygons.rds") |>
inner_join(readRDS("data/gmb24_eas.rds"), by = "ea_id") |>
mutate(density = households / (as.numeric(sf::st_area(geometry)) / 1e6)) |>
sf::st_drop_geometry() |>
filter(urban_rural == "Rural") |>
summarise(median_density = round(median(density)), .by = lga)
#> lga median_density
#> 1 Brikama 133
#> 2 Mansakonko 10
#> 3 Kerewan 17
#> 4 Kuntaur 11
#> 5 Janjanbureh 15
#> 6 Basse 15A peri-urban EA is likely to hold households of many origins and occupations, as an urban one does. Making the extra homogeneity fall with density, rather than switch at the urban boundary, moved Brikama’s published DEFT to the 8th percentile, and kept the other LGAs inside their spreads.
spreads <- bind_rows(Residence = deft_spread(check_residence),
Density = deft_spread(check), .id = "model") |>
mutate(lga = factor(.domain, levels = rev(inputs$lga)))
ggplot(spreads, aes(y = lga, color = model)) +
geom_linerange(aes(xmin = low, xmax = high),
position = position_dodge(width = 0.6), linewidth = 1.2) +
geom_point(aes(x = median), shape = 124, size = 4,
position = position_dodge(width = 0.6)) +
geom_point(aes(x = published), shape = 18, size = 3.5,
color = "black") +
scale_color_manual(values = c(Density = "#1f5f99", Residence = "grey60")) +
labs(x = "DEFT of mCPR", y = NULL, color = "Model") +
theme_minimal(base_size = 11) +
theme(legend.position = "bottom")
The failure was useful twice. It found a feature of the real Gambia that the first model lacked. It also changed the plan of Chapter 8, where Brikama’s low DEFT would otherwise have been taken at face value. A synthetic population is a model, and it is checked like any other model, by comparing what it predicts with what was observed.
6.5 Reading a virtual survey
A virtual survey is a simulation study, and the structure that Morris et al. (2019) propose for such studies helps to read one. It names five things.
- The aims, here whether the 2019-20 design gives the precision of its report, and whether its standard errors are right.
- The data-generating mechanism, the synthetic Gambia and the response rates.
- The estimands, the true mCPR of each LGA and of the country.
- The methods, the design and the estimator (a weighted mean with a linearized standard error that treats clusters as drawn with replacement, as DHS sampling errors are computed).
- The performance measures, which the box defines.
Over \(R\) replicates with estimates \(\hat\theta_r\) and estimated standard errors \(\widehat{\mathrm{SE}}_r\) of a true value \(\theta\), \[ \mathrm{bias} = \bar{\hat\theta} - \theta, \qquad \mathrm{SE}_{\mathrm{true}} = \sqrt{\frac{1}{R - 1} \sum_r (\hat\theta_r - \bar{\hat\theta})^2}, \qquad \text{SE ratio} = \frac{\overline{\widehat{\mathrm{SE}}}} {\mathrm{SE}_{\mathrm{true}}}, \] and the coverage is the share of replicates whose interval \(\hat\theta_r \pm 1.96 \, \widehat{\mathrm{SE}}_r\) contains \(\theta\). The true RSE is \(\mathrm{SE}_{\mathrm{true}} / \theta\). Their Monte Carlo errors are about \(\mathrm{SE}_{\mathrm{true}} / \sqrt{R}\) for the bias, \(1 / \sqrt{2(R - 1)}\) of the value for \(\mathrm{SE}_{\mathrm{true}}\), and \(\sqrt{c(1 - c) / R}\) for a coverage \(c\).
virtual_survey() returns these measures for each LGA and for the country.
check |>
mutate(lga, truth, bias = mean - truth, true_rse, se_ratio, coverage,
.keep = "none") |>
mutate(across(where(is.numeric), \(x) round(x, 3)))
#> # A tibble: 9 × 6
#> lga truth true_rse se_ratio coverage bias
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 Banjul 0.217 0.076 1.27 0.985 -0.001
#> 2 Kanifing 0.159 0.079 1.13 0.967 0
#> 3 Brikama 0.197 0.09 0.943 0.909 -0.001
#> 4 Mansakonko 0.144 0.132 0.991 0.944 0
#> 5 Kerewan 0.208 0.097 0.993 0.932 -0.001
#> 6 Kuntaur 0.141 0.112 1.17 0.959 -0.001
#> 7 Janjanbureh 0.182 0.112 0.936 0.944 0
#> 8 Basse 0.078 0.129 1.05 0.948 0
#> 9 National 0.17 0.053 0.954 0.926 0The estimator has no bias that matters. The largest is a tenth of a percentage point, under a tenth of the standard error. The coverage ranges from 91% to 98%, and its Monte Carlo error at 95% is 0.7 points, so departures of more than about 1.4 points are real. They come from the SE ratio. Where the estimated standard error is too large, coverage is above 95%, and where it is too small, below.
The largest SE ratio is Banjul’s, 1.27. The 2019-20 design selects 40 of Banjul’s 93 clusters, and the standard error that treats them as drawn with replacement leaves out the finite population correction. The correction for a sampling fraction of 40 out of 93 is \(1 / \sqrt{1 - 40/93} = 1.32\), close to the ratio observed. The survey overstates Banjul’s standard error, a conservative error. Chapter 13 discusses when to correct it.
6.6 What a virtual survey cannot show
A virtual survey tests a design against the variation its population contains, and no other. The synthetic Gambia is calibrated on one indicator. An indicator that clusters more, such as access to piped water, or less, such as the sex of a newborn, would give other design effects. Response is drawn at random within each LGA, so the population has no nonresponse that depends on the outcome. Chapter 17 adds it. The frame counts are exact, so the listing finds the households the frame promised. Chapter 15 relaxes that.
The population is also one draw. Its EA effects were drawn once, and the 1,000 replicates all select from the same EAs. A virtual survey measures how a design performs on this Gambia, which the check brought close to the real one. It does not average over all the Gambias that could have produced the 2019-20 report.
Within these limits, a virtual survey answers questions no formula answers in one line. Each chapter of Parts II and III ends with a virtual survey, with the design of that chapter and the call virtual_survey(design, gmb_synthetic, response).
6.7 Exercises
- The virtual survey used 1,000 replicates. Rerun the check with 200 and with 5,000 replicates. How much do the percentiles of the published DEFTs move?
- The Monte Carlo error of a coverage of 95% is \(\sqrt{0.95 \times 0.05 / R}\). With \(R = 1{,}000\), which LGAs of the check have a coverage that differs from 95% by more than two Monte Carlo errors? What are their SE ratios?
- Compute the finite population correction for each stratum of the 2019-20 design, from the EAs of Table A.3 and the clusters of each stratum in
gmb_synthetic$clusters. Which strata other than Banjul have a correction above 1.05? Does the correction explain Kuntaur’s SE ratio? - Run a virtual survey of an allocation of 281 EAs proportional to the households of the 2024 frame, with at least two EAs in each stratum. What national RSE does it reach, and at what cost to the small LGAs?
- With 200 replicates the percentiles move by up to 4 points from their values at 1,000, and with 5,000 by up to 3. Every published DEFT stays inside the central 90% in all three runs.
- Two Monte Carlo errors are 1.4 points, so coverages outside 93.6% to 96.4% differ from 95%. Banjul (98.5%) and Kanifing (96.7%) have SE ratios of 1.27 and 1.13, and Brikama (90.9%) one of 0.94. Kerewan (93.2%) has a ratio of 0.99, and its coverage is just outside the band.
- The correction is
1 / sqrt(1 - n / N). Banjul’s is 1.33. Above 1.05 come the urban parts of Kuntaur (3 of 16 clusters, 1.11), Mansakonko (1.10) and Janjanbureh (1.08), and the rural parts of Mansakonko (1.07) and Kuntaur (1.05). Kuntaur’s correction is a few percent, so most of its SE ratio of 1.17 comes from the systematic draw, not from the finite population. - The national RSE falls to about 3.3%, against 4.9% with the 2019-20 allocation. Banjul, Mansakonko and Kuntaur receive 6, 11 and 11 EAs, and their RSEs rise above 20%.