The same population, different frames
Source:vignettes/articles/frames-compared.Rmd
frames-compared.RmdA survey is planned from a frame, and the frame shapes the plan. Small EAs hold households that live close together, so their outcomes are more alike and a survey needs more of them. A stale or incomplete frame changes the sizes EAs are drawn with and the population a sample can reach. On a simulated population the truth is known, so both effects can be measured. This article asks two questions, in the structure of Morris, White and Crowther (2019). Does a design planned with the components of its own frame reach its target precision, whatever the size of the EAs? And when a frame misses more rural EAs than urban ones, what do the estimates converge to? decoupage builds the population, its frames and their truth, svyplan plans the survey, samplyr draws it and survey estimates from it.
Population and frames
Households fall on the Yako window (?yako) in proportion
to its population raster, 30,000 of them, twenty times the real density,
so that frames of many EAs fit. A household is urban where its square
kilometer holds at least 2,000 households. The outcome is a binary
indicator of persons, with variance from a spatial field of range 400 m,
from households and from persons, a prevalence of 40% among rural
persons, and urban persons 0.4 latent standard deviations lower.
path <- system.file("extdata", "yako.gpkg", package = "decoupage")
raster <- system.file("extdata", "yako_pop.tif", package = "decoupage")
communes <- sf::st_read(path, layer = "communes", quiet = TRUE)
pop <- sim_territory(communes, district = "commune") |>
sim_households(n = 30000, raster = raster, urban_density = 2000,
seed = 1) |>
sim_outcome("y", family = "binary", prevalence = 0.4,
components = c(spatial = 0.25, household = 0.25, person = 0.5),
range = 400, effects = c(urban = -0.4), seed = 2)
population_truth(pop, "y", by = "urban")[c("domain", "persons", "mean")]
#> domain persons mean
#> 1 FALSE 38088 0.4044056
#> 2 TRUE 111840 0.2480597Three frames cut the same households into EAs of about 60, 150 and 300 households, the range of real census frames. The population and the frames are drawn once, and each repetition below draws a new sample, so the results hold for this population, as in a design-based study.
sizes <- list(small = c(60, 100), medium = c(150, 250),
large = c(300, 500))
frames <- lapply(sizes, function(s) {
sim_frame(pop, target = s[1], max = s[2], seed = 3)
})
par(mfrow = c(1, 3), mar = c(0, 0, 1.5, 0))
for (k in names(frames)) {
plot(sf::st_geometry(frames[[k]]$eas), border = "grey40", lwd = 0.4,
main = sprintf("%s, %d EAs", k, nrow(frames[[k]]$eas)))
}
Truth and plans
The estimand is the prevalence of y among persons.
frame_truth() gives it on each frame, with the components a
planner needs. The homogeneity within EAs, icc, falls as
EAs grow, because a larger EA spans more of the spatial field.
truth <- do.call(rbind, lapply(names(frames), function(k) {
cbind(frame = k, frame_truth(frames[[k]], "y"))
}))
truth[c("frame", "eas", "mean", "unit_relvar", "icc", "icc_ssu")]
#> frame eas mean unit_relvar icc icc_ssu
#> 1 small 509 0.2877781 2.474916 0.10527809 0.3526851
#> 2 medium 200 0.2877781 2.474916 0.08823643 0.3592888
#> 3 large 100 0.2877781 2.474916 0.07458391 0.3653665Each frame gets its own design. EAs are drawn with probability proportional to their recorded size, then 12 households in each with all their persons. svyplan finds the count of EAs that reaches a coefficient of variation of 10%, at a cost of 400 per EA, 25 per household and 1 per person. It plans persons as a sample within each household and leaves out the finite population correction, so the plan is conservative.
plan <- function(t) {
svyplan::n_cluster(
stage_cost = c(400, 25, 1),
icc = c(t$icc, t$icc_ssu),
var_ratio = c(t$var_ratio, t$var_ratio_ssu),
unit_relvar = t$unit_relvar,
cv = 0.1, n_per_psu = 12, n_per_ssu = 5
)
}
plans <- lapply(split(truth, truth$frame)[names(frames)], plan)
n_eas <- vapply(plans, function(p) p$operational$n[["n_psu"]], 1L)
n_eas
#> small medium large
#> 39 35 32samplyr draws from the EAs of the frame that have a size, and from the listing of households. survey estimates the prevalence as a ratio of weighted totals, with Brewer’s approximation at the first stage and an interval on the design’s degrees of freedom.
hh <- pop$households
cases <- tapply(pop$persons$y,
factor(pop$persons$household, levels = hh$household), sum)
survey_once <- function(frame, n_ea, seed) {
register <- sf::st_drop_geometry(frame$frame)[c("ea", "mos")]
register <- register[register$mos > 0, ]
listing <- data.frame(ea = frame$assignment, household = hh$household,
persons = hh$size, cases = as.vector(cases))
design <- sampling_design() |>
add_stage() |>
cluster_by(ea) |>
draw(n = n_ea, method = "pps_brewer", mos = mos) |>
add_stage() |>
draw(n = 12)
drawn <- execute(design, list(register, listing), seed = seed)
svy <- as_svydesign(drawn)
est <- survey::svyratio(~cases, ~persons, svy)
c(estimate = as.numeric(coef(est)), se = as.numeric(sqrt(vcov(est))),
df = survey::degf(svy))
}Performance
Each frame gets reps samples, which give the bias, the
empirical standard error and coefficient of variation, the mean
estimated standard error, the root mean squared error and the coverage
of the 95% interval, with the Monte Carlo standard errors of Morris et
al. (2019).
performance <- function(out, target) {
est <- out["estimate", ]
r <- length(est)
emp_se <- stats::sd(est)
half <- stats::qt(0.975, out["df", ]) * out["se", ]
cover <- mean(abs(est - target) <= half)
data.frame(
bias = mean(est) - target,
bias_mcse = emp_se / sqrt(r),
emp_se = emp_se,
cv = emp_se / target,
model_se = mean(out["se", ]),
rmse = sqrt(mean((est - target)^2)),
coverage = cover,
coverage_mcse = sqrt(cover * (1 - cover) / r)
)
}
replicate_surveys <- function(frame, n_ea, reps) {
vapply(seq_len(reps), function(r) survey_once(frame, n_ea, seed = r),
c(estimate = 0, se = 0, df = 0))
}
reps <- 200
results <- do.call(rbind, lapply(names(frames), function(k) {
out <- replicate_surveys(frames[[k]], n_eas[[k]], reps)
cbind(frame = k, eas = n_eas[[k]], performance(out, truth$mean[1]))
}))
print(results, digits = 2)
#> frame eas bias bias_mcse emp_se cv model_se rmse coverage
#> 1 small 39 -0.00016 0.0017 0.024 0.084 0.025 0.024 0.96
#> 2 medium 35 -0.00191 0.0018 0.025 0.087 0.025 0.025 0.96
#> 3 large 32 0.00013 0.0018 0.025 0.087 0.023 0.025 0.93
#> coverage_mcse
#> 1 0.013
#> 2 0.013
#> 3 0.019The bias of each design is within two Monte Carlo standard errors of
zero, each reaches a coefficient of variation below 10%, and the
intervals cover close to 95%. The frames differ in the count of EAs a
design needs, since large EAs are less homogeneous. A planner who took
the icc of one frame to plan on another would draw too many
EAs or too few. A run of 2,000 samples per design gives coverages of
95%, 96% and 94% for the small, medium and large frames, each within
half a point of Monte Carlo error.
A frame that misses rural EAs
sim_frame_defects() makes the medium frame ten years
stale and omits rural EAs with probability 40% and urban ones with 2%.
The survey keeps the design planned on the complete frame.
medium <- frames$medium
omit <- stats::setNames(ifelse(medium$eas$urban, 0.02, 0.4),
medium$eas$ea)
stale <- sim_frame_defects(medium, years = 10, undercoverage = omit,
seed = 4)
stale_truth <- frame_truth(stale, "y")
stale_truth[c("eas", "eas_frame", "persons_missed", "mean",
"mean_covered")]
#> eas eas_frame persons_missed mean mean_covered
#> 1 200 177 0.1270877 0.2877781 0.2748827
out <- replicate_surveys(stale, n_eas[["medium"]], reps)
targets <- c(population = stale_truth$mean,
covered = stale_truth$mean_covered)
do.call(rbind, lapply(names(targets), function(k) {
cbind(target = k, performance(out, targets[[k]]))
})) |>
print(digits = 2)
#> target bias bias_mcse emp_se cv model_se rmse coverage
#> 1 population -0.01246 0.0018 0.026 0.090 0.024 0.029 0.89
#> 2 covered 0.00043 0.0018 0.026 0.094 0.024 0.026 0.96
#> coverage_mcse
#> 1 0.023
#> 2 0.014The frame misses rural persons, who have the outcome more often.
Against the covered population, the estimates have no bias beyond their
Monte Carlo error, and the stale sizes do not bias them, since
households are drawn from the listing of each selected EA. Against the
whole population, they carry the gap between the two targets, which no
design on the frame can see. In 2,000 samples the intervals cover the
whole population 90% of the time and the covered one 94%. A study of
undercoverage states which target it compares with, and
frame_truth() gives both.
Reference
Morris, T. P., White, I. R., and Crowther, M. J. (2019). Using simulation studies to evaluate statistical methods. Statistics in Medicine, 38(11), 2074-2102. https://doi.org/10.1002/sim.8086