Weighting and Design
You have survey data from a sample that does not mirror the population, and this guide takes you through the full fix: base weights from the sample design, a nonresponse adjustment, and calibration to known population totals, ending with weighted estimates and the standard errors that belong with them. In the worked example, weighting moves the headline estimate from 36.0% to 34.2%. Because the data are simulated, the true value is known: 34.1%. This draw shows a larger-than-typical correction: over repeated surveys, the unweighted estimate is off by about 0.8 points on average, and weighting removes nearly all of it.
When to use this, and when not to
Weight your data when the sample was drawn with known, unequal selection probabilities, when response rates differ across groups you can identify, or when your sample's mix on variables like age and sex does not match a population you know from a census or register. If any of those three holds and you report unweighted numbers, your estimates describe your respondents, not your population.
Weighting is the wrong choice in three common situations. First, if your sample is a convenience sample with no design and no population totals to calibrate to, weights manufactured from the sample itself cannot repair the selection problem; the guide on weighting opt-in samples in this series covers what you can claim in that case. Second, if a cell in your data has nobody in it, no weight fixes a group that was never sampled; you have a coverage problem, not a weighting problem. Third, if your analysis is a model of relationships rather than a population total or mean, read the guide on regression standard errors (classical, robust, and design-based) before you decide how much of this pipeline you need.
What you need
| Item | Requirement |
|---|---|
| Data shape | One row per sampled case, respondents and nonrespondents together, with a response indicator |
| Design variables | The stratum (or selection probability) for every sampled case, plus the population size of each stratum |
| Adjustment variables | Variables recorded for respondents and nonrespondents alike (frame or sampling data), used to form nonresponse classes |
| Calibration targets | Population totals for each calibration margin, all summing to the same population total |
| Outcome variables | Recorded for respondents only; that gap is what the nonresponse adjustment addresses |
| Minimum size | Enough respondents in every adjustment cell that one person does not carry a cell; 20 or more per cell is a workable floor |
The method rests on two assumptions. Selection probabilities are known and positive for everyone in the population. Within each nonresponse class, the people who responded are similar to the people who did not, on the outcomes you measure. The second assumption cannot be tested from your data; it is the reason you form classes from variables tied both to responding and to the outcome.
The worked example
The dataset is simulated, and the package includes the script that generated it, so every number below can be checked. The script builds the whole population first, all 60,000 adults, so the true values are known and printed here: 34.1% of the population visited a public library in the past month (20,457 people), and mean annual income is $49,369. A real survey never gets to see its truth; this one does, and the stages below are judged against it.
You surveyed adults in a state of 60,000 people across four regions. The regions differ in more than size: the North skews young, the Coast skews old, and library use and income differ by region as well as by age. You sampled 120 adults per region, the same number everywhere, even though the regions hold between 12,000 and 20,000 people. Equal allocation buys you equal precision per region; it also guarantees that your raw sample overrepresents the small regions, which is exactly what base weights correct. Of the 480 people sampled, 395 responded, a response rate of 82.3% (weighted: 83.0%). You measured two outcomes for respondents: whether they visited a public library in the past month, and annual income. This draw was chosen, under a selection rule stated in the verification package, to show a clear correction and one adjustment class below the size floor; judge the method by the repeated-draw results later in this guide, not by this one draw.
Stage 1: base weights. Each sampled person represents their region's population divided by the number sampled there. A Central respondent represents 20,000 / 120 = 166.67 people. A North respondent represents 12,000 / 120 = 100 people. Check this by hand: it is one division per region.
Table 1. The design and the base weights.
| Region | Population | Sampled | Base weight |
|---|---|---|---|
| North | 12,000 | 120 | 100.00 |
| Central | 20,000 | 120 | 166.67 |
| South | 16,000 | 120 | 133.33 |
| Coast | 12,000 | 120 | 100.00 |
| Total | 60,000 | 480 |
Base weights over all 480 sampled cases sum to exactly 60,000, the population. Over the 395 respondents alone they sum to 49,800. The missing 10,200 is the population share of the 85 people who never answered, and stage 2 hands it back.
Stage 2: nonresponse adjustment. Group the sample into classes where response behavior differs. Here you use region crossed with age group, twelve classes, because younger adults responded at lower rates in every region. Inside a class, the adjustment factor is the base-weight sum of everyone sampled divided by the base-weight sum of the respondents. Check one by hand: in the North, age 18 to 34 class, 47 people were sampled at a base weight of 100 each, a base-weight sum of 4,700; 27 responded, a sum of 2,700; the factor is 4,700 / 2,700 = 1.7407. Each young North respondent's weight grows by about 74%, and that respondent now also stands in for the nonrespondents in their class.
Table 2. Nonresponse classes and adjustment factors.
| Class | Sampled | Respondents | Base sum, sampled | Base sum, respondents | Factor |
|---|---|---|---|---|---|
| Central, 18-34 | 28 | 25 | 4,666.67 | 4,166.67 | 1.1200 |
| Central, 35-54 | 47 | 40 | 7,833.33 | 6,666.67 | 1.1750 |
| Central, 55+ | 45 | 45 | 7,500.00 | 7,500.00 | 1.0000 |
| Coast, 18-34 | 23 | 15 | 2,300.00 | 1,500.00 | 1.5333 |
| Coast, 35-54 | 35 | 31 | 3,500.00 | 3,100.00 | 1.1290 |
| Coast, 55+ | 62 | 57 | 6,200.00 | 5,700.00 | 1.0877 |
| North, 18-34 | 47 | 27 | 4,700.00 | 2,700.00 | 1.7407 |
| North, 35-54 | 39 | 34 | 3,900.00 | 3,400.00 | 1.1471 |
| North, 55+ | 34 | 32 | 3,400.00 | 3,200.00 | 1.0625 |
| South, 18-34 | 43 | 26 | 5,733.33 | 3,466.67 | 1.6538 |
| South, 35-54 | 43 | 34 | 5,733.33 | 4,533.33 | 1.2647 |
| South, 55+ | 34 | 29 | 4,533.33 | 3,866.67 | 1.1724 |
After this stage the respondents' weights sum to 60,000 again. One class deserves a hard look: Coast, age 18 to 34, where only 15 of 23 sampled people responded. That is below the 20-per-cell floor set out above, and the Checks and pitfalls section returns to it with a comparison against collapsed classes.
Stage 3: calibration by raking. After the nonresponse adjustment, the weighted sample runs slightly heavy on men and on adults under 35 relative to the state's known totals; raking corrects both. You know the population margins: 30,900 women and 29,100 men; 16,800 adults aged 18 to 34, 21,000 aged 35 to 54, and 22,200 aged 55 and over. Raking scales the weights up and down in turns, first matching the sex margin, then the age margin, then sex again because the age pass disturbed it, until both margins hold at once. Every respondent keeps a positive weight, nobody is dropped, and the final weights reproduce both margins and the 60,000 total exactly. Note what raking does not do: it matches the margins one variable at a time, not the joint distribution. The weighted share of young women in the South is whatever the two margins imply, not a number you supplied.
Table 3. The weights at each stage (respondents, n = 395).
| Stage | Sum | Smallest | Largest | CV |
|---|---|---|---|---|
| Base | 49,800.00 | 100.00 | 166.67 | 0.226 |
| After nonresponse adjustment | 60,000.00 | 106.25 | 220.51 | 0.241 |
| After raking (final) | 60,000.00 | 106.77 | 217.39 | 0.229 |
Stage 4: estimates. Apply the final weights to the outcomes, and carry the design (stratified sampling) into the standard errors. One decision matters here. Because the weights come from a calibration, the standard errors in this guide are calibration-aware: the variance calculation replaces each outcome by its residuals from a regression on the calibration variables (sex and age group), which credits the calibration for the variation it explains. Treating the final weights as if they had been fixed in advance skips that credit and overstates the standard error when the calibration variables predict the outcome. For income, where age separates lower earners from higher earners sharply, the fixed-weights standard error is $1,113 against the calibration-aware $991, about 11% wider. For the library rate, where age and sex predict the outcome weakly, the two nearly agree: 0.0240 against 0.0239. Analysis Studio computes the calibration-aware version, and so does the survey package in R when you estimate from a raked design.
Table 4. Estimates under each weighting stage, with the population truth.
| Estimate | Unweighted | Base | Nonresponse-adjusted | Final (raked) | Population truth |
|---|---|---|---|---|---|
| Visited a library last month | 0.3595 | 0.3501 | 0.3403 | 0.3416 | 0.3410 |
| Mean annual income | not reported | $49,619 | $48,922 | $48,980 | $49,369 |
With the final weights: 34.2% of adults visited a public library in the past month, standard error 0.0239, 95% confidence interval 0.2963 to 0.3900, built on the logit scale so it can never run below 0 or above 1 (the linear construction gives 0.2946 to 0.3885). As a total, that is an estimated 20,495 library visitors, standard error 1,433, against a true count of 20,457. Mean annual income is $48,980, standard error $991, 95% confidence interval $47,030 to $50,929, against a true mean of $49,369. Both intervals cover their true values. Read the stage columns as the lesson: the unweighted 0.3595 is the biased number. In this population the base weights change little on average, because the two oversampled small regions happen to offset each other (the North runs low on library use, the Coast runs high), so the 0.9-point move they make in this draw is mostly sampling luck; they are still required, because in most populations the regions do not cancel. The nonresponse stage does the heavy lifting on the age skew in who answered, and raking refines rather than reinvents the estimate. If your stages ever swing an estimate wildly, treat that as a finding about your data, not a detail.
One worked example is one draw, and a single draw can flatter or embarrass a method by chance. The verification package therefore includes a Monte Carlo script that repeats this whole survey 500 times from the same population. Averaged over the repetitions, the unweighted library estimate is biased by +0.008 and base-weighted income by +$574; after all three stages the average bias is +0.002 and −$32, effectively zero. The calibration-aware 95% intervals cover the truth in 96.2% of repetitions for the library rate (the logit interval of Stage 4) and 93.6% for income, in line with the nominal 95%. Those averages, not the single draw above, are the evidence that the pipeline works.
Doing it in Analysis Studio
Load the sample file, all 480 rows, nonrespondents included, then open the Survey Weighting and Raking module and work through the steps in order.
- Set the starting weights. The sample file already carries each case's base weight in the column base_wt: each region's population divided by the 120 sampled there, the Table 1 values. In the module's Choose variables step, add income_k as a key variable, so the report compares its mean before and after weighting. In Set up the weighting, set Base weights to base_wt and the calibration method to raking. Leave "Match the first margin's total" unticked; the margins in step 4 below already share a total, and the Checks and pitfalls section explains what that option would hide.


