DPredict · Guide test 230
Pettitt change point test
Uses ranks to test for a single change in distributional location at an unknown point.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Change-point tests (level shifts) — Did the level of the series jump at some point — and if so, when, and by how much?
In Change-point tests (level shifts), choose Test = Pettitt (ranks).
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 · Pettitt change point 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 K varies across samples when H₀ is true, Pettitt's K for n = 50 (asymptotic) (2 exp(−6K²/(n³ + n²))).
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .018).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- rank of observation s
- Mann–Whitney statistic comparing before and after t
The verdict
K = 316, p = .018
p ≤ α = .050: reject H₀
Rank-based, so outliers matter little; trend or autocorrelation also produce large K.
- Statistic
- 316.000
- p-value
- 0.0182
Pettitt change point test on 50 (x, y) pairs: K = 316, p = .018. The p-value is below α = .050, so the data are hard to reconcile with H₀.
Question and hypotheses
H0: one continuous distribution throughout the series; H1: one unknown location change.
Assumptions
Independent observations under the null; a single change-point interpretation; appropriate handling of ties.
Formula
Parameters and notation
Ri are ranks in the whole series; argmax|Uk| estimates the change point.
Structure of the method
Rank the whole series, form a cumulative rank score at every eligible split, and take the largest absolute score. The argmax is a candidate location estimate, while the test statistic is the maximum over the whole search. These are different outputs with different uncertainty questions.
Estimated and nuisance parameters
Estimate ranks, the maximized rank contrast, and candidate breakpoint; no parametric error distribution or neural model is fitted. The null calibration accounts for the split search. A breakpoint confidence interval is not supplied automatically by the test p value and requires a separately justified inferential procedure.
Settings and design choices
Choose admissible split range, one- versus two-direction change interpretation, tie treatment, and permutation versus approximate p-value calibration. If endpoint trimming or other constraints are added, calibrate that exact search. The common exponential approximation should not be treated as an exact finite-sample result.
Fitting and adaptation
For a new domain, identify whether iid exchangeability is defensible before choosing permutation calibration. If data are serially dependent, use a valid dependence-aware change-point method or resampling design. Re-run the full rank/search algorithm in each replicate; testing only the selected split ignores selection.
Sensitivity and robustness
Inspect serial correlation, multiple changes, gradual trends, heavy ties, and short segments. Several breaks can mask or distort the estimated single break. The supplied gently trending series demonstrates a calculation but is not a clean one-step-change example; rejection need not identify a unique physical discontinuity.
How to use and calibrate
Use permutation calibration, or the common approximation p≈min[1,2exp{−6K²/(n³+n²)}].
Example application
Locate a possible shift in annual measurements.
Interpretation and pitfalls
Watch out
The p value concerns the maximum across all candidate splits. Serial dependence or repeated scanning needs additional treatment.
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
Keep observations in temporal order. Serial correlation and seasonality can invalidate the default independent-error calibration; do not treat the selected change point as known in advance.
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<-seq_len(60)*.02+rnorm(60)
print(trend::pettitt.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<-seq_len(60)*.02+rnorm(60)
print(trend::pettitt.test(x))
Sources
- trend — trend · pettitt.testAuthor documentation/source reviewed: trend 1.1.10.search.r-project.org
- pettitt.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 230, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT230.