13  Weights, sampling errors and the hand-off

Plan the sample1 Domains→2 Inputs→3 Targets→4 Design effect→5 Sample size→6 Allocation
Draw the sample7 Frame→8 PSUs→9 Households→10 Weights

The sample is drawn. What remains of the design is to say what each interview stands for, and how precise the estimates will be. This chapter takes the first half of the tenth decision of Figure 1.1. It computes the weights, checks them, adjusts them for nonresponse, computes sampling errors the way Appendix B does, and hands the sample to the survey package for analysis.

13.1 The data a survey collects

A real survey would now go to the field. Here the synthetic Gambia answers instead. The listing of each selected cluster is the list of its synthetic households, the 25 selected households respond at the rates of 2019-20, and their married women answer whether they use a modern method.

gmb_synthetic <- readRDS("data/gmb_synthetic.rds")
inputs <- gmb_inputs()
clusters <- gmb_clusters()

selected <- execute(gmb_design(), clusters, stages = 1, seed = 2025)

listing <- gmb_synthetic$households |>
  filter(cluster %in% selected$cluster) |>
  left_join(select(clusters, cluster, lga, urban_rural), by = "cluster") |>
  rename(hh_id = household)
issued <- execute(selected, listing, seed = 2027)

set.seed(2029)
households <- as.data.frame(issued) |>
  select(hh_id, lga) |>
  left_join(select(inputs, lga, completed, women_rr), by = "lga") |>
  mutate(responded = runif(n()) < completed)
women <- gmb_synthetic$married_women |>
  rename(hh_id = household) |>
  filter(hh_id %in% households$hh_id[households$responded]) |>
  left_join(select(households, hh_id, women_rr), by = "hh_id") |>
  mutate(interviewed = runif(n()) < women_rr)

interviews <- households |>
  select(hh_id, responded) |>
  left_join(summarise(women, eligible = n(), married = sum(interviewed),
                      users = sum(mcpr * interviewed), .by = hh_id),
            by = "hh_id") |>
  mutate(across(c(eligible, married, users), \(x) coalesce(x, 0L)))

observed <- left_join(issued, interviews, by = "hh_id",
                      relationship = "one-to-one")

observed |>
  as.data.frame() |>
  select(lga, cluster, hh_id, .weight, responded, eligible, married, users) |>
  mutate(.weight = round(.weight, 2)) |>
  head()
#>      lga cluster hh_id .weight responded eligible married users
#> 1 Banjul 1011002    79    7.76      TRUE        0       0     0
#> 2 Banjul 1011002    82    7.76      TRUE        2       2     0
#> 3 Banjul 1011002    85    7.76      TRUE        0       0     0
#> 4 Banjul 1011002    88    7.76      TRUE        2       2     1
#> 5 Banjul 1011002    91    7.76      TRUE        1       1     0
#> 6 Banjul 1011002    94    7.76      TRUE        0       0     0

observed keeps every issued household, respondent or not, with its design weight. For each household it records whether it responded, its eligible married women, those interviewed, and the users among them. The first rows include households with no married woman, which carry zeros in the last three columns, as does a household that did not respond.

13.2 The weight of a household

NoteOverall weight

The design weight of a unit is the product of the inverse probabilities of its stages, \[ w = \frac{1}{\pi_1} \times \frac{1}{\pi_2} \times \cdots \] For the DHS, \(w_{hij} = 1 / (P_{1hi} P_{2hi})\) (Gambia Bureau of Statistics and ICF 2021).

samplyr keeps each stage’s weight and their product. Three checks catch most errors before the weights reach an analyst.

checks <- as.data.frame(observed)

## The overall weight is the product of the stage weights
max(abs(checks$.weight - checks$.weight_1 * checks$.weight_2))
#> [1] 0

## The weights of each stratum add up to its households
checks |>
  summarise(weights = sum(.weight), .by = c(lga, urban_rural)) |>
  left_join(summarise(clusters, households = sum(households),
                      .by = c(lga, urban_rural)),
            by = c("lga", "urban_rural")) |>
  summarise(largest_difference = max(abs(weights - households)))
#>   largest_difference
#> 1       8.731149e-11

## The spread of the weights
range(checks$.weight)
#> [1]   7.764706 112.570256

The weights of a stratum add up to its households exactly here, because the synthetic listing finds the households the frame promised. With a real listing they add up to the frame count only on average, and a large difference in one stratum points to a listing or data entry error. The weights run from 8 in Banjul urban to 113 in Brikama urban, the spread that the allocation of Chapter 10 produced.