- Mark who responded. In the same Set up the weighting step, set the nonresponse adjustment to weighting classes, the response variable to respondent, and the responded level to 1 (395 cases). Respondents carry outcomes; nonrespondents carry design and frame variables only. If your file has already dropped the nonrespondents, stop and restore them, because this stage is computed from the full sample.

- Build the nonresponse adjustment. Set the class variable to region_age, the combined region-and-age-group column, whose twelve levels are the classes. After the run, the report lists each class with its sampled and respondent base-weight sums and the factor, the same figures as Table 2. Read the largest factor (1.7407, North, age 18 to 34) and the thinnest class (Coast, age 18 to 34, 15 respondents) before you accept the adjustment.
- Calibrate. In Add calibration margins, add the two margins as totals: sex (Female 30,900, Male 29,100) and age group (16,800, 21,000, and 22,200). Confirm the targets sum to 60,000, then run. The report shows both margins matched exactly and the final weights summing to 60,000, with a design effect of 1.05 and an effective sample size of 375.


- Put the final weights to work. In the results, choose Use this dataset now. The Studio builds a new version of your data with weight_final added; the 85 nonrespondents carry no final weight, which the data table shows as 85 missing. Then declare the design in the Survey design card: Taylor, weight column weight_final, strata column region. Every analysis module now computes design-based standard errors under that design, instead of treating your respondents as a simple random sample. One caution: the calibration record stays with this session's dataset. If you save the file and reload it later, rerun the weighting module, or expect the wider fixed-weights standard errors.


