EProportions · Guide test 073
Rao–Scott survey chi square test
Adjusts contingency table inference for the weights and dependence induced by complex survey sampling.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- χ² test of independence — Are two categorical variables associated?
Do it in CodeSplash Run this test on your own data, in Python or R.
Bench
Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.
Bench · Rao–Scott survey chi square test
Bigger values make people in a cluster more alike: the design effect grows.
Your data
People come in clusters| no | yes | |
|---|---|---|
| Row A | 22.9% | 16.7% |
| Row B | 27.1% | 33.3% |
- Average design effect δ̄
- 2.48
- Naive χ² p (ignores clusters)
- .210
- Rao–Scott p
- .443
People in the same cluster resemble each other, so 96 people carry less information than 96 independent ones. The design effect says how much the variance is inflated; Rao–Scott divides χ² by it.
If H₀ were true
- The reference: how F varies across samples when H₀ is true (second-order Rao–Scott: F on Satterthwaite df).
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .443).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- Pearson χ² on the weighted table
- generalized design effects from the linearized covariance
- PSUs minus strata
The verdict
F(1, 11) = 0.63, p = .443
p > α = .050: compatible with H₀
Clusters make answers alike, so the naive χ² overstates the evidence; Rao and Scott divide by the average design effect and match the χ² law's spread with an F.
- Statistic
- 0.633
- p-value
- 0.4430
Rao–Scott survey chi square test on 96 people in 12 clusters of 8: F(1, 11) = 0.63, p = .443. The p-value is above α = .050, so the data are compatible with H₀.
Question and hypotheses
H0: categorical variables are independent in the target survey population.
Assumptions
A probability sample with correctly specified weights, strata, clusters and design covariance; enough independent sampling units.
Formula
Parameters and notation
XP² is the weighted Pearson statistic under the software’s normalization; λj are eigenvalues of the design effect matrix for q independent table contrasts.
Structure of the method
Start with a weighted contingency table and a design-based covariance estimator for independent table contrasts. Rao–Scott corrections compare this covariance with simple-random-sampling covariance; first-order scaling uses average design effects, while a second-order approximation also adjusts the reference degrees of freedom.
Estimated and nuisance parameters
Estimate weighted population proportions, their covariance, and design-effect eigenvalues. Sampling weights, primary sampling-unit identifiers, strata, and finite-population information come from the survey design. Replicate-weight designs supply a different covariance route; weights are not ordinary replication counts.
Settings and design choices
Specify first-order chi-square or second-order F calibration, variance estimator, handling of singleton strata, and missingness/domain definitions. Survey degrees of freedom depend on independent sampling units, not merely respondent count. The supplied ids=~1 example illustrates an unclustered weighted design only.
Fitting and adaptation
Update the survey-design object when new data or revised weights arrive, then recompute proportions and design covariance. Domain analysis should retain the full design structure where required. There is no neural fine-tuning; recalibration means revising weights or covariance with documented design information.
Sensitivity and robustness
Few primary sampling units, highly variable weights, rare categories, and near-singular contrast covariance can make asymptotics fragile. Treating weighted totals as independent integer frequencies is invalid. A large respondent total cannot compensate for very few independent clusters in the relevant domain.
How to use and calibrate
First order Rao–Scott rescales Pearson. Second order uses eigenvalue moments for adjusted degrees of freedom, often an F reference with survey design df. Use survey software rather than naive weighted counts.
Example application
Test a demographic association in a stratified clustered national survey.
Interpretation and pitfalls
Watch out
Weights alone are insufficient; treating weighted totals as independent frequencies understates uncertainty.
What changed in edition 2
- New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.
Python and R
Illustrates independent weighted sampling. Real survey designs must include their actual PSU, strata, finite-population corrections and weights.
Not run — Executed end to end through Rscript · needs Python standard library + Rscript; R packages: survey
# Python launcher for the complete R implementation below.
# Requires Rscript on PATH and the listed R packages.
import shutil
import subprocess
rscript = shutil.which("Rscript")
if rscript is None:
raise RuntimeError("Install R and make Rscript available on PATH.")
r_code = r"""
set.seed(2026)
d <- data.frame(a=factor(rbinom(100,1,.4)),b=factor(rbinom(100,1,.5)),w=runif(100,1,3))
des <- survey::svydesign(ids=~1,weights=~w,data=d)
print(survey::svychisq(~a+b,des,statistic="F"))
"""
# No shell interpolation. A failed R execution raises an error in Python.
result = subprocess.run([rscript, "--vanilla", "-"], input=r_code,
text=True, capture_output=True)
print(result.stdout)
if result.stderr:
print(result.stderr)
result.check_returncode()
Validated — Executed successfully in the validation environment · needs survey
set.seed(2026)
d <- data.frame(a=factor(rbinom(100,1,.4)),b=factor(rbinom(100,1,.5)),w=runif(100,1,3))
des <- survey::svydesign(ids=~1,weights=~w,data=d)
print(survey::svychisq(~a+b,des,statistic="F"))
Output
Pearson's X^2: Rao & Scott adjustment data: survey::svychisq(~a + b, des, statistic = "F") F = 0.36187, ndf = 1, ddf = 99, p-value = 0.5488
Sources
- survey — survey · svychisqAuthor documentation/source reviewed: survey 4.5.search.r-project.org
- svychisqsearch.r-project.org
- svydesignsearch.r-project.org
- Statistics guide v4 (historical):
- Python: Executed end to end through Rscript · R: Executed successfully in the validation environment
- Reference's record:
- Edition 2 review: Python: skip · R: not executed (Rscript unavailable); why not run: Python: Python-to-R bridge; Rscript is unavailable. R code was not executed. Python: Not run in the reference's review: Python-to-R bridge; Rscript is unavailable. R code was not executed. R: Reviewed but not run: R wasn't available to the reference's authors.
From the CodeSplash statistics guide (v4), entry 073, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT073.