13.3 Nonresponse and normalization

The design weights describe the selection. DHS weights are then adjusted for nonresponse, separately for households and for women, within each stratum, and normalized (Gambia Bureau of Statistics and ICF 2021). The household adjustment multiplies the weights of responding households by the inverse of the stratum’s weighted response rate. The women’s adjustment does the same with the women interviewed among those eligible.

adjusted <- checks |>
  mutate(stratum = paste(lga, urban_rural)) |>
  mutate(household_factor = sum(.weight) / sum(.weight[responded]),
         .by = stratum) |>
  filter(responded) |>
  mutate(women_factor = sum(.weight * eligible) / sum(.weight * married),
         .by = stratum) |>
  mutate(weight = .weight * household_factor * women_factor)

adjusted <- adjusted |>
  mutate(normalized = weight * sum(married) / sum(weight * married))

c(households = nrow(adjusted), women = sum(adjusted$married))
#> households      women 
#>       7187       9797

adjusted |>
  distinct(stratum, household_factor, women_factor) |>
  mutate(across(where(is.numeric), \(x) round(x, 3)))
#>              stratum household_factor women_factor
#> 1       Banjul Urban            1.090        1.055
#> 2     Kanifing Urban            1.136        1.088
#> 3      Brikama Urban            1.059        1.048
#> 4      Brikama Rural            1.060        1.037
#> 5   Mansakonko Rural            1.046        1.034
#> 6   Mansakonko Urban            1.047        1.019
#> 7      Kerewan Urban            1.048        1.040
#> 8      Kerewan Rural            1.049        1.059
#> 9      Kuntaur Rural            1.047        1.039
#> 10     Kuntaur Urban            1.042        1.024
#> 11 Janjanbureh Rural            1.030        1.047
#> 12 Janjanbureh Urban            1.016        1.042
#> 13       Basse Rural            1.075        1.050
#> 14       Basse Urban            1.093        1.046

The table gives the two factors of each stratum. They stay close to one, from 1.02 to 1.14 for households, since the 2019-20 response rates were high. The largest is in Kanifing Urban, where the completion rate of 2019-20 was among the lowest.

Normalized weights average one over the interviewed women, so weighted counts equal unweighted ones nationally. They give the same proportions and means as the unnormalized weights, but no longer estimate population totals, which the report says plainly. This adjustment assumes that respondents and nonrespondents of a stratum are alike, the assumption Chapter 17 questions. Calibration to population projections, which labor force surveys use, goes one step further and is done with survey::calibrate().

13.4 Sampling errors as Appendix B computes them

A DHS estimate of a proportion is a ratio, the weighted users over the weighted women interviewed. Appendix B computes its standard error by linearization, treating the clusters of each stratum as drawn with replacement and ignoring the sampling fraction (Gambia Bureau of Statistics and ICF 2021). In survey, that is a design with the clusters as PSUs, the strata, the weights and no finite population correction.

dhs <- svydesign(ids = ~cluster, strata = ~stratum, weights = ~weight,
                 data = adjusted)

national <- svyratio(~users, ~married, dhs)
national
#> Ratio estimator: svyratio.survey.design2(~users, ~married, dhs)
#> Ratios=
#>         married
#> users 0.1720065
#> SEs=
#>           married
#> users 0.006878435

by_lga <- svyby(~users, ~lga, dhs, svyratio, denominator = ~married)
by_lga
#>                     lga users/married se.users/married
#> Banjul           Banjul    0.24170616      0.023759992
#> Basse             Basse    0.07054552      0.007551491
#> Brikama         Brikama    0.19636013      0.012678791
#> Janjanbureh Janjanbureh    0.19415551      0.019059335
#> Kanifing       Kanifing    0.15634218      0.014710142
#> Kerewan         Kerewan    0.22855470      0.020979435
#> Kuntaur         Kuntaur    0.15190763      0.017402202
#> Mansakonko   Mansakonko    0.13145577      0.018328301

The DEFT follows from the standard error and the women interviewed.

n_women <- tapply(adjusted$married, adjusted$lga, sum)
tibble(lga = by_lga$lga,
       estimate = by_lga[["users/married"]],
       se = by_lga[["se.users/married"]]) |>
  mutate(deft = se / sqrt(estimate * (1 - estimate) / as.numeric(n_women[lga])),
         rse = se / estimate) |>
  mutate(across(where(is.numeric), \(x) round(x, 3)))