- Run your estimates. Open Module 1, Descriptive statistics and frequencies, and summarize library and income_k. The report opens with a Checks note: the weight variable weight_final is missing for 85 of 480 cases, and those cases are excluded from design-based analysis. That is the nonrespondents leaving the analysis, by design, and the estimates run on the 395 respondents with calibration-aware standard errors: the income standard error is $991, as in Stage 4. For the library proportion, the Studio builds its interval on the logit scale, the construction Stage 4 uses, so the interval on screen (29.6% to 39.0%) is the interval printed there.


Reading the output
The module's report gives you the weight summary first, and it is worth reading before any estimate. Weights that sum to your population (60,000) confirm the arithmetic closed. A largest-to-smallest ratio of 217.39 to 106.77, about 2.0 to 1, tells you no respondent is carrying an outsized share of the population. The coefficient of variation of the final weights, 0.229, feeds the design effect: Kish's approximation gives 1.0525, an effective sample size of about 375 of your 395 respondents. The design-based calculation for the library estimate gives a design effect of 0.976 and an effective sample size of about 405, slightly better than a simple random sample of the same size. That can happen, and here it should not surprise you: library use differs sharply by region, from 26.5% in the North to 40.8% on the Coast, and stratifying the sample by region removes that between-region variation from the estimate's error. The age margin is not the cause; age and sex predict library use weakly in this population, which is why the two standard errors in Stage 4 nearly agree. Either way you read it, your 395 interviews buy you roughly the precision of 375 to 405 simple-random-sample interviews. The weighting here cost almost nothing, because the sample needed only mild correction.
The plain-language result sentence for your report: an estimated 34.2% of adults in the state visited a public library in the past month (95% CI: 29.6% to 39.0%), based on 395 respondents weighted to the state's population of 60,000. Write yours the same way: the estimate, the interval, the respondent count, and what the weights tie to. If you report the total, it is 20,495 adults (standard error 1,433). For income, report the mean of $48,980 with its interval, $47,030 to $50,929, and name the unit (dollars per year) so nobody mistakes it for a median.
Checks and pitfalls
Check the margins, not just the message that calibration succeeded. Print the weighted totals for every calibration variable and compare them with the targets digit for digit. Margin errors come in two kinds. A typo that keeps the margins summing to the same total (women entered as 29,100 and men as 30,900, the two swapped) still converges, to the wrong population, and nothing warns you. A typo that breaks the total (39,000 entered for 30,900) makes the margins disagree about the population size, raking chases two totals at once, and it does not converge at all; the failure to converge is the warning. If your tool offers to rescale margins to a common total, that option removes this warning; use it only when you know your margins come from sources with different totals. Check every adjustment class for size: the Coast, age 18 to 34 factor of 1.5333 rests on 15 respondents, below the floor of 20 this guide sets, so those 15 people speak for 23 sampled cases and their population share. That is legal arithmetic and a fragile estimate at the same time. The remedy to reach for first is collapsing the classes, here to age group alone, which gives factors of 1.4704, 1.1846, and 1.0674 and no class under 93 respondents. Run through the same raking, the collapsed version estimates 0.3450 for the library rate and $49,149 for mean income, against 0.3416 and $48,980 from the twelve classes (truth: 0.3410 and $49,369). Collapsing costs a little accuracy in this draw, because response really does differ by region within age, and it buys sturdier classes. When a class sits under your floor, run both versions and report whether the headline moves; here it moves the library estimate by about a third of a point, which changes no conclusion. The guide on weight trimming and the design effect covers the next remedy when weights spread too far. Check the weight distribution itself: a largest weight ten times the smallest is a warning that one stage is fighting your data.
The three mistakes this pipeline sees most often. First, deleting nonrespondents before weighting, which makes the nonresponse adjustment impossible and silently converts your survey into a respondent poll. Second, raking to margins that do not sum to the same total (a census table for one variable, a register for another, different reference dates), which forces the algorithm to chase two populations at once. Third, computing standard errors as if the weighted sample were a simple random sample: your intervals come out too narrow, by the design effect, and every comparison you publish inherits the error.
Verify it yourself
The verification package for this guide contains the dataset (data.csv, all 480 sampled cases), the generating script, a Monte Carlo script (monte_carlo.py, 500 repetitions: bias by stage and interval coverage, the numbers quoted in the worked example), reference scripts in R and Python (reference.R, reference.py), and expected_outputs.csv with every computed result printed above, its unit, its location in this guide, and its tolerance. Counts and base weights are exact; estimates are stated to four significant digits, and both scripts must reproduce them within that tolerance. Run either script and it prints PASS or FAIL for each figure.
Package: Download it from the verification package page.
Related guides
- The people who did not answer are still in your data: base weights and nonresponse: stages 1 and 2 in depth, including eligibility and weighting-class versus propensity adjustments.
- Raking to population margins: setup, convergence, and diagnostics: convergence, diagnostics, and what to do when margins fight.
- Weight trimming and the design effect: when the weight spread itself becomes the problem.
The Investor Stats Cheat Sheet
A free three-page PDF: breakeven win rates, stop-loss sizing, volatility drag, reverse valuation, and how to tell a real track record from noise. Plus new tools as they ship.
Comments
No comments yet. Ask the first question.