Skip to content

EProportions · Guide test 073

Rao–Scott survey chi square test

Adjusts contingency table inference for the weights and dependence induced by complex survey sampling.

Runs in CodeSplashPython (calls R) example not runR example validated

Do it in CodeSplash

In the app, set it up in Analyze with this method:

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

12
8
1.20

Bigger values make people in a cluster more alike: the design effect grows.

0.70
0.050

Your data

People come in clusters
123456789101112
Weighted shares
noyes
Row A22.9%16.7%
Row B27.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

F = 0.63
  1. The reference: how F varies across samples when H₀ is true (second-order Rao–Scott: F on Satterthwaite df).
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .443).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

F=X2tr⁡Δ^∼Fd0, d0ν,d0=(tr⁡Δ^)2tr⁡Δ^2F = \dfrac{X^2}{\operatorname{tr}\hat\Delta} \sim F_{d_0,\ d_0\nu},\quad d_0 = \dfrac{(\operatorname{tr}\hat\Delta)^2}{\operatorname{tr}\hat\Delta^2}

With your numbers

X2=1.57,δˉ=2.48,F=0.63X^2 = 1.57,\quad \bar\delta = 2.48,\quad F = 0.63
X2X^2
Pearson χ² on the weighted table
Δ^\hat\Delta
generalized design effects from the linearized covariance
ν\nu
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 H0.

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

XRS12=XP2/λˉλˉ=q−1∑j=1qλj\begin{gathered}X^2_{RS1}=X^2_P/\bar\lambda\\[5pt] \bar\lambda=q^{-1}\sum_{j=1}^{q}\lambda_j\end{gathered}

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.

Python · invokes R

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()
R

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

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.