How this calculation works
Each sampled unit has a positive base weight and one category in every supplied margin. External totals must refer to the same target population.
For each margin category c: wᵢ←wᵢ·Tc/Σj∈c wⱼ; cycle until all margins meet tolerance.A worked example
Symmetric default converges weights[10,10,10,10,10,10], each margin30/30,total60. Structural joint categories retain relative base weight; matching separate margins does not imply joint-cell targets.
Good to know
5–500 unit rows, positive base weights,2–5 categorical margins with2–8 categories each; equal population total across margins;1000 sweeps; reject uncovered positive target cells and return unresolved when joint support prevents convergence; no trimming, continuous calibration, replicate weights or design SE.
Reference: survey author-maintained rake documentation (opens in a new tab) ↗
Define categories and external totals
Each sampled unit has a positive base weight and one category in every supplied margin. External totals must refer to the same target population.
Category encodings must match the target keys exactly. A numerically successful fit to mislabeled categories would still be the wrong calibration.
Compare this with the Survey replicate weight mean total and standard error calculator. Generate adjusted unit weights by iterative proportional fitting to externally supplied category totals while preserving relative base weights within joint cells; report margin residuals and weight concentration. Existing replicate page only consumes supplied weights and explicitly excludes weight generation.
Adjust weights by repeated proportional ratios
Within a category, multiply all current weights by its target total divided by its current weighted total. Cycle through every margin.
A later adjustment can disturb an earlier margin. One sweep is sufficient only in special cases, so convergence is checked against every margin together. The default has six unit rows and two binary categorical margins, each targeting totals30 and30. Starting from equal base weights, the two margins are already balanced in the sample, so every final weight becomes10. Total weight is60 and the Kish effective size remains6. This simple example checks both the target-total scale and preservation of equal weights. In a less balanced sample, rows sharing the same combination of categories may still retain their relative base-weight ratios because every raking adjustment multiplies them by the same factor.
Respect the supported joint distribution
Positive target mass requires sampled support for that category. Even supported separate categories can have incompatible joint structural zeros.
If the available joint cells cannot realize the targets, iteration cannot repair the missing support. Return unresolved convergence rather than inventing units or adding pseudocounts.
Work through the checked default example
Symmetric default converges weights[10,10,10,10,10,10], each margin30/30,total60. Structural joint categories retain relative base weight; matching separate margins does not imply joint-cell targets.
The first proportional adjustment already yields six weights of10. Their total is60, each category margin is30 and weight-only effective sample size is6; no survey design standard error is implied. Each sweep visits one margin at a time. Within a target category, multiply current unit weights by target total divided by current weighted total. Later margins may disturb earlier ones, so sweeps continue until all margins meet the tolerance. This is iterative proportional fitting on sampled categorical support, not fitting a regression to the outcome variable. A target category with positive population but no sampled units cannot be created through weighting. Even when every marginal category appears individually, missing joint combinations can prevent the full set of margins from being simultaneously attainable.
Inspect concentration as well as margin agreement
Weight sums certify calibration totals, while effective sample size and maximum weight reveal concentration. Exact margin agreement does not imply efficient estimation.
Units in the same joint category keep their relative base weights. Raking separate margins does not force unprovided joint-cell totals to their population values.
Keep estimation and uncertainty separate
The output is a new set of unit weights. A weighted outcome mean can use them, but its survey variance also depends on design information.
Raking alone does not manufacture replicate weights or establish a design-based standard error. Carry strata, clusters and replicate conventions through a suitable analysis. Large calibrated weights reveal limited sample support and can sharply reduce effective sample size. The Kish expression (sum w)²/sum w² summarizes weight concentration; it is not a complete survey design effect or a substitute for a design-based standard error. The page does not trim extreme weights or generate replicate weights. Trimming after raking generally breaks the achieved margins and would need an additional calibrated procedure. Record whether the supplied margins are counts or proportions converted to a common population total, since inconsistent totals describe an impossible calibration target rather than a convergence-tolerance problem.
Use genuine population controls
Targets should come from a compatible external count or accepted calibration source. Treating an uncertain target as exact can understate uncertainty later.
Do not trim large calibrated weights silently. Trimming changes margin agreement and requires a new stated optimization or recalibration decision. An iteration count describes numerical convergence, not the quality of the external population controls. Outdated or mismatched controls can force precisely calibrated weights toward the wrong population. Compare the category definitions and sampling frame before relying on a small margin residual. Weighting cannot supply observations for a population subgroup that never entered the sample.
A few questions, answered
Must all margins have the same total?
Yes. They describe the same population size; inconsistent totals cannot all be matched.
Does this fill empty sampled cells?
No. It changes existing unit weights and cannot create representation for an uncovered positive target.
Do matched separate margins imply correct joint counts?
No. Unprovided cross-classified population totals are not imposed.
Is the resulting effective sample size a survey SE?
No. It is a weight-concentration diagnostic, not a substitute for the sampling design variance.