Skip to contents

Compute the required sample size for estimating a population proportion with a specified margin of error or coefficient of variation.

Usage

n_prop(p, ...)

# Default S3 method
n_prop(
  p,
  ...,
  moe = NULL,
  cv = NULL,
  rmoe = NULL,
  alpha = 0.05,
  N = Inf,
  deff = 1,
  resp_rate = 1,
  eligibility_rate = 1,
  eligible_per_unit = 1,
  method = c("wald", "wilson", "logodds", "beta"),
  df = NULL,
  min_cases = NULL,
  plan = NULL
)

# S3 method for class 'svyplan_prec'
n_prop(p, ..., moe = NULL, cv = NULL, rmoe = NULL)

Arguments

p

For the default method: expected proportion, in (0, 1). For svyplan_prec objects: a precision result from prec_prop().

...

Additional arguments passed to methods. Unused arguments are rejected.

moe

Desired margin of error, the half-width of the confidence interval on the proportion scale. For example, moe = 0.05 means the 95 percent CI should be no wider than +/- 5 percentage points. Specify exactly one of moe, cv, or rmoe.

cv

Target coefficient of variation (relative standard error). For example, cv = 0.10 means the standard error should be at most 10 percent of the estimate. Use cv when you want precision to scale with the estimate (common in economic surveys). Use moe when you want a fixed absolute precision (common in health surveys). Specify exactly one of moe, cv, or rmoe.

rmoe

Target margin of error relative to p, so rmoe = 0.12 asks for a 95 percent interval whose half-width is 12 percent of the proportion. It is moe / p, and therefore fixes the same interval moe does while scaling with the estimate the way cv does. See the precision quantities section of prec_prop(). Specify exactly one of moe, cv, or rmoe.

alpha

Significance level, default 0.05. alpha = 2 * pnorm(-2) gives the multiplier of 2 that the DHS and MICS manuals use in place of 1.96.

N

Population size. Inf (default) means no finite population correction.

deff

Design effect multiplier (> 0). Accounts for the loss of precision from a complex design (clustering, unequal weights) compared to simple random sampling. A DEFF of 1.5 means 50 percent more interviews are needed for the same precision. Estimate from a previous survey, use design_effect() to compute it, or apply a rule of thumb (1.5–2.0 for typical cluster designs). Values < 1 are valid for efficient designs (e.g., stratified sampling with Neyman allocation). A published DEFT is squared first. See varcomp() for that and for removing the published survey's weighting loss.

resp_rate

Expected response rate among eligible units, in (0, 1]. Default 1 (no adjustment). The required sample size is inflated by 1 / resp_rate. Estimate from response rates observed in similar surveys in the same population. See the nonresponse section of svyplan-package for what the rate counts and what this adjustment does and does not claim.

eligibility_rate

Share of issued units in scope, such as dwellings found occupied, in (0, 1]. Default 1. With a finite N, the population in scope is N * eligibility_rate. See the nonresponse section of svyplan-package.

eligible_per_unit

Eligible units per sampled unit, a positive number, default 1. In a household survey of married women it is the average number of married women per household, and it can exceed 1. n and N stay in sampled units, while the precision is computed on the eligible respondents out of N * eligibility_rate * eligible_per_unit eligible units, which must exceed 1 when N is finite. See Details.

method

One of "wald" (default), "wilson", "logodds", or "beta".

df

Degrees of freedom of the variance estimator the planned design will have, typically sampled PSUs minus strata, and available from design_df() where the plan is in hand. It widens the interval for a variance estimated from few clusters. NULL (default) applies no adjustment, treating the variance as known. See Details, including for what an unset df means under method = "beta", where the reference is the value a simple random sample would have rather than infinity.

min_cases

Minimum expected number of positive cases the sample must yield, an alternative constraint to precision for a rare outcome. The returned n satisfies both. NULL (default) sizes on precision alone. See Details.

plan

Optional svyplan() object providing design defaults.

Value