#> # A tibble: 8 × 5
#>   lga         estimate    se  deft   rse
#>   <chr>          <dbl> <dbl> <dbl> <dbl>
#> 1 Banjul         0.242 0.024  1.14 0.098
#> 2 Basse          0.071 0.008  1.56 0.107
#> 3 Brikama        0.196 0.013  1.26 0.065
#> 4 Janjanbureh    0.194 0.019  1.50 0.098
#> 5 Kanifing       0.156 0.015  1.06 0.094
#> 6 Kerewan        0.229 0.021  1.45 0.092
#> 7 Kuntaur        0.152 0.017  1.86 0.115
#> 8 Mansakonko     0.131 0.018  1.74 0.139

These are the numbers a sample design report gives for one survey. Each is one draw from the spread that Chapter 6 measured.

13.5 Backtest

Appendix B prints the formula it uses. With \(y_{hi}\) and \(x_{hi}\) the weighted sums of users and of women in cluster \(i\) of stratum \(h\), \(r\) the ratio, \(z_{hi} = y_{hi} - r x_{hi}\) and \(z_h = \sum_i z_{hi}\), \[ \mathrm{SE}^2(r) = \frac{1 - f}{x^2} \sum_{h} \left[\frac{m_h}{m_h - 1} \left(\sum_{i} z_{hi}^2 - \frac{z_h^2}{m_h}\right)\right], \] with \(f\) “so small that it is ignored”. The formula can be written out and compared with survey.

appendix_b <- adjusted |>
  summarise(y = sum(weight * users), x = sum(weight * married),
            .by = c(stratum, cluster)) |>
  mutate(z = y - sum(y) / sum(x) * x) |>
  summarise(m = n(), term = m / (m - 1) * (sum(z^2) - sum(z)^2 / m),
            x = sum(x), .by = stratum)

c(appendix_b = sqrt(sum(appendix_b$term)) / sum(appendix_b$x),
  survey = sqrt(as.numeric(national$var)))
#>  appendix_b      survey 
#> 0.006878435 0.006878435

The two agree. The design declared above computes the sampling errors of Appendix B.

13.6 The hand-off

as_svydesign() builds the survey design from the sample itself, with every stage, its strata, clusters and probabilities, so that nothing has to be retyped. It approximates the variance of each systematic stage (Brewer’s approximation for the clusters, simple random sampling for the households) and warns unless the call accepts the approximation.

handed <- as_svydesign(observed, systematic_variance = "approximate")

svyby(~users, ~lga, subset(handed, responded), svyratio,
      denominator = ~married)
#>                     lga users/married se.users/married
#> Banjul           Banjul    0.24170616      0.021886997
#> Basse             Basse    0.07055172      0.007229315
#> Brikama         Brikama    0.19636798      0.012588497
#> Janjanbureh Janjanbureh    0.19403382      0.018398400
#> Kanifing       Kanifing    0.15634218      0.014609158
#> Kerewan         Kerewan    0.22850735      0.020601334
#> Kuntaur         Kuntaur    0.15170823      0.016195612
#> Mansakonko   Mansakonko    0.13148758      0.016606838

The estimates are those of the design weights, before nonresponse adjustment, and the standard error in Banjul is smaller than with the formula of Appendix B, because the export includes a finite population correction at each stage and Banjul selects a third of its clusters. The analyst who receives the sample can choose either design. The next section asks which standard error is closer to the truth.

13.7 Virtual survey

The virtual survey draws the design 1,000 times and computes each estimate’s standard error twice, as Appendix B does and with the correction \(1 - n_h / N_h\) for the share of clusters selected in each stratum.

response <- mutate(inputs, lga, household = completed, person = women_rr,
                   .keep = "none")
without_fpc <- virtual_survey(gmb_design(), gmb_synthetic, response, reps = 1000,
                        seed = 12)
with_fpc <- virtual_survey(gmb_design(), gmb_synthetic, response, reps = 1000,
                     seed = 12, fpc = TRUE)

tibble(lga = without_fpc$lga,
       ratio_without = without_fpc$se_ratio,
       ratio_with = with_fpc$se_ratio,
       cover_without = without_fpc$coverage,
       cover_with = with_fpc$coverage) |>
  mutate(across(where(is.numeric), \(x) round(x, 3))) |>
  as.data.frame()
