view source

Survey Analysis: Weighting, Margin of Error, NPS

skill

Review a questionnaire and analyze survey results: weighting, margin of error, NPS intervals, Likert scales and disclosure. Use for survey data.

Apache-2.0 Python 3 with pandas, scipy and statsmodels, or uv to fetch them. No network access needed.

agents that use this skill

instructions

Overview

A survey number is an estimate with an error, made from people who chose to answer. This skill covers checking the questions, stating who answered, weighting, computing the error that goes with each figure, comparing groups without inflating false positives, and disclosing the method. The deliverable is a set of estimates, each with an interval and an unweighted base, plus a method note a reader could use to judge them.

Mental model

  • Sampling error shrinks with sample size. Nonresponse and coverage error do not, and no formula captures them; only the method note and honest wording can.
  • Weighting pulls the sample toward known population shares. It reduces bias on the weighted variables and increases variance, so the usable sample is smaller than the count of completes.
  • Likert answers are ordered categories. The gap between agree and strongly agree is not known to equal the gap between neutral and agree.
  • A percentage without its base is not a finding.

Rules

Review the questions first

FaultExampleFix
LeadingA question that adds a consequence or a loaded phrase. Pew found support for military action fell from 68% to 43% when the question added a casualty clauseNeutral wording, same wording for every group
Double-barreled"Confidence in handling domestic and foreign policy"One idea per question; split it
Unbalanced scaleMore positive than negative options, or labels that differ in strengthEqual numbers of options on each side, labeled symmetrically, a neutral midpoint when neutral is real
Agree-disagree formatInvites acquiescence, more among less educated respondents and with an interviewerAsk a forced choice between two statements
Order effectsOptions always listed best to worstRotate or reverse the order for part of the sample

Return the list of faulty questions with a rewrite for each, before analysis starts. Results from a faulty question carry a flag in the report.

Sample and nonresponse

  • Record the frame, the selection method, the mode, the dates, completes, and the response rate with its definition, using the AAPOR standard disposition codes. Report unweighted sizes for every subgroup shown.
  • Compare respondents with known population shares on age, sex, region and education. A gap on a variable that predicts the answers is a bias risk to state, even after weighting.

Weighting and the design effect

Raking (iterative proportional fitting) adjusts weights until the weighted shares match population margins, repeating over the variables until all agree. It needs only the marginal shares for each variable. With targets as a dict of variable name to a Series of population shares by category:

text
df["w"] = 1.0
for _ in range(50):                         # stop earlier once the shares stop moving
    for var, target in targets.items():
        current = df.groupby(var).w.sum() / df.w.sum()
        df["w"] *= df[var].map(target / current)

The Kish design effect is one plus the squared coefficient of variation of the weights, as Pew reports it. The effective sample size is n divided by it. Pew's example: 1,503 completes with a design effect of about 1.4 act like about 1,071. Use the effective size in every margin and test:

text
deff = 1 + df.w.var(ddof=0) / df.w.mean() ** 2
neff = len(df) / deff                      # same as sum(w)**2 / sum(w**2)
moe = 1.96 * (0.25 / neff) ** 0.5          # at 50%, 95% level

After raking, check that weighted shares equal the targets and look at the range of the weights. Report the design effect.

Margin of error and small bases

  • The margin quoted for one share does not cover a gap between two shares. For two answers in the same sample the margin on the gap is roughly double (Pew). For two independent groups or waves of similar size it is about 1.4 times one margin, the square root of two.
  • A subgroup of 160 respondents has a margin near eight points for one share (Pew). For subgroup shares, use the Wilson interval from statsmodels (proportion_confint with method="wilson"); it returns the lower and upper bounds.
  • Below a base you set in advance, show the count and suppress the percentage. Say the base in the method note.

Net Promoter Score with its interval

NPS is the percent of promoters minus the percent of detractors. Score each answer +1 (promoter), 0 (passive) or -1 (detractor). With p the share of promoters and d the share of detractors, NPS is (p - d) times 100, the variance of one answer is p + d - (p - d)^2, and the 95% margin is 1.96 times the square root of variance over n, times 100, where n is the effective sample size for weighted data. Check on 52 promoters, 28 passives and 20 detractors: NPS 32, margin 15.4 points. A 10-point difference between two quarters of 100 answers each is inside the noise. Compare two NPS values by the interval of their difference, not by looking at two numbers.

Likert answers

Report the full distribution and the top-box share (agree plus strongly agree), with intervals. Compare groups with a rank-based test such as Mann-Whitney (scipy.stats.mannwhitneyu, independent samples) or by comparing top-box shares. The rank test takes no weights: use it on unweighted data, and compare top-box shares with the effective sample size when the data is weighted.

Multiple comparisons

Comparing every question across every group multiplies false positives. Fix the list of comparisons before looking. For a planned family, adjust p-values with Holm (controls the chance of any false positive) or Benjamini-Hochberg (controls the share of false discoveries), both in statsmodels multipletests (methods holm and fdr_bh). Run on five p-values 0.001, 0.012, 0.03, 0.04, 0.20, Holm gives 0.005, 0.048, 0.09, 0.09, 0.20. Label other findings exploratory. Tests on shares use the effective sample size.

Open-text answers

Read a sample first and write a codebook: each code with a definition and an example. Report the share of answers per code with its base, and allow more than one code per answer. State whether people, software or a model coded the answers, and check a sample of machine-coded answers by hand.

Disclosure items

The AAPOR Transparency Initiative lists the elements to state with the findings: data collection strategy; sponsor and who conducted the research; exact question wording and response options; population and its definition; sample frame, selection and recruitment; mode and languages; dates; number of completes and precision, including design effects; weighting variables and sources; data processing and quality steps, including who or what coded; limitations; any use of AI. Add unweighted subgroup bases on request.

Examples

Margin of the gap. Bad: "A leads B by 4 points, within the 3-point margin, so a lead." Good: "A leads B by 4 points; the margin on the gap is about 6, so the lead is not distinguishable from a tie."

Raw completes. Bad: "n = 800, margin 3.5". Good: "n = 800, design effect 1.2, effective n = 667, margin 3.8 points."

Mean of a scale. Bad: "Satisfaction is 3.8 against 3.6, a significant improvement." Good: "Top-box satisfaction is 41% against 36% (n = 400 each); the interval on the difference spans zero."

Checklist

  • Faulty questions are listed with rewrites and flagged in the results.
  • Frame, mode, dates, completes, response rate and its definition are stated.
  • Weighted shares match their targets; the design effect and effective size are reported.
  • Every estimate has an interval based on the effective size and an unweighted base.
  • Gaps and changes use their own margins.
  • Likert items show the distribution; comparisons do not treat steps as equal.
  • The comparison list was fixed in advance and p-values are adjusted.
  • The AAPOR elements appear in the method note.

When the user cannot be asked, state the response-rate definition and weighting targets you assumed.

Composition / References

Scope limits: general hypothesis testing, experiments, charts of survey results and predictive models are separate jobs.