A svyplan_n object with type = "proportion":

n

Required sample size, continuous and gross. It already carries deff and the 1 / resp_rate inflation, so it counts the units to release, not the completed interviews. $n and as.double() keep the unrounded value, which is what makes the round trip through prec_prop() exact, whereas print() and as.integer() round it up to the whole units you would field. Take the field figure from as.integer() rather than from $n.

se, moe, cv, rmoe

Precision the design achieves at that n, the same values prec_prop() reports for the same inputs. se is the sampling standard error and cv is se / p, so both are the same under all four methods. moe is half the length of the interval the chosen method builds, which equals q * se under "wald" alone, with q defined in Details. Where confint() truncates a Wald interval at 0 or 1, moe stays q * se and exceeds half the reported width (see Details). For the three asymmetric methods it is not an offset from either limit, so read the limits with confint(). rmoe is moe / p, so a target stated as a relative margin of error reads back in the units it was stated in.

method

The interval method used.

expected_cases

Positive cases the design expects to yield, n * resp_rate * eligibility_rate * eligible_per_unit * p.

binding

Which constraint set the size, "precision" or "min_cases". NULL when no min_cases was given, there being nothing for precision to bind against.

params

The validated inputs (p, alpha, N, deff, resp_rate, df, min_cases when given, and whichever of moe, cv, or rmoe was the target). predict(), confint() and the prec_prop() round trip read the design back from here.

Details

Four confidence interval methods are available:

  • Wald ("wald"): Standard normal approximation (Cochran, 1977, Ch. 3). Supports moe, rmoe, and cv targets, with optional finite population correction.

  • Wilson ("wilson"): Wilson (1927) score interval. moe and rmoe targets only, with optional finite population correction.

  • Log-odds ("logodds"): Log-odds (logit) transform interval. moe and rmoe targets only, with optional finite population correction.

  • Beta ("beta"): Korn-Graubard (1998) interval, the Clopper-Pearson limits evaluated at the effective sample size, optionally widened for the degrees of freedom of the variance estimator via df. moe and rmoe targets only, with optional finite population correction. This is the method survey::svyciprop(method = "beta") reports, and the two agree exactly on a design where they see the same effective size.

All four read one variance, \(\mathrm{deff}\,\frac{N}{N-1}\,p(1-p)(1/n-1/N)\). They differ only in the interval built around it, so they agree closely whenever the margin of error is small and diverge only where the normal approximation itself is doubtful. In practice the choice matters for a rare or near-universal outcome and is immaterial otherwise. See the section below.

The design effect and the finite population correction enter every method through the effective sample size \(n_\mathrm{eff}=n_\mathrm{net}/(\mathrm{deff}\cdot\mathrm{fpc})\), the size at which an infinite-population simple random sample would carry the same variance. For Wald this reproduces the usual closed form exactly, and for the other three it is the approximation that keeps deff and N acting on the interval as they act on the variance. A census therefore yields a zero margin of error under all four.

The Wilson, log-odds, and beta intervals are not symmetric about p, so the reported moe is half the interval's length rather than an offset either limit sits at. For the limits themselves, use confint(), which returns the interval the chosen method actually produces. The gap matters most for the beta method at a rare outcome, where the upper arm can be several times the lower one.

Choosing a method

Reach for Wald unless you have a reason not to. It is the only method that also solves a cv target, and it is what survey texts and sample size tables conventionally report. moe and rmoe targets are available under all four.

How much the choice costs depends on the sample size, and the four methods converge on each other slowly. With alpha = 0.05, deff = 1, N = Inf, resp_rate = 1, no supplied df, and p from 0.1 to 0.9, the widest and narrowest margins of error differ by 8.2 percent at n = 100, 3.8 percent at 500, 2.7 percent at 1000, and 1.2 percent at 5000. Below a few thousand the choice is worth a moment. At larger survey sizes its effect on required size is often modest over this range.