#>           lga ratio_without ratio_with cover_without cover_with
#> 1      Banjul         1.076      0.857         0.963      0.894
#> 2    Kanifing         1.034      1.013         0.954      0.947
#> 3     Brikama         0.989      0.977         0.942      0.939
#> 4  Mansakonko         1.068      0.963         0.960      0.934
#> 5     Kerewan         0.943      0.920         0.925      0.922
#> 6     Kuntaur         1.128      1.044         0.961      0.945
#> 7 Janjanbureh         1.164      1.113         0.960      0.955
#> 8       Basse         1.007      0.948         0.943      0.923
#> 9    National         1.012      0.993         0.944      0.942

The correction does not help. In Banjul it turns a standard error 8% too large into one 14% too small, and the coverage of its intervals falls to 89%. The correction \(1 - n_h / N_h\) assumes clusters selected with equal probabilities. Under PPS the large clusters are more likely to be selected, and the share of the stratum’s households in the sample is not \(n_h / N_h\). The systematic draw adds the effect of the order of the list.

samplyr’s export corrects differently. Each cluster carries its own inclusion probability \(\pi_{hi}\) as its finite population correction, so a large cluster with a high chance of selection is corrected more than a small one, and the systematic stage is treated with Brewer’s approximation. The virtual survey above computes its own standard errors and cannot test that export. The next study runs the whole pipeline instead. It draws the design 200 times with execute(), takes the households from the synthetic Gambia, exports each sample with as_svydesign(), and compares the standard error of the export and that of Appendix B with the true one.

households <- gmb_synthetic$households
women_by_household <- gmb_synthetic$married_women |>
  summarise(married = n(), users = sum(mcpr), .by = household)
domains <- c("Banjul", "Kuntaur")

draw_and_export <- function(r) {
  selected <- suppressMessages(execute(gmb_design(), clusters, stages = 1,
                                       seed = r))
  listing <- households |>
    filter(cluster %in% selected$cluster) |>
    left_join(select(clusters, cluster, lga, urban_rural), by = "cluster") |>
    rename(hh_id = household)
  issued <- suppressMessages(execute(selected, listing, seed = r))
  observed <- issued |>
    left_join(rename(women_by_household, hh_id = household), by = "hh_id") |>
    mutate(married = coalesce(married, 0L), users = coalesce(users, 0L))
  exported <- as_svydesign(observed, systematic_variance = "approximate")
  appendix_b <- as_svydesign(observed, stages = 1,
                             systematic_variance = "approximate")
  errors <- function(d) {
    by_lga <- svyby(~users, ~lga, subset(d, lga %in% domains), svyratio,
                    denominator = ~married)
    national <- svyratio(~users, ~married, d)
    tibble(lga = c(by_lga$lga, "National"),
           estimate = c(by_lga[["users/married"]], coef(national)),
           se = c(by_lga[["se.users/married"]],
                  sqrt(as.numeric(vcov(national)))))
  }
  left_join(rename(errors(exported), se_export = se),
            select(rename(errors(appendix_b), se_appendix_b = se), lga,
                   se_appendix_b),
            by = "lga")
}

study <- bind_rows(lapply(1:200, draw_and_export))

truth <- gmb_synthetic$married_women |>
  left_join(households, by = "household") |>
  left_join(select(clusters, cluster, lga), by = "cluster") |>
  summarise(truth = mean(mcpr), .by = lga) |>
  bind_rows(tibble(lga = "National",
                   truth = mean(gmb_synthetic$married_women$mcpr)))

export_study <- study |>
  left_join(truth, by = "lga") |>
  summarise(true_se = sd(estimate),
            ratio_export = mean(se_export) / sd(estimate),
            ratio_appendix_b = mean(se_appendix_b) / sd(estimate),
            coverage_export = mean(abs(estimate - truth) <= 1.96 * se_export),
            coverage_appendix_b = mean(abs(estimate - truth) <=
                                         1.96 * se_appendix_b),
            .by = lga)
export_study |>
  mutate(across(where(is.numeric), \(x) round(x, 3))) |>
  as.data.frame()
#>        lga true_se ratio_export ratio_appendix_b coverage_export
#> 1   Banjul   0.021        0.958            1.075           0.955
#> 2  Kuntaur   0.014        1.081            1.157           0.965
#> 3 National   0.007        1.024            1.037           0.940
#>   coverage_appendix_b
#> 1               0.965
#> 2               0.980
#> 3               0.940

The export comes closest. Its standard error is 0.96 times the true one in Banjul, 1.08 in Kuntaur and 1.02 nationally, against 1.07, 1.16 and 1.04 for the formula of Appendix B. With 200 replicates the Monte Carlo error of a true standard error is about 5%. The export is within that error of the truth in Banjul and nationally, and conservative by about 8% in Kuntaur, half the excess of the formula of Appendix B there. The formula of Appendix B is conservative everywhere, most in the strata that select a large share of their clusters.

