BCompare groups · Guide test 173
MRPP or multiresponse permutation procedure
Tests whether within group distances are smaller than expected under exchangeable group labels.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- MRPP (multi-response permutation procedure) — Are rows within each group more alike than rows picked at random?
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 · MRPP (multiresponse permutation procedure)
Above 1 the later groups are more spread out (unequal covariance matrices).
Your data
Simulated with known truth3 groups on two measurements; crosses mark the group means.
If H₀ were true
- The reference: how δ varies across samples when H₀ is true, δ over relabelings (permutation null: 199 relabelings of these data (seed 20261107)).
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .200).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- mean distance within group g
- mean of all distances: δ's expectation over relabellings
- chance-corrected within-group agreement
The verdict
δ = 1.83, p = .200
p > α = .050: compatible with H₀
Small δ is evidence (the lower tail). A is an effect size: values around 0.1 are already common in ecology.
- Statistic
- 1.835
- p-value
- 0.2000
MRPP (multiresponse permutation procedure) on 3 groups of 12 rows on two variables: δ = 1.83, p = .200. The p-value is above α = .050, so the data are compatible with H₀.
Question and hypotheses
H0: group labels are unrelated to the multivariate observations.
Assumptions
Exchangeability under the actual design; choose a dissimilarity and group weighting before testing.
Formula
Parameters and notation
cg are specified weights, often ng/N; δ is weighted within-group average dissimilarity.
Structure of the method
Average within-group dissimilarities, combine those means using prespecified group weights, and compare the resulting delta with its label-permutation distribution. Small delta indicates stronger within-group agreement than expected under exchangeability. The optional A effect compares observed delta with its null expectation rather than estimating an ANOVA variance fraction.
Estimated and nuisance parameters
Within-group distance means and the permutation-null expected delta are estimated summaries. Group sizes determine common weighting schemes. The procedure does not estimate a mean-vector model or require training a representation unless preprocessing introduces one.
Settings and design choices
Specify distance, feature scaling, weights proportional to group size or alternative documented schemes, permutation blocks, replication count, and random seed. Singleton groups cannot supply ordinary within-group pairwise means and require explicit handling. Choose the lower-tail convention before looking at results.
Fitting and adaptation
No predictive fitting step is intrinsic. Recompute the weighted within-group summary for each permitted group reassignment. If a metric, transformation, or grouping was learned using the same outcomes, evaluate on fresh data or reproduce that selection in calibration. Do not treat reweighting groups until significance appears as harmless fine-tuning.
Sensitivity and robustness
Unequal group sizes change how weighting emphasizes evidence, and spread differences can produce rejection alongside location differences. Distance units and outliers matter; dependence invalidates unrestricted permutations. Report delta, its null expectation, A where useful, and Monte Carlo precision. A does not establish causal separation or practical classification performance.
How to use and calibrate
Permute labels and use the lower tail: unusually small δ indicates within-group similarity. Report A=1−δ/E0δ if desired.
Example application
Test group separation without assuming normal multivariate observations.
Interpretation and pitfalls
Watch out
Different weighting conventions yield different MRPP procedures; effect A is chance-corrected agreement, not variance explained.
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
Euclidean distance, independent groups, 999 unrestricted permutations. Clustered or repeated designs require restricted permutations; location and dispersion can affect different procedures.
Not run — Executed end to end through Rscript · needs Python standard library + Rscript; R packages: vegan
# 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<-matrix(rnorm(120),ncol=3);Y<-matrix(rnorm(150,mean=.3),ncol=3)
Z<-rbind(X,Y);g<-factor(rep(1:2,c(nrow(X),nrow(Y))))
print(vegan::mrpp(Z,g,distance="euclidean",permutations=999))
"""
# 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 vegan
set.seed(2026)
X<-matrix(rnorm(120),ncol=3);Y<-matrix(rnorm(150,mean=.3),ncol=3)
Z<-rbind(X,Y);g<-factor(rep(1:2,c(nrow(X),nrow(Y))))
print(vegan::mrpp(Z,g,distance="euclidean",permutations=999))
Output
Call:
vegan::mrpp(dat = Z, grouping = g, permutations = 999, distance = "euclidean")
Dissimilarity index: euclidean
Weights for groups: n
Class means and counts:
1 2
delta 2.32 2.062
n 40 50
Chance corrected within-group agreement A: 0.03697
Based on observed delta 2.177 and expected delta 2.26
Significance of delta: 0.001
Permutation: free
Number of permutations: 999Sources
- vegandevs.github.io/vegan/reference/mrpp.htmlvegandevs.github.io
- mrppvegandevs.github.io
- mrppsearch.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 173, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT173.