The case that decides it is a rare or near-universal outcome. As p approaches 0 or 1 the Wald interval loses coverage and can extend past 0 or 1. confint() truncates it at the boundary when it does, and moe is then no longer half the reported interval's length. Wilson and log-odds lie strictly inside \((0, 1)\) and beta inside \([0, 1]\), all three by construction, so none of them needs that truncation. Planning a survey for a 2 percent prevalence is the case that justifies method = "wilson", since the score interval keeps its nominal coverage far better there.

Log-odds is the narrower case again. It respects the parameter space like Wilson but keeps the estimate at the center of the interval on the logit scale. Back-transforming its limits gives an interval for the proportion, or equivalently for its odds. It is not an interval for an odds ratio and does not size a logistic regression. Prefer Wilson unless reporting on the logit or odds scale is itself useful.

Reach for "beta" when the expected number of outcomes in the category nearest a boundary is small in absolute terms, not merely when p is numerically close to a boundary. Rare-outcome domain estimates in a clustered survey are the standard case. Near p = 1, apply the same reasoning to expected negative outcomes. Beta is the widest over most of the range, and so the most demanding to plan for, but not everywhere. For a very rare outcome at a small sample, log-odds is wider still. Nor is it the only method that answers to a variance estimated from few clusters. All four read df through the same t quantile and widen by it, so df alone is not a reason to choose beta.

A note on where the methods bind. For sizing, the sizes differ by the measured few-percent amounts over the range above. That does not make the interval methods inferentially interchangeable. When the reported interval's width is the binding requirement, size under the method you will report. Compare methods with separate n_prop() or prec_prop() calls, or with separately constructed objects. predict() varies the permitted planning parameters while keeping an object's method fixed. For assessing an achieved design, method choice can dominate when realized counts are sparse or the estimate lies near a boundary.

A minimum expected number of cases

For a rare outcome in a small domain the constraint that actually binds is often not a margin of error but an expected count. An indicator may require 30 positive cases on average, or a subgroup analysis may need a planning floor for its expected events. min_cases states that requirement directly. The size it demands is $$n_\mathrm{cases} = \mathrm{min\_cases} / (p \cdot \mathrm{resp\_rate} \cdot \mathrm{eligibility\_rate} \cdot \mathrm{eligible\_per\_unit}),$$ and the result is the larger of that and the size precision asks for. Thus the count floor holds in expectation. The realized count is random, and the calculation does not control the probability of observing at least min_cases. Such an assurance constraint is outside this function's scope. binding says which planning constraint decided, and expected_cases reports the expected positive count either way.

deff does not enter this size, and that is deliberate rather than an omission. A design effect describes how precisely the proportion is estimated and the number of positive cases that turn up in a sample of \(n\) is a property of the sample size and the prevalence alone. The response rate does enter, because the cases are counted among respondents and the returned n is gross, on the same footing as every other size the package reports.

expected_cases is reported on every proportion result, with or without min_cases. It is the expected number of positive respondents after the response-rate adjustment, not an observed count or an assurance probability. It does not incorporate deff and is not an effective event count. It helps interpret a rare positive outcome, but it is not a complete interval diagnostic. Near p = 1, inspect the expected negative count instead. The min_cases constraint acts only on expected positive cases.

Finite population correction

Setting N to a finite value reduces the required sample size when the sampling fraction (n/N) is non-negligible. As a rule of thumb, FPC has little effect when n/N < 5 percent. The Wald FPC uses the Cochran (1977, Ch. 3) form with an N/(N-1) factor to account for the Bernoulli finite-population variance. This differs from n_mean(), where no N/(N-1) adjustment is needed because the variance is already defined on N-1 degrees of freedom.

Eligible units per sampled unit

A household survey samples households and measures persons, such as the married women or the children under five in each sampled household. eligible_per_unit is their average number per household. The sample size and N stay in households. The precision is computed on n * resp_rate * eligibility_rate * eligible_per_unit eligible respondents out of N * eligibility_rate * eligible_per_unit eligible persons, so the sampling fraction is the household one, n * resp_rate / N. expected_cases counts eligible respondents with the trait.

