DPredict · Guide test 210
Wallis–Moore phase frequency test
Tests randomness by counting runs of successive increases and decreases.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Randomness and serial-dependence tests — Is the series (or a model's residuals) just random noise, or does it carry runs, trends, autocorrelation, volatility clustering or nonlinear structure?
In Randomness and serial-dependence tests, choose Test = Wallis–Moore phase frequency or choose Wallis–Moore convention = As trend::wm.test.
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 · Wallis–Moore phase frequency test
Each error carries φ × the previous one; 1 is a random walk.
Your data
Simulated with a known ρIf H₀ were true
- The reference: how z varies across samples when H₀ is true (normal approximation).
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .096).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- number of phases: runs of rises or falls, first and last excluded
- continuity correction (n ≤ 30)
The verdict
z = 1.66, p = .096
p > α = .050: compatible with H₀
Too few phases point to trend or positive autocorrelation, too many to alternation. It ignores how large the moves are. This bench follows trend::wm.test: n is the number of values and the ½ correction applies only up to 30 values. The CodeSplash method's default drops ties and corrects at every n; choose Wallis–Moore convention: As trend::wm.test to reproduce trend.
- Statistic
- 1.663
- p-value
- 0.0963
Wallis–Moore phase frequency test on 40 (x, y) pairs: z = 1.66, p = .096. The p-value is above α = .050, so the data are compatible with H₀.
Question and hypotheses
H0: successive observations are independent in random order.
Assumptions
Continuous exchangeable sequence; enough observations for phase-frequency approximation; many ties invalidate the simple calibration.
Formula
Parameters and notation
h counts interior phases: runs of consecutive increases or consecutive decreases, excluding the first and last phase.
Structure of the method
Take signs of successive changes, group identical signs into monotone phases, discard the boundary phases as specified, and compare the remaining phase count with its randomness reference. The statistic summarizes local directional persistence. Its phase definition differs from counting above/below-threshold runs or simply counting all turning points without boundary adjustment.
Estimated and nuisance parameters
The phase count and effective sequence length are observed summaries; no regression parameters are estimated. The reference mean and variance depend on n and the assumed random continuous ordering. An absolute standardized deviation and a signed version give the same two-sided tail only with consistent calibration.
Settings and design choices
Fix handling of zero differences, missing observations, boundary phases, and the finite-sample correction. The documentation warns about many ties. Verify the exact implementation when reporting a small-sample correction, because prose descriptions of numerator/denominator adjustments can be ambiguous.
Fitting and adaptation
No training or fine-tuning stage is present. If applied after detrending or model fitting, that preprocessing becomes part of the diagnostic and may require refitted null simulation. Do not fill missing observations with interpolation and then apply an independent-continuous null without evaluating the induced phase structure.
Sensitivity and robustness
Ties, quantization, short sequences, smooth trends, and seasonal oscillation can strongly change phase frequency. A rejection identifies unusual directional ordering, not necessarily stochastic autocorrelation or a specific nonstationarity mechanism. Report the counted phases and boundary convention, and inspect the sequence graph; passing the test does not establish independence against every alternative.
How to use and calibrate
Use an approximate normal two sided test; specify finite sample continuity correction if used.
Example application
Check whether a time series has too many or too few monotone phases.
Interpretation and pitfalls
Watch out
Phase definitions and ties matter. This is not a test of all forms of weak stationarity.
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
The input vector is in time/sequence order, not sorted by magnitude.
Not run — Python launcher syntax checked; R backend runtime not verified · needs Python standard library + Rscript; R packages: trend
# 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)
x<-rnorm(60);print(trend::wm.test(x))
"""
# 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()
Not run — Syntax checked; runtime not verified in the final environment · needs trend
set.seed(2026)
x<-rnorm(60);print(trend::wm.test(x))
Sources
- trend — trend · wm.testAuthor documentation/source reviewed: trend 1.1.10.search.r-project.org
- wm.testsearch.r-project.org
- Statistics guide v4 (historical):
- Python: Python launcher syntax checked; R backend runtime not verified · R: Syntax checked; runtime not verified in the final 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 210, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT210.