Compute the required sample size for estimating a population mean with a specified margin of error or coefficient of variation.
Usage
n_mean(var = NULL, ...)
# Default S3 method
n_mean(
var = NULL,
...,
sd = NULL,
mu = NULL,
moe = NULL,
cv = NULL,
rmoe = NULL,
alpha = 0.05,
N = Inf,
deff = 1,
resp_rate = 1,
df = NULL,
plan = NULL
)
# S3 method for class 'svyplan_prec'
n_mean(var, ..., moe = NULL, cv = NULL, rmoe = NULL)Arguments
- var
For the default method: population variance \(S^2\). Estimate from a pilot study, a previous survey, or published data for a similar population. When uncertain, use a conservative (larger) estimate to avoid under-sizing. For
svyplan_precobjects: a precision result fromprec_mean().- ...
Additional arguments passed to methods. Unused arguments are rejected.
- sd
Population standard deviation, an alternative spelling of
var. Supply exactly one ofvarorsd. Stratum frames and published survey reports usually quote standard deviations.- mu
Population mean. Required when
cvorrmoeis specified, both being defined against the mean.- moe
Desired margin of error, the half-width of the confidence interval, in the same units as the variable. For example, if measuring income in dollars,
moe = 50means the 95 percent CI should be no wider than +/- $50. Specify exactly one ofmoe,cv, orrmoe.- cv
Target coefficient of variation (relative standard error). For example,
cv = 0.05means the standard error should be at most 5 percent of the estimate. Usecvwhen you want precision to scale with the estimate (common in economic surveys). Usemoewhen you want a fixed absolute precision. Requiresmu. Specify exactly one ofmoe,cv, orrmoe.- rmoe
Target margin of error relative to
mu, sormoe = 0.05asks for a 95 percent interval whose half-width is 5 percent of the mean. It ismoe / abs(mu), taken on the magnitude so that a negative mean gives a positive margin of error, and it requiresmu. Specify exactly one ofmoe,cv, orrmoe.- alpha
Significance level, default 0.05.
- N
Population size.
Inf(default) means no finite population correction. Setting a finiteNreduces the required sample size when the sampling fraction is non-negligible (rule of thumb: matters when n/N > 5 percent).- deff
Design effect multiplier (> 0). See
n_prop()for guidance on estimating DEFF. 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.- df
Degrees of freedom of the variance estimator the planned design will have, typically sampled PSUs minus strata, and available from
design_df(). It switches the interval quantile from normal to t.NULL(default) applies no adjustment. Seen_prop()for the full account.- plan
Optional
svyplan()object providing design defaults.
Value
A svyplan_n object with type = "mean":
nRequired sample size, continuous and gross. It already carries
deffand the1 / resp_rateinflation, so it counts the units to release, not the completed interviews.$nandas.double()keep the unrounded value, which is what makes the round trip throughprec_mean()exact;print()andas.integer()round it up to the whole units you would field. Take the field figure fromas.integer()rather than from$n.se,moe,cv,rmoePrecision the design achieves at that
n, the same valuesprec_mean()reports for the same inputs.moeisqnorm(1 - alpha / 2) * se, and the interval is symmetric about the mean.cvandrmoeareNAunlessmuwas supplied, both needing a mean to be relative to.paramsThe validated inputs (
var,alpha,N,deff,resp_rate,muwhen given, and whichever ofmoe,cv, orrmoewas the target). Dispersion is always stored asvar, including when you suppliedsd.predict(),confint()and theprec_mean()round trip read the design back from here.
Details
Two modes:
MOE mode:
n = deff * z^2 * var / (moe^2 + deff * z^2 * var / N). Anrmoetarget enters here asmoe = rmoe * abs(mu).CV mode: Computes
CVpop = sqrt(var) / abs(mu), thenn = deff * CVpop^2 / (cv^2 + deff * CVpop^2 / N).
deff appears in the denominator as well as the numerator: it inflates
the variance the finite population correction is then applied to, rather
than scaling a size already corrected. The two coincide only at infinite
N. For var = 100, moe = 2, N = 100 and deff = 2, inflating
afterwards would give 97.98 against the correct 65.76.
Finite population correction
Setting N to a finite value reduces the required sample size when
the sampling fraction (n/N) is non-negligible (rule of thumb: matters
when n/N > 5 percent). Unlike n_prop(), no N/(N-1) adjustment is
needed because var is already defined on N-1 degrees of freedom.
See n_prop() for a fuller explanation of FPC.
All methods use the normal (z) quantile. This is standard for survey sampling where the sample size is large enough for the CLT to apply.
Sample size for a total
A separate n_total() function is not needed because the sample size
for a population total \(\hat{Y} = N \bar{y}\) is identical to
the sample size for the mean. The two are related by a factor of
\(N\):
CV mode: \(CV(\hat{Y}) = CV(\bar{y})\), so the required sample size is the same. Use
n_mean(var, mu, cv)directly.MOE mode: \(MOE(\hat{Y}) = N \times MOE(\bar{y})\), so divide the target MOE for the total by \(N\):
n_mean(var, moe = moe_total / N, N = N).
See Examples below.
References
Cochran, W. G. (1977). Sampling Techniques (3rd ed.). Wiley.
Valliant, R., Dever, J. A., and Kreuter, F. (2018). Practical Tools for Designing and Weighting Survey Samples (2nd ed.). Springer.
See also
n_prop() for proportions, n_cluster() for multistage designs,
n_multi() for multiple indicators, prec_mean() for the inverse.
Other sample size functions:
n_alloc(),
n_change(),
n_cluster(),
n_multi(),
n_multi_cluster(),
n_panel(),
n_pooled(),
n_prop(),
n_twophase()
Examples
# MOE mode
n_mean(var = 100, moe = 2)
#> Sample size for mean
#> n = 97 (var = 100.00, moe = 2.000, deff = 1)
# CV mode
n_mean(var = 100, mu = 50, cv = 0.05)
#> Sample size for mean
#> n = 16 (var = 100.00, cv = 0.050, deff = 1)
# Relative MOE mode: interval half-width 5 percent of the mean
n_mean(var = 100, mu = 50, rmoe = 0.05)
#> Sample size for mean
#> n = 62 (var = 100.00, rmoe = 0.050, deff = 1)
# With FPC, design effect, and response rate
n_mean(var = 100, moe = 2, N = 5000, deff = 1.5, resp_rate = 0.8)
#> Sample size for mean
#> n = 176 gross (net: 141) (var = 100.00, moe = 2.000, deff = 1.50, resp_rate = 0.80)
## Sample size for a total
# Target: estimate total income (N = 10000) with MOE of 500000
n_mean(var = 2500, moe = 500000 / 10000, N = 10000)
#> Sample size for mean
#> n = 4 (var = 2500.00, moe = 50.000, deff = 1)
# CV mode: identical for means and totals
n_mean(var = 2500, mu = 300, cv = 0.05, N = 10000)
#> Sample size for mean
#> n = 12 (var = 2500.00, cv = 0.050, deff = 1)