With N = Inf, a rate at or below 1 gives the same n as passing resp_rate * eligible_per_unit as the response rate. With a finite N that folded rate understates the sampling fraction, so it asks for slightly more households.

A survey that reports households selected, occupied and interviewed and an individual response rate, as DHS and MICS do, gives the four inputs directly. eligibility_rate is the households occupied over the households selected, resp_rate the published household response rate times the individual rate, and eligible_per_unit the eligible persons per interviewed household (see the nonresponse section of svyplan-package). Folding the individual rate into eligible_per_unit instead gives the same n only at N = Inf, and a slightly smaller one with a finite N.

Above 1, several eligible persons come from each sampled household and resemble each other. deff then carries that correlation, as a design effect published at the person level does. For an outcome the whole household shares, such as poverty counted per person, the precision is closer to that of the household count than this calculation implies.

Degrees of freedom

Write \(q\) for the interval quantile. By default \(q = \Phi^{-1}(1-\alpha/2)\), which treats the variance as known. Supplying df instead gives \(q = t_{1-\alpha/2}(\mathrm{df})\).

Supplying df says the variance will be estimated from a design with that many degrees of freedom, and switches the quantile to \(t_{1-\alpha/2}(\mathrm{df})\). It is opt-in rather than derived. In n_cluster() the df depends on the PSU count being solved for, so an automatic version would need a fixed point. Read it off a plan you already have with design_df(), or pass a count directly.

The three interval methods and the Korn-Graubard one apply that quantile widening by different routes. "wald", "wilson" and "logodds" substitute the quantile in the half-width. "beta" instead scales the effective sample size by the squared ratio of the two t quantiles (Korn and Graubard, 1998, eq. 2.2), which is the same widening expressed on the sample size rather than on the interval.

The two routes differ in what an unset df means, because they differ in what they measure it against. For the three substituting methods NULL and Inf are the same statement, the normal quantile. For "beta" the reference is the value a simple random sample of the same size would have, so NULL is equivalent to df = n - 1, and df = Inf claims more degrees of freedom than an SRS has and narrows the interval accordingly.

With df set, "beta" sizes a sample of at least df + 1 respondents, the fewest a design with df degrees of freedom can have, and never fewer than about 5 (7 at alpha = 0.01). Below that size the adjusted interval narrows as the sample shrinks, so no smaller size is a solution. A margin wide enough to be met at that floor returns the floor, and prec_prop() at that size reports the narrower margin it achieves.

The reported se is the sampling standard error from the common variance above, and cv = se / p. Neither depends on method, alpha, or df. The margin of error reads the interval construction and is therefore method-specific. Under "wald", moe = q * se. The other three methods are asymmetric, so their half-length has no universal q * se identity.

df is deliberately absent from the power functions. There the quantile is a normal deviate for an alternative rather than an interval half-width, and a t-based power calculation is a different procedure, not a substituted quantile.

When called on a svyplan_prec object, parameters are extracted from the stored result. Any argument of the default method (e.g. method, deff, N) can be overridden through .... Unknown argument names are an error. Passing a different method evaluates the stored precision target under that formula. The round-trip will not be exact because the precision was computed under the original method.

References

Cochran, W. G. (1977). Sampling Techniques (3rd ed.). Wiley.

Wilson, E. B. (1927). Probable inference, the law of succession, and statistical inference. Journal of the American Statistical Association, 22(158), 209–212.

Brown, L. D., Cai, T. T. and DasGupta, A. (2001). Interval estimation for a binomial proportion. Statistical Science, 16(2), 101–133. The coverage comparison that motivates preferring the score interval for a rare or near-universal outcome.

Korn, E. L. and Graubard, B. I. (1998). Confidence intervals for proportions with small expected number of positive counts estimated from survey data. Survey Methodology, 24(2), 193–201.

