Skip to content

ADescribe · Guide test 258

Rayleigh test

Tests circular uniformity, with greatest sensitivity to concentration around a single direction.

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:

In Tests of circular uniformity (Rayleigh, V, Kuiper, Watson, Rao), choose Test = Rayleigh.

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 · Rayleigh test

30
60
70

Large spreads approach a uniform circle.

0.050

Your data

Drag a point or use ↑/↓ to change it
Directions (°) · n = 30 · mean direction 57°

If H₀ were true

2Z = 7.52
  1. The reference: how 2Z varies across samples when H₀ is true (χ²₂ limit drawn; p from the Mardia–Jupp expansion).
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .022).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

Z=nRˉ2,p≈e−Z[1+2Z−Z24n−24Z−132Z2+76Z3−9Z4288n2]Z = n\bar R^2,\qquad p \approx e^{-Z}\left[1+\dfrac{2Z-Z^2}{4n}-\dfrac{24Z-132Z^2+76Z^3-9Z^4}{288n^2}\right]

With your numbers

Rˉ=0.35,Z=30×0.352=3.76\bar R = 0.35,\quad Z = 30\times0.35^2 = 3.76
Rˉ\bar R
mean resultant length: 0 for spread, 1 for identical directions
Z=nRˉ2Z = n\bar R^2
Rayleigh's statistic; 2Z is approximately χ² with 2 df, the curve drawn
pp
Mardia–Jupp small-sample expansion, as CodeSplash computes it

The verdict

2Z(2) = 7.52, p = .022, R̄ = 0.35

p ≤ α = .050: reject H₀

Effect size: mean resultant length R̄ = 0.354

Detects one preferred direction. It misses bimodal (axial) data whose resultant cancels; double the angles first for axial data.

Statistic
7.519
p-value
0.0220
Rayleigh test on Directions (°): n = 30: 2Z(2) = 7.52, p = .022, R̄ = 0.35. The p-value is below α = .050, so the data are hard to reconcile with H0.

Rayleigh test on Directions (°): n = 30: 2Z(2) = 7.52, p = .022, R̄ = 0.35. The p-value is below α = .050, so the data are hard to reconcile with H₀.

Question and hypotheses

H0: uniform direction on the circle; H1: typically unimodal concentration.

Assumptions

Independent angular observations with a clear radians/degrees convention and orientation. The usual null uses a full circular domain; axial data require an appropriate doubling transformation or axial model.

Formula

C=∑icos⁡θiS=∑isin⁡θiRˉ=C2+S2/nZ=nRˉ2\begin{gathered}C=\sum_i\cos\theta_i\\[5pt] S=\sum_i\sin\theta_i\\[5pt]\bar R=\sqrt{C^2+S^2}/n\\[5pt] Z=n\bar R^2\end{gathered}

Parameters and notation

2Z is asymptotically χ²2; finite sample Rayleigh corrections depend on n.

Structure of the method

Map each angle to a unit vector, sum cosine/sine components, compute resultant length, and compare its squared scaled magnitude with the circular-uniform reference. This detects the first trigonometric moment; it is not a universal detector of every departure from circular uniformity.

Estimated and nuisance parameters

Estimate mean resultant length and optionally mean direction as descriptive summaries. Under uniformity, direction is undefined, so reporting an apparently precise sample direction after a nonrejection can be misleading. The test itself does not fit a von Mises model or concentration parameter, although such modeling can follow separately.

Settings and design choices

Choose angular units, zero direction, rotation convention, directional versus axial treatment, and finite-sample versus simulated calibration. Axial observations often require angle doubling with corresponding interpretation. Rounding creates ties/discrete support and may require a null respecting the recording resolution instead of continuous uniform angles.

Fitting and adaptation

Adapt by transforming the original measurements into a correctly defined circular domain and retaining the sampling design. For repeated directions from the same subject, use an appropriate dependence-aware model/resampling scheme; treating all observations as independent artificially increases effective sample size. There are no neural hyperparameters to optimize.

Sensitivity and robustness

Inspect antipodal/multimodal patterns, outliers near wrap boundaries, instrument heaping, small samples, and subject clustering. Opposite modes can cancel the resultant and produce nonrejection despite strong nonuniformity. Report a circular plot and concentration/effect summary in addition to the p value.

How to use and calibrate

Use the Rayleigh upper tail or uniform-angle simulation.

Example application

Test whether bearings show a preferred direction.

Interpretation and pitfalls

Watch out

Symmetric multimodal departures can cancel the first resultant and be missed.

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

Angles are in radians on a full circle. The V test specifies direction zero in advance; ordinary Rayleigh does not. Some circular routines return critical-value ranges rather than a continuously resolved p-value.

Python · invokes R

Not run — Executed end to end through Rscript · needs Python standard library + Rscript; R packages: circular

# 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)
a<-circular::circular(runif(40,0,2*pi),units="radians")
print(circular::rayleigh.test(a))
"""
# 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 circular

set.seed(2026)
a<-circular::circular(runif(40,0,2*pi),units="radians")
print(circular::rayleigh.test(a))
Output
       Rayleigh Test of Uniformity 
       General Unimodal Alternative 

Test Statistic:  0.1794 
P-value:  0.2775

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 258, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT258.