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,
  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.

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).

resp_rate

Expected response rate, 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 this adjustment does and does not claim.

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 * 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}),$$ 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.

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.

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 multiple indicators, prec_prop() for the inverse.

Other proportion, mean and ratio 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

# 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