Clopper, C. J. and Pearson, E. S. (1934). The use of confidence or fiducial limits illustrated in the case of the binomial. Biometrika, 26(4), 404–413.

See also

n_mean() for continuous variables, n_cluster() for multistage designs, n_multi() for several indicators or for one indicator in several domains, prec_prop() for the inverse.

Other sample size and precision functions: n_mean(), n_ratio(), prec_mean(), prec_prop(), prec_ratio()

Examples

# Wald, absolute margin of error
n_prop(p = 0.3, moe = 0.05)
#> Sample size for proportion (wald)
#> n = 323 (p = 0.30, moe = 0.050, deff = 1)
#> expected cases = 96.8

# Wald, target CV with finite population
n_prop(p = 0.5, cv = 0.10, N = 10000)
#> Sample size for proportion (wald)
#> n = 100 (p = 0.50, cv = 0.100, deff = 1)
#> expected cases = 49.5

# Wilson score interval
n_prop(p = 0.1, moe = 0.03, method = "wilson")
#> Sample size for proportion (wilson)
#> n = 388 (p = 0.10, moe = 0.030, deff = 1)
#> expected cases = 38.7

# Korn-Graubard interval for a rare outcome, and the asymmetric limits
# it implies
rare <- n_prop(p = 0.02, moe = 0.01, method = "beta")
confint(rare)
#>       2.5 %     97.5 %
#>  0.01173814 0.03173814

# The same, allowing for a variance estimated from 30 PSUs in 5 strata
n_prop(p = 0.02, moe = 0.01, method = "beta", df = 25)
#> Sample size for proportion (beta)
#> n = 949 (p = 0.02, moe = 0.010, deff = 1)
#> expected cases = 19.0

# A margin this wide is met by the fewest respondents 25 df allow
n_prop(p = 0.5, moe = 0.4, method = "beta", df = 25)
#> Sample size for proportion (beta)
#> n = 26 (p = 0.50, moe = 0.400, deff = 1)
#> expected cases = 13.0

# With design effect and response rate
n_prop(p = 0.3, moe = 0.05, deff = 1.5, resp_rate = 0.8)
#> Sample size for proportion (wald)
#> n = 606 gross (net: 485) (p = 0.30, moe = 0.050, deff = 1.50, resp_rate = 0.80)
#> expected cases = 145.2

# At least 30 expected cases of a rare outcome, whatever precision asks
rare <- n_prop(p = 0.02, moe = 0.02, min_cases = 30)
rare$binding
#> [1] "min_cases"
rare$expected_cases
#> [1] 30

# MICS-style relative margin of error, 12% of the proportion
n_prop(p = 0.2, rmoe = 0.12, deff = 1.5, resp_rate = 0.9)
#> Sample size for proportion (wald)
#> n = 1779 gross (net: 1601) (p = 0.20, rmoe = 0.120, deff = 1.50, resp_rate = 0.90)
#> expected cases = 320.1

# Households to sample for married women, 0.41 per household
n_prop(p = 0.28, cv = 0.05, deff = 2.5, resp_rate = 0.9,
       eligible_per_unit = 0.41)
#> Sample size for proportion (wald)
#> n = 6969 gross (eligible respondents: 2572) (p = 0.28, cv = 0.050, deff = 2.50, resp_rate = 0.90, eligible_per_unit = 0.41)
#> expected cases = 720.0

# From a report's household table: 96% of selected dwellings occupied,
# 94% of occupied households and 93% of eligible women interviewed, and
# 1.13 women aged 15 to 49 per interviewed household
n_prop(p = 0.22, moe = 0.04, deff = 1.5, N = 6600,
       eligibility_rate = 0.96, resp_rate = 0.94 * 0.93,
       eligible_per_unit = 1.13)
#> Sample size for proportion (wald)
#> n = 600 gross (eligible respondents: 569) (p = 0.22, moe = 0.040, deff = 1.50, resp_rate = 0.87, eligibility_rate = 0.96, eligible_per_unit = 1.13)
#> expected cases = 125.2