The plan uses both. The analysis takes the design that as_svydesign() exports, the closest to the truth. The formula of Appendix B is computed alongside, because the earlier rounds published it, and a backtest or a comparison between rounds must compare like with like. In the study above it comes from as_svydesign(observed, stages = 1), which keeps the clusters and strata of the first stage, reads the clusters as drawn with replacement and leaves out the correction.

No Gambian cluster is large enough to be taken with certainty. One that was would add no variance between clusters, since it is in every sample, and the export handles it according to what was drawn inside it. With two households or more, as in any Gambian cluster, it is a stratum of its own whose households are its clusters; with every household taken, it is a census stratum and adds no variance. With a single household drawn, a stratum of its own could not estimate the variance of that draw, so the cluster stays a draw of its stratum and samplyr says so with a message. A stage drawn with replacement has no such clusters, even where a cluster’s expected number of hits is one or more.

13.8 National precision from the domains

Chapter 10 computed the national RSE of a plan from the LGA standard errors, \(\sqrt{\sum_h W_h^2 \mathrm{SE}_h^2}\), with \(W_h\) each LGA’s share of the married women. The same formula applied to the sample should come close to the national standard error survey computes directly.

shares <- adjusted |>
  summarise(w = sum(weight * married), .by = lga) |>
  mutate(w = w / sum(w))
se_lga <- setNames(by_lga[["se.users/married"]], by_lga$lga)

c(from_domains = sqrt(sum(shares$w^2 * se_lga[shares$lga]^2)),
  direct = sqrt(as.numeric(national$var)))
#> from_domains       direct 
#>  0.006810146  0.006878435

They agree closely, because the LGAs are sampled independently and the national estimate is their weighted mean.

13.9 How the other surveys weight

MICS weights follow the same steps, with one more factor where a large cluster was segmented, and the same normalization Chapter 26. The Malawi IHS counts a replacement household as a respondent, so its nonresponse adjustment is near one, and the weights carry the assumption that replacements resemble the households they replace (Chapter 28). Labor force surveys calibrate their weights to population projections by age and sex, and their rotation groups add a factor (Chapter 20). Where a stratum is a census of its clusters, such as Likoma in the Malawi IHS, its first stage contributes no variance, and the with-replacement formula overstates the error by the most.

13.10 What to record

TipFor the sample design report

The design weight of a household is \(1 / (P_{1hi} P_{2hi})\), with \(P_{1hi} = a_h M_{hi} / M_h\) and \(P_{2hi} = 25 / L_{hi}\). Household weights are adjusted for household nonresponse within each stratum, and women’s weights for individual nonresponse within each stratum, and both are normalized so that the weighted number of interviews equals the unweighted number nationally. Sampling errors are computed by Taylor linearization on the design exported from the sample, with a finite population correction from each cluster’s inclusion probability. For comparison with earlier rounds, the errors of the formula of Appendix B, with clusters treated as selected with replacement within strata, are computed too. A virtual survey on the synthetic Gambia found the first close to the truth and the second conservative, most in the LGAs that select a large share of their clusters.

13.11 Exercises

  1. Recompute the household adjustment factors with unweighted response rates, as DHS reports describe them. Do the factors change? Why?
  2. Estimate the national mCPR with the normalized weights and with the unnormalized ones. Then estimate the number of users. Which weights give a sensible total?
  3. Add fpc = ~N_clusters to the design of Appendix B, with N_clusters the clusters of each stratum, and compare Banjul’s standard error with the two values above.
  4. Compute the DEFT of the national estimate from national and the women interviewed. How much of it is the weighting loss of the allocation?
  1. Within a stratum the design weights are equal when the listing finds the frame’s households, so weighted and unweighted rates are the same here. With a real listing they differ slightly.
  2. Both give the same proportion. The normalized weights add up to the number of women interviewed, so their total of users is the number of users interviewed, not of the country. The unnormalized weights estimate the users in the population.
  3. The standard error falls by a factor of \(\sqrt{1 - 34/93} = 0.80\) in Banjul, below both the Appendix B and the samplyr values.
  4. The DEFT is \(\mathrm{SE} / \sqrt{p(1 - p)/n}\). Dividing its square by Kish’s factor of the allocation, about 1.8, leaves the clustering.