BMultivariate · multivariate.permdisp
PERMDISP (homogeneity of multivariate dispersions)
Do groups differ in how spread out their rows are, judged by a dissimilarity?
PERMDISP measures each row's distance to its group's spatial median (or centroid) in principal-coordinate space and compares those distances across groups with an ANOVA F tested by permuting residuals — a multivariate Levene test. Use it on its own for beta diversity or alongside PERMANOVA to tell location from spread.
A real result
Example “Guide median”, recorded in both engines. In the app, “Try this example” loads it into Analyze.
PERMDISP (Euclidean), F(1, 88) = 2.38, p = .100
- F
- 2.377
- df1
- 1
- df2
- 88
- p (permutation)
- .100
- p (F table)
- .127
Plots
View data
| group | PCoA 1 (42.4%) | PCoA 2 (32.5%) |
|---|---|---|
| g1 | 1.880 | −0.0590 |
| g1 | −1.612 | 0.8910 |
| g1 | 1.852 | 0.2849 |
| g1 | 1.182 | 0.9049 |
| g1 | 0.6558 | 0.7322 |
| g1 | −1.723 | 2.557 |
| g1 | −0.3537 | 1.066 |
| g1 | 0.8733 | 1.373 |
| g1 | −1.190 | −0.0974 |
| g1 | −1.994 | −0.0357 |
| g1 | 2.363 | 1.065 |
| g1 | −0.9171 | 0.3980 |
| g1 | 1.105 | 0.4423 |
| g1 | −0.8731 | 0.2165 |
| g1 | 1.609 | 3.095 |
| g1 | 0.7412 | −0.9501 |
| g1 | 1.794 | −0.2277 |
| g1 | 1.202 | 0.0360 |
| g1 | 0.8136 | 1.379 |
| g1 | 0.6387 | −0.6940 |
| g1 | −0.6997 | 0.1242 |
| g1 | 0.4424 | 0.5991 |
| g1 | 0.2818 | 1.578 |
| g1 | 1.449 | −0.7876 |
| g1 | 0.5212 | −0.4453 |
| g1 | 0.2217 | −1.750 |
| g1 | 2.778 | −1.161 |
| g1 | −1.653 | −0.0826 |
| g1 | 1.813 | −0.1413 |
| g1 | 1.168 | −0.9665 |
| g1 | 0.9167 | 1.327 |
| g1 | 1.130 | 0.4960 |
| g1 | −0.4198 | 0.8517 |
| g1 | 0.3646 | −0.3902 |
| g1 | 0.4888 | 0.4014 |
| g1 | 1.132 | −0.9397 |
| g1 | −0.8284 | 0.1889 |
| g1 | −1.268 | 0.8131 |
| g1 | −1.258 | −1.108 |
| g1 | 0.3973 | 1.515 |
| g2 | 0.3005 | −1.929 |
| g2 | 2.515 | −1.324 |
| g2 | −0.2758 | 0.0576 |
| g2 | 0.8521 | −0.7303 |
| g2 | −0.2571 | 1.649 |
| g2 | −1.075 | −0.8621 |
| g2 | 1.336 | 0.2787 |
| g2 | 0.1976 | 0.4148 |
| g2 | −1.410 | −0.4676 |
| g2 | −0.5506 | −1.262 |
| g2 | 0.4851 | −0.0900 |
| g2 | −0.9148 | −2.405 |
| g2 | −0.6339 | −0.7328 |
| g2 | −1.124 | 0.1816 |
| g2 | 0.1908 | −0.2489 |
| g2 | −1.143 | −0.1104 |
| g2 | 0.4909 | 1.963 |
| g2 | −0.9839 | −0.6186 |
| g2 | −0.5787 | −1.013 |
| g2 | −1.271 | −1.232 |
First 60 of 90 rows.
View data
| group | Distance to center |
|---|---|
| g1 | 1.431 |
| g1 | 2.277 |
| g1 | 1.365 |
| g1 | 1.370 |
| g1 | 0.9381 |
| g1 | 3.156 |
| g1 | 1.161 |
| g1 | 1.120 |
| g1 | 1.755 |
| g1 | 2.792 |
| g1 | 1.990 |
| g1 | 1.883 |
| g1 | 0.8026 |
| g1 | 1.417 |
| g1 | 2.987 |
| g1 | 1.384 |
| g1 | 1.420 |
| g1 | 0.8525 |
| g1 | 1.153 |
| g1 | 1.273 |
| g1 | 1.521 |
| g1 | 0.4264 |
| g1 | 1.358 |
| g1 | 1.722 |
| g1 | 2.013 |
| g1 | 2.119 |
| g1 | 2.724 |
| g1 | 2.205 |
| g1 | 1.395 |
| g1 | 1.952 |
| g1 | 1.469 |
| g1 | 0.9567 |
| g1 | 1.540 |
| g1 | 1.114 |
| g1 | 0.7874 |
| g1 | 1.445 |
| g1 | 2.385 |
| g1 | 1.890 |
| g1 | 2.642 |
| g1 | 1.475 |
| g2 | 1.751 |
| g2 | 3.349 |
| g2 | 0.9700 |
| g2 | 1.262 |
| g2 | 2.020 |
| g2 | 1.077 |
| g2 | 2.256 |
| g2 | 1.012 |
| g2 | 1.444 |
| g2 | 1.008 |
| g2 | 1.025 |
| g2 | 2.684 |
| g2 | 0.5416 |
| g2 | 1.009 |
| g2 | 0.7028 |
| g2 | 0.8613 |
| g2 | 3.012 |
| g2 | 0.7711 |
| g2 | 0.8043 |
| g2 | 2.123 |
First 60 of 90 rows.
Assumptions
- Exchangeable residuals — The permutation test permutes residuals of the distance-to-center ANOVA (Anderson 2006).
Distance to each group's spatial median
| group | n | Mean distance |
|---|---|---|
| g1 | 40 | 1.642 |
| g2 | 50 | 1.425 |
- Euclidean dissimilarity of the variables; principal coordinates keep negative eigenvalue axes (Anderson 2006), centers are spatial medians (Weiszfeld); p from 199 residual permutations (seed 42).
PERMDISP (Euclidean), F(1, 88) = 2.38, p = .100
- F
- 2.377
- df1
- 1
- df2
- 88
- p (permutation)
- .100
- p (F table)
- .127
To keep this page light, the plots are shown once, under the R tab.
Assumptions
- Exchangeable residuals — The permutation test permutes residuals of the distance-to-center ANOVA (Anderson 2006).
Distance to each group's spatial median
| group | n | Mean distance |
|---|---|---|
| g1 | 40 | 1.642 |
| g2 | 50 | 1.425 |
- Euclidean dissimilarity of the variables; principal coordinates keep negative eigenvalue axes (Anderson 2006), centers are spatial medians (Weiszfeld); p from 199 residual permutations (seed 42).
Do it in CodeSplash Run it on your own data, in Python or R, with the code to prove it.
Worked examples in the app
- Guide medianmv_guide · group: group · variables: y1, y2, y3
- Guide centroidmv_guide · group: group · variables: y1, y2, y3
- Dune bray biasmv_dune · group: Management · variables: Achimill, Agrostol, Airaprae, Alopgeni, Anthodor, Bellpere, Bromhord, Chenalbu, Cirsarve, Comapalu, Eleopalu, Elymrepe, Empenigr, Hyporadi, Juncarti, Juncbufo, Lolipere, Planlanc, Poaprat, Poatriv, Ranuflam, Rumeacet, Sagiproc, Salirepe, Scorautu, Trifprat, Trifrepe, Vicilath, Bracruta, Callcusp
- Degenerate single levelmv_guide · group: group · variables: y1, y2, y3
In the guides
Tests from the statistics guide this method runs
Where it sits in the decision guides
- More than two independent groups: one-way ANOVA, Kruskal–Wallis · Statistics Guide · B — Compare groups
- Equal variance · Statistics Guide · Step 2 — Check assumptions
What you need
- Variablesnumeric · 1–200 columns
- The numeric variables (or species counts) whose dissimilarities define the spread.
- Groupscategorical / boolean · 1 column · 2–30 levels
- The groups whose dispersions are compared.
Choices you make
options
- Dissimilaritydefault euclidean
How unlike two rows are.
- Euclidean(default) — Straight-line distance; standardize first when variables have different units.
- Manhattan (city block) — Sum of absolute differences.
- Bray–Curtis — For non-negative counts or abundances (beta diversity).
- Jaccard (quantitative) — 2B/(1 + B) from Bray–Curtis B.
- Gower (range-scaled) — Mean absolute difference after scaling each variable to its range.
- Transform firstdefault none
A transform of the variables applied before the dissimilarity.
- None(default) — Use the values as they are.
- Standardize (z-scores) — Each variable to mean 0 and SD 1.
- Scale to 0–1 — Each variable to its range.
- Hellinger — Square roots of each row's relative abundances.
- log(1 + x) — Damps very large counts.
hypothesis
- Centerdefault median
The center spread is measured from.
- Spatial median(default) — Robust center (Anderson 2006; vegan's default).
- Centroid — The mean in principal-coordinate space; sensitive to outlying rows.
- Small-group bias adjustmentdefault off
Multiply distances by √(n/(n − 1)) so small groups are not made to look less dispersed (Stier et al. 2013).
- Permutationsdefault 999
Residual permutations; the smallest possible p is 1/(B + 1).
- Significance leveldefault 0.05
Level used in the narrative.
Checks and remedies
CodeSplash checks each testable assumption on every run and shows the result on the card; premises the data can’t test are marked. If a check fails, these are the ways forward.
Exchangeable residuals
The permutation test permutes residuals of the distance-to-center ANOVA.
Non-Euclidean dissimilarity
With semi-metric dissimilarities some squared distances to the center are negative and are set to 0.
What it reports
- Tests: Equal multivariate dispersions
- f
- PERMANOVA's F ratio; it has the form of ANOVA's F but its p-value comes from permutations, not the F table.
- p
- How surprising your data would be if the null hypothesis were true, as a probability.
- p_f
- The ratio of explained to unexplained variance, used by ANOVA and regression tests.
- df1
- How much independent information is left to estimate variability after fitting the model.
- df2
- How much independent information is left to estimate variability after fitting the model.
- k
- How many groups, studies or clusters the analysis used. Many methods are less reliable when k is small.
- n
- How many independent units the analysis used; it sets precision and power.
- n_perm
- How many independent units the analysis used; it sets precision and power.
- missing_share
- Values that were not recorded; how they went missing decides which fixes are safe.
Per group, level or term: dispersion[<group>]
Python and R
Python and R agree to 6 decimals (relative tolerance 1e-8). Python uses pandas, numpy, scipy, codesplash; R uses stats, nanoparquet, codesplashr.
Default traps between the two languages
- Spatial medians come from Weiszfeld iterations to 1e-12 in both engines (agreement about 1e-10); vegan::betadisper minimizes with optim (BFGS), so its F agrees with ours to about four significant digits. With centroids the agreement is exact.
The exact script CodeSplash ran for example “Guide median” · Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# PERMDISP (homogeneity of multivariate dispersions)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method multivariate.permdisp 1.0.1 · spec 8386fce5e1d31b02
# Dataset: mv_guide (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
import numpy as np
import pandas as pd
import codesplash as cs
from codesplash.stats import mvdist
# %% Data
df = pd.read_parquet("tests/parity/fixtures/mv_guide.parquet", columns=["y1", "y2", "y3", "group"])
n_input = len(df)
df["group"] = pd.Categorical(df["group"], categories=["g1", "g2"]) # stored level order
df = df.dropna(subset=["y1", "y2", "y3", "group"]) # listwise deletion over the analysis columns
df["group"] = df["group"].cat.remove_unused_categories()
n_dropped = n_input - len(df)
warnings = []
if n_dropped:
warnings.append(cs.cs_warning("CS_W_ROWS_DROPPED", dropped=n_dropped, total=n_input))
if n_input and not len(df):
cs.cs_error("CS_E_NO_ROWS")
cs.check_finite_columns(df, ["y1", "y2", "y3", "group"]) # infinite values stop the run (registry/errors.yaml)
# %% Distances
# The dissimilarity between every pair of rows after the chosen transform (codesplash.stats.mvdist); all
# permutations come from the shared Wichmann–Hill stream, so Python and R draw the same relabellings.
variables = ["y1", "y2", "y3"]
transform_kind = "none" # none | standardize | range | hellinger | log1p
metric = "euclidean" # euclidean | manhattan | bray | jaccard | gower
seed = 42
n_perm = int(199)
DIST_LABEL = {"euclidean": "Euclidean", "manhattan": "Manhattan", "bray": "Bray–Curtis", "jaccard": "Jaccard", "gower": "Gower"}
TRANSFORM_LABEL = {"none": "", "standardize": "standardized ", "range": "range-scaled ", "hellinger": "Hellinger-transformed ", "log1p": "log(1 + x) "}
Y = df[variables].to_numpy(dtype=float)
n = int(Y.shape[0])
dims = len(variables)
if n > 5000:
raise ValueError(f"Distance-based tests use an n × n matrix; {n} rows is too many (at most 5000). Filter or sample the data first.")
D = mvdist.distance(mvdist.transform(Y, transform_kind), metric)
dist_text = f"{DIST_LABEL[metric]} dissimilarity of the {TRANSFORM_LABEL[transform_kind]}variables"
g = "group"
levels = [str(lv) for lv in df[g].cat.categories]
codes = df[g].cat.codes.to_numpy().astype(int)
k = len(levels)
if k < 2:
cs.cs_error("CS_E_TOO_FEW_GROUPS", column=g, min=2, k=k)
group_n = np.bincount(codes, minlength=k)
strata_col = None
strata = None
# %% Test
# PERMDISP (Anderson 2006): distances of each row to its group's spatial median or centroid in
# principal-coordinate space, a one-way ANOVA F of those distances, p by permuting the residuals.
center = "median" # median | centroid
bias_adjust = False
alpha = 0.05
res = mvdist.permdisp(D, codes, k, center, bias_adjust, n_perm, seed)
f, p = res["f"], res["p"]
order = np.argsort(-res["group_mean"], kind="stable")
widest, narrowest = levels[order[0]], levels[order[-1]]
ratio = res["group_mean"][order[0]] / res["group_mean"][order[-1]] if res["group_mean"][order[-1]] > 0 else float("inf")
# %% Assumptions
assumptions = [
{"key": "exchangeable", "label": "Exchangeable residuals", "status": "info",
"detail": "The permutation test permutes residuals of the distance-to-center ANOVA (Anderson 2006)."},
]
if res["negative_clipped"]:
assumptions.append({"key": "non_euclidean", "label": "Non-Euclidean dissimilarity", "status": "info",
"detail": f"{res['negative_clipped']} rows had a negative squared distance to the center (non-Euclidean dissimilarity) and were set to 0."})
# %% Result
summary = (f"PERMDISP on the {dist_text}: the groups of {g} " +
(f"differ in spread (F({res['df1']}, {res['df2']}) = {f:.3f}, permutation {cs.fmt_p(p)}); " if p < alpha
else f"show no evidence of different spread (F({res['df1']}, {res['df2']}) = {f:.3f}, permutation {cs.fmt_p(p)}); ")
+ f"{widest} is the most dispersed and {narrowest} the least (mean distance ratio {ratio:.2f}).")
values = {"f": f, "p": p, "p_f": res["p_f"], "df1": res["df1"], "df2": res["df2"], "k": k, "n": n, "n_perm": n_perm}
for lv, z in zip(levels, res["group_mean"]):
values[f"dispersion[{lv}]"] = float(z)
values["missing_share"] = n_dropped / n_input if n_input else 0.0
pc = res["pcoa"]
V, ex = pc["vectors"], pc["explained"]
ax1 = V[:, 0] if V.shape[1] else np.zeros(n)
ax2 = V[:, 1] if V.shape[1] > 1 else np.zeros(n)
cs.publish({
"method": "multivariate.permdisp",
"methodVersion": "1.0.1",
"title": "PERMDISP: homogeneity of multivariate dispersions",
"engine": cs.engine_info("pandas", "numpy", "scipy"),
"n": n,
"summary": summary,
"apa": f"PERMDISP ({DIST_LABEL[metric]}), F({res['df1']}, {res['df2']}) = {cs.fmt_num(f)}, {cs.fmt_p(p)}",
"statistics": [{"key": "f", "label": "F", "value": f}, {"key": "df1", "label": "df1", "value": res["df1"]},
{"key": "df2", "label": "df2", "value": res["df2"]}, {"key": "p", "label": "p (permutation)", "value": p, "format": "p"},
{"key": "p_f", "label": "p (F table)", "value": res["p_f"], "format": "p"}],
"tables": [{"key": "dispersion", "title": f"Distance to each group's {'spatial median' if center == 'median' else 'centroid'}",
"columns": [{"key": "group", "label": g, "type": "string"}, {"key": "n", "label": "n", "type": "integer"},
{"key": "mean", "label": "Mean distance", "type": "number"}],
"rows": [{"group": lv, "n": int(m), "mean": float(z)} for lv, m, z in zip(levels, res["group_n"], res["group_mean"])]}],
"effectSizes": [],
"assumptions": assumptions,
"warnings": warnings,
"notes": [f"{dist_text}; principal coordinates keep negative eigenvalue axes (Anderson 2006), centers are "
+ ("spatial medians (Weiszfeld)" if center == "median" else "centroids")
+ (", distances multiplied by √(n/(n − 1))" if bias_adjust else "")
+ f"; p from {n_perm} residual permutations (seed {seed})."],
"values": values,
"charts": [cs.chart("ordination", "pcoa-centroids", f"Distances to each group's center, principal coordinates of the {DIST_LABEL[metric]} dissimilarities", {
"x": cs.col(f"PCoA 1 ({100 * ex[0]:.1f}%)" if V.shape[1] else "PCoA 1", ax1),
"y": cs.col(f"PCoA 2 ({100 * ex[1]:.1f}%)" if V.shape[1] > 1 else "PCoA 2", ax2),
"group": cs.col(g, df[g].astype(str).to_numpy(), levels=levels)}, controls={"center": center, "spokes": True}),
cs.chart("distances", "box-violin", f"Distance to the {'spatial median' if center == 'median' else 'centroid'} by {g}", {
"y": cs.col("Distance to center", res["z"]),
"group": cs.col(g, df[g].astype(str).to_numpy(), levels=levels)}, controls={"violin": False})],
})
The exact script CodeSplash ran for example “Guide median” · R version 4.5.1 (2025-06-13)
# PERMDISP (homogeneity of multivariate dispersions)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method multivariate.permdisp 1.0.1 · spec 8386fce5e1d31b02
# Dataset: mv_guide (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
library(codesplashr)
# %% Data
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/mv_guide.parquet", col_select = c("y1", "y2", "y3", "group")))
n_input <- nrow(df)
df[["group"]] <- factor(df[["group"]], levels = c("g1", "g2")) # stored level order
df <- df[stats::complete.cases(df[c("y1", "y2", "y3", "group")]), , drop = FALSE] # listwise deletion
df[] <- lapply(df, function(x) if (is.factor(x)) droplevels(x) else x)
n_dropped <- n_input - nrow(df)
warnings <- list()
if (n_dropped > 0) {
warnings <- c(warnings, cs_warning("CS_W_ROWS_DROPPED", dropped = n_dropped, total = n_input))
}
if (n_input > 0 && nrow(df) == 0) cs_error("CS_E_NO_ROWS")
cs_check_finite_columns(df, c("y1", "y2", "y3", "group")) # infinite values stop the run (registry/errors.yaml)
# %% Distances
# The dissimilarity between every pair of rows after the chosen transform (codesplashr cs_mvd_*); all
# permutations come from the shared Wichmann-Hill stream, so Python and R draw the same relabellings.
variables <- c("y1", "y2", "y3")
transform_kind <- "none" # none | standardize | range | hellinger | log1p
metric <- "euclidean" # euclidean | manhattan | bray | jaccard | gower
seed <- 42
n_perm <- as.integer(199)
DIST_LABEL <- c(euclidean = "Euclidean", manhattan = "Manhattan", bray = "Bray–Curtis", jaccard = "Jaccard", gower = "Gower")
TRANSFORM_LABEL <- c(none = "", standardize = "standardized ", range = "range-scaled ", hellinger = "Hellinger-transformed ", log1p = "log(1 + x) ")
Y <- as.matrix(df[variables])
storage.mode(Y) <- "double"
n <- nrow(Y)
dims <- length(variables)
if (n > 5000) stop(sprintf("Distance-based tests use an n × n matrix; %d rows is too many (at most 5000). Filter or sample the data first.", n))
D <- cs_mvd_distance(cs_mvd_transform(Y, transform_kind), metric)
dist_text <- sprintf("%s dissimilarity of the %svariables", DIST_LABEL[[metric]], TRANSFORM_LABEL[[transform_kind]])
g <- "group"
levels_g <- levels(df[[g]])
codes <- as.integer(df[[g]]) - 1L
k <- length(levels_g)
if (k < 2) cs_error("CS_E_TOO_FEW_GROUPS", column = g, min = 2, k = k)
group_n <- tabulate(codes + 1L, nbins = k)
strata_col <- NULL
strata <- NULL
# %% Test
# PERMDISP (Anderson 2006): distances of each row to its group's spatial median or centroid in
# principal-coordinate space, a one-way ANOVA F of those distances, p by permuting the residuals.
center <- "median" # median | centroid
bias_adjust <- FALSE
alpha <- 0.05
res <- cs_mvd_permdisp(D, codes, k, center, bias_adjust, n_perm, seed)
f <- res$f
p <- res$p
ord <- order(-res$group_mean, method = "radix")
widest <- levels_g[ord[1]]
narrowest <- levels_g[ord[k]]
ratio <- if (res$group_mean[ord[k]] > 0) res$group_mean[ord[1]] / res$group_mean[ord[k]] else Inf
# %% Assumptions
assumptions <- list(list(key = "exchangeable", label = "Exchangeable residuals", status = "info",
detail = "The permutation test permutes residuals of the distance-to-center ANOVA (Anderson 2006)."))
if (res$negative_clipped > 0) {
assumptions[[2]] <- list(key = "non_euclidean", label = "Non-Euclidean dissimilarity", status = "info",
detail = sprintf("%d rows had a negative squared distance to the center (non-Euclidean dissimilarity) and were set to 0.", as.integer(res$negative_clipped)))
}
# %% Result
summary <- paste0(sprintf("PERMDISP on the %s: the groups of %s ", dist_text, g),
if (p < alpha) sprintf("differ in spread (F(%d, %d) = %.3f, permutation %s); ", res$df1, res$df2, f, cs_fmt_p(p))
else sprintf("show no evidence of different spread (F(%d, %d) = %.3f, permutation %s); ", res$df1, res$df2, f, cs_fmt_p(p)),
sprintf("%s is the most dispersed and %s the least (mean distance ratio %.2f).", widest, narrowest, ratio))
values <- list(f = f, p = p, p_f = res$p_f, df1 = res$df1, df2 = res$df2, k = k, n = n, n_perm = n_perm)
for (i in seq_len(k)) values[[sprintf("dispersion[%s]", levels_g[i])]] <- res$group_mean[i]
values$missing_share <- if (n_input > 0) n_dropped / n_input else 0
pc <- res$pcoa
V <- pc$vectors
ex <- pc$explained
ax1 <- if (ncol(V) > 0) V[, 1] else rep(0, n)
ax2 <- if (ncol(V) > 1) V[, 2] else rep(0, n)
center_lab <- if (center == "median") "spatial median" else "centroid"
cs_publish(list(
method = "multivariate.permdisp",
methodVersion = "1.0.1",
title = "PERMDISP: homogeneity of multivariate dispersions",
engine = cs_engine_info("stats", "nanoparquet"),
n = n,
summary = summary,
apa = sprintf("PERMDISP (%s), F(%d, %d) = %s, %s", DIST_LABEL[[metric]], res$df1, res$df2, cs_fmt_num(f), cs_fmt_p(p)),
statistics = list(list(key = "f", label = "F", value = f), list(key = "df1", label = "df1", value = res$df1),
list(key = "df2", label = "df2", value = res$df2), list(key = "p", label = "p (permutation)", value = p, format = "p"),
list(key = "p_f", label = "p (F table)", value = res$p_f, format = "p")),
tables = list(list(key = "dispersion", title = sprintf("Distance to each group's %s", center_lab),
columns = list(list(key = "group", label = g, type = "string"), list(key = "n", label = "n", type = "integer"),
list(key = "mean", label = "Mean distance", type = "number")),
rows = data.frame(group = levels_g, n = as.integer(res$group_n), mean = res$group_mean))),
effectSizes = list(),
assumptions = assumptions,
warnings = warnings,
notes = list(paste0(sprintf("%s; principal coordinates keep negative eigenvalue axes (Anderson 2006), centers are ", dist_text),
if (center == "median") "spatial medians (Weiszfeld)" else "centroids",
if (bias_adjust) ", distances multiplied by √(n/(n − 1))" else "",
sprintf("; p from %d residual permutations (seed %d).", n_perm, as.integer(seed)))),
values = values,
charts = list(
cs_chart("ordination", "pcoa-centroids", sprintf("Distances to each group's center, principal coordinates of the %s dissimilarities", DIST_LABEL[[metric]]), list(
x = cs_col(if (ncol(V) > 0) sprintf("PCoA 1 (%.1f%%)", 100 * ex[1]) else "PCoA 1", ax1),
y = cs_col(if (ncol(V) > 1) sprintf("PCoA 2 (%.1f%%)", 100 * ex[2]) else "PCoA 2", ax2),
group = cs_col(g, as.character(df[[g]]), levels = levels_g)), controls = list(center = center, spokes = TRUE)),
cs_chart("distances", "box-violin", sprintf("Distance to the %s by %s", center_lab, g), list(
y = cs_col("Distance to center", res$z),
group = cs_col(g, as.character(df[[g]]), levels = levels_g)), controls = list(violin = FALSE)))
))
Sources
- Anderson, M. J. (2006). Distance-based tests for homogeneity of multivariate dispersions. Biometrics, 62, 245–253.
- Anderson, M. J., Ellingsen, K. E., & McArdle, B. H. (2006). Multivariate dispersion as a measure of beta diversity. Ecology Letters, 9, 683–693.
- Stier, A. C., Geange, S. W., Hanson, K. M., & Bolker, B. M. (2013). Predator density and timing of arrival affect reef fish community assembly. Ecology, 94, 1057–1068.
From the CodeSplash method registry · multivariate.permdisp v1.0.1.