BMultivariate · multivariate.profile
Profile analysis
Do groups follow parallel profiles across several commensurate measures, at the same level, and is the common profile flat?
Profile analysis of measures on one scale (repeated occasions, subtests, items): parallelism (a MANOVA of successive differences — the group × measure interaction without sphericity), levels (an ANOVA of each row's mean) and flatness (Hotelling's T² of the mean differences), with a profile plot of group means.
A real result
Example “Obrien kaiser post”, recorded in both engines. In the app, “Try this example” loads it into Analyze.
parallelism F(8, 22) = 0.41, p = .901; levels F(2, 13) = 3.95, p = .046; flatness F(4, 10) = 9.03, p = .002
- F (parallelism)
- 0.4120
- p (parallelism)
- .901
- p (levels)
- .046
- p (flatness)
- .002
Effect size
- Partial η² (parallelism) 0.1303 · medium
- η² (levels) 0.3777
Plots
View data
| treatment | CI high | CI low | Mean | Measure |
|---|---|---|---|---|
| control | 5.478 | 1.322 | 3.400 | post_1 |
| control | 6.459 | 0.7415 | 3.600 | post_2 |
| control | 8.031 | 2.369 | 5.200 | post_3 |
| control | 6.160 | 3.440 | 4.800 | post_4 |
| control | 3.878 | 2.122 | 3 | post_5 |
| A | 10.447 | 0.5527 | 5.500 | post_1 |
| A | 9.778 | 2.722 | 6.250 | post_2 |
| A | 10.598 | 5.402 | 8 | post_3 |
| A | 11.109 | 2.891 | 7 | post_4 |
| A | 11.469 | 0.0312 | 5.750 | post_5 |
| B | 7.510 | 4.490 | 6 | post_1 |
| B | 8.248 | 4.895 | 6.571 | post_2 |
| B | 9.018 | 5.839 | 7.429 | post_3 |
| B | 8.782 | 5.503 | 7.143 | post_4 |
| B | 7.618 | 3.810 | 5.714 | post_5 |
Assumptions
- Measures on one scale — Profile analysis compares differences between the measures — check they share units (e.g. the same scale at each time).
- Multivariate normality of the differences — Mardia skewness p = .423, kurtosis z = -1.17, p = .241.
- Equal covariance matrices — Box's M needs every group larger than the number of measures; Pillai's trace is the safest parallelism test.
Profile tests
| Test | Pillai's trace / T² | F | df1 | df2 | p |
|---|---|---|---|---|---|
| Parallelism (group × measure) | 0.2606 | 0.4120 | 8 | 22 | .901 |
| Levels (equal group means) | — | 3.946 | 2 | 13 | .046 |
| Flatness (equal measure means) | 46.953 | 9.029 | 4 | 10 | .002 |
Group profiles (means)
| treatment | n | post_1 | post_2 | post_3 | post_4 | post_5 |
|---|---|---|---|---|---|---|
| control | 5 | 3.400 | 3.600 | 5.200 | 4.800 | 3 |
| A | 4 | 5.500 | 6.250 | 8 | 7 | 5.750 |
| B | 7 | 6 | 6.571 | 7.429 | 7.143 | 5.714 |
- Successive-difference contrasts; the parallelism test is the multivariate (sphericity-free) test of the group × measure interaction, flatness uses the pooled within-group covariance (N − k df).
parallelism F(8, 22) = 0.41, p = .901; levels F(2, 13) = 3.95, p = .046; flatness F(4, 10) = 9.03, p = .002
- F (parallelism)
- 0.4120
- p (parallelism)
- .901
- p (levels)
- .046
- p (flatness)
- .002
Effect size
- Partial η² (parallelism) 0.1303 · medium
- η² (levels) 0.3777
To keep this page light, the plots are shown once, under the R tab.
Assumptions
- Measures on one scale — Profile analysis compares differences between the measures — check they share units (e.g. the same scale at each time).
- Multivariate normality of the differences — Mardia skewness p = .423, kurtosis z = -1.17, p = .241.
- Equal covariance matrices — Box's M needs every group larger than the number of measures; Pillai's trace is the safest parallelism test.
Profile tests
| Test | Pillai's trace / T² | F | df1 | df2 | p |
|---|---|---|---|---|---|
| Parallelism (group × measure) | 0.2606 | 0.4120 | 8 | 22 | .901 |
| Levels (equal group means) | — | 3.946 | 2 | 13 | .046 |
| Flatness (equal measure means) | 46.953 | 9.029 | 4 | 10 | .002 |
Group profiles (means)
| treatment | n | post_1 | post_2 | post_3 | post_4 | post_5 |
|---|---|---|---|---|---|---|
| control | 5 | 3.400 | 3.600 | 5.200 | 4.800 | 3 |
| A | 4 | 5.500 | 6.250 | 8 | 7 | 5.750 |
| B | 7 | 6 | 6.571 | 7.429 | 7.143 | 5.714 |
- Successive-difference contrasts; the parallelism test is the multivariate (sphericity-free) test of the group × measure interaction, flatness uses the pooled within-group covariance (N − k df).
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
- Obrien kaiser postmv_obrienkaiser · group: treatment · measures: post_1, post_2, post_3, post_4, post_5
- Two group wilksmv_guide · group: group · measures: y1, y2, y3
- Gender pretests roymv_obrienkaiser · group: gender · measures: pre_1, pre_2, pre_3
- Degenerate single levelmv_obrienkaiser · group: treatment · measures: post_1, post_2, post_3, post_4, post_5
In the guides
Where it sits in the decision guides
- Factorial designs, covariates, multivariate (ANCOVA, MANOVA) · Statistics Guide · B — Compare groups
What you need
- Measures (in order)numeric · 2–20 columns
- Two or more measures on the same scale, in their natural order (e.g. time 1, time 2, time 3); profiles connect them.
- Groupscategorical / boolean · 1 column · 2–30 levels
- The groups whose profiles are compared.
Choices you make
hypothesis
- Parallelism statisticdefault pillai
How the parallelism test is reported (with two groups all four agree).
- Pillai's trace(default) — Most robust; equals Hotelling's T² with two groups.
- Wilks' lambda — Rao's F approximation.
- Hotelling–Lawley trace — Sum of the eigenvalues of E⁻¹H.
- Roy's largest root — Largest eigenvalue only; its F is an upper bound.
- Confidence leveldefault 0.95
Significance is judged at α = 1 − confidence level; the profile plot shows means with intervals at this level.
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.
Measures on one scale
Profiles compare differences between measures, which only make sense in the same units.
- If violated → MANOVA of the measures — When the measures are on different scales, compare the groups on all of them jointly instead of comparing their profile shapes. Changes the question: Tests equal mean vectors rather than parallel, coincident or flat profiles.
Multivariate normality of the differences
Mardia's tests of the group-centered successive differences.
Equal covariance matrices
Box's M of the measures across groups at α = 0.001.
What it reports
- Tests: Parallel profiles (group × measure)
- Tests: Equal group levels
- Tests: Flat common profile
- parallel_stat
- Compares groups' mean profiles across measures on one scale — parallel, level and flat.
- parallel_f
- The ratio of explained to unexplained variance, used by ANOVA and regression tests.
- parallel_df1
- How much independent information is left to estimate variability after fitting the model.
- parallel_df2
- How much independent information is left to estimate variability after fitting the model.
- parallel_p
- How surprising your data would be if the null hypothesis were true, as a probability.
- parallel_eta_p
- How surprising your data would be if the null hypothesis were true, as a probability.
- levels_f
- The ratio of explained to unexplained variance, used by ANOVA and regression tests.
- levels_df1
- How much independent information is left to estimate variability after fitting the model.
- levels_df2
- How much independent information is left to estimate variability after fitting the model.
- levels_p
- How surprising your data would be if the null hypothesis were true, as a probability.
- levels_eta_p
- How surprising your data would be if the null hypothesis were true, as a probability.
- flat_t2
- Compares groups' mean profiles across measures on one scale — parallel, level and flat.
- flat_f
- The ratio of explained to unexplained variance, used by ANOVA and regression tests.
- flat_df1
- How much independent information is left to estimate variability after fitting the model.
- flat_df2
- How much independent information is left to estimate variability after fitting the model.
- flat_p
- How surprising your data would be if the null hypothesis were true, as a probability.
- 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.
- dims
- How many outcome columns a multivariate test compares at once. More of them need more rows per group.
- mardia_skew_p
- Multivariate skewness and kurtosis tests of whether rows (or residuals) are multivariate normal.
- mardia_kurt_p
- Multivariate skewness and kurtosis tests of whether rows (or residuals) are multivariate normal.
- box_m_p
- Tests whether groups share one covariance matrix, by comparing their log-determinants.
- missing_share
- Values that were not recorded; how they went missing decides which fixes are safe.
Per group, level or term: mean[<group>|<measure>]
Python and R
Python and R agree to 10 decimals (relative tolerance 1e-10). Python uses pandas, numpy, scipy, codesplash; R uses stats, nanoparquet, codesplashr.
The exact script CodeSplash ran for example “Obrien kaiser post” · Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Profile analysis
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method multivariate.profile 1.0.1 · spec 894e0f54c9d00ac5
# Dataset: mv_obrienkaiser (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
from scipy import stats
import codesplash as cs
from codesplash.stats import multivariate as mv
# %% Data
df = pd.read_parquet("tests/parity/fixtures/mv_obrienkaiser.parquet", columns=["post_1", "post_2", "post_3", "post_4", "post_5", "treatment"])
n_input = len(df)
df["treatment"] = pd.Categorical(df["treatment"], categories=["control", "A", "B"]) # stored level order
df = df.dropna(subset=["post_1", "post_2", "post_3", "post_4", "post_5", "treatment"]) # listwise deletion over the analysis columns
df["treatment"] = df["treatment"].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, ["post_1", "post_2", "post_3", "post_4", "post_5", "treatment"]) # infinite values stop the run (registry/errors.yaml)
# %% Helpers
def magnitude(x, cuts, labels=("negligible", "small", "medium", "large")):
"""Benchmark label for an effect size (rule set named in the result)."""
if x is None or not np.isfinite(x):
return "undetermined"
for cut, label in zip(cuts, labels):
if abs(x) < cut:
return label
return labels[-1]
# %% Test
# Profile analysis (Morrison 2005, §4.7): parallelism = MANOVA of successive differences; levels =
# ANOVA of each row's mean; flatness = T² of the mean differences with the pooled within covariance.
measures = ["post_1", "post_2", "post_3", "post_4", "post_5"]
g = "treatment"
test = "pillai"
conf = 0.95
alpha = 1 - conf
levels = [str(lv) for lv in df[g].cat.categories]
k = len(levels)
if k < 2:
cs.cs_error("CS_E_TOO_FEW_GROUPS", column=g, min=2, k=k)
X = df[measures].to_numpy(dtype=float)
codes = df[g].cat.codes.to_numpy()
n, dims = X.shape
res = mv.profile_analysis(X, codes, k)
par = res["parallel"][test]
lev, flat = res["levels"], res["flatness"]
# %% Assumptions
assumptions = [{"key": "commensurate", "label": "Measures on one scale", "status": "info",
"detail": "Profile analysis compares differences between the measures — check they share units (e.g. the same scale at each time)."}]
D = res["D"]
resid = D - np.vstack([D[codes == c].mean(axis=0) for c in range(k)])[codes]
mardia = mv.mardia(resid) if n > dims and dims > 1 else None
if mardia is not None:
ok = mardia["skew_p"] >= 0.05 and mardia["kurt_p"] >= 0.05
status = "pass" if ok else ("info" if n - k >= 50 else "warn")
assumptions.append({"key": "mv_normality", "label": "Multivariate normality of the differences", "status": status, "p": min(mardia["skew_p"], mardia["kurt_p"]),
"detail": f"Mardia skewness {cs.fmt_p(mardia['skew_p'])}, kurtosis z = {mardia['kurt_z']:.2f}, {cs.fmt_p(mardia['kurt_p'])}."})
groups = [X[codes == c] for c in range(k)]
box = mv.box_m(groups) if min(x.shape[0] for x in groups) > dims else None
if box is None:
assumptions.append({"key": "equal_covariance", "label": "Equal covariance matrices", "status": "info", "detail": "Box's M needs every group larger than the number of measures; Pillai's trace is the safest parallelism test."})
else:
status = "warn" if box["p"] < 0.001 else "pass"
assumptions.append({"key": "equal_covariance", "label": "Equal covariance matrices", "status": status, "statistic": box["chisq"], "p": box["p"],
"detail": f"Box's M χ²({box['df']:.0f}) = {box['chisq']:.2f}, {cs.fmt_p(box['p'])}" + (" — prefer Pillai's trace." if status == "warn" else " (judged at α = 0.001).")})
# %% Result
NAMES = {"pillai": "Pillai's trace", "wilks": "Wilks' lambda", "hotelling_lawley": "Hotelling–Lawley trace", "roy": "Roy's largest root"}
size = magnitude(par["eta"], (0.01, 0.06, 0.14))
parts = [
("not parallel" if par["p"] < alpha else "compatible with parallel") + f" ({NAMES[test]}, {cs.fmt_p(par['p'])})",
("the group levels differ" if lev["p"] < alpha else "the group levels do not differ significantly") + f" ({cs.fmt_p(lev['p'])})",
("the common profile is not flat" if flat["p"] < alpha else "the common profile is compatible with flat") + f" ({cs.fmt_p(flat['p'])})",
]
summary = f"Profiles of {', '.join(measures)} across {k} groups of {g}: the profiles are {parts[0]}, {parts[1]}, and {parts[2]}."
if par["p"] < alpha:
summary += " Because the profiles are not parallel, read the levels and flatness tests with care (they average over a group × measure interaction)."
values = {"parallel_stat": par["stat"], "parallel_f": par["f"], "parallel_df1": par["df1"], "parallel_df2": par["df2"], "parallel_p": par["p"], "parallel_eta_p": par["eta"],
"levels_f": lev["f"], "levels_df1": lev["df1"], "levels_df2": lev["df2"], "levels_p": lev["p"], "levels_eta_p": lev["eta"],
"flat_t2": flat["t2"], "flat_f": flat["f"], "flat_df1": flat["df1"], "flat_df2": flat["df2"], "flat_p": flat["p"],
"k": k, "n": n, "dims": dims, "mardia_skew_p": None if mardia is None else mardia["skew_p"],
"mardia_kurt_p": None if mardia is None else mardia["kurt_p"], "box_m_p": None if box is None else box["p"]}
plot = {"measure": [], "group": [], "mean": [], "low": [], "high": []}
for i, lv in enumerate(levels):
ni = int(res["ns"][i])
tcrit = float(stats.t.ppf(1 - alpha / 2, ni - 1)) if ni > 1 else float("nan")
for j, m in enumerate(measures):
mu = float(res["means"][i, j])
half = tcrit * float(res["sds"][i, j]) / np.sqrt(ni) if ni > 1 else float("nan")
values[f"mean[{lv}|{m}]"] = mu
plot["measure"].append(m)
plot["group"].append(lv)
plot["mean"].append(mu)
plot["low"].append(mu - half if np.isfinite(half) else None)
plot["high"].append(mu + half if np.isfinite(half) else None)
values["missing_share"] = n_dropped / n_input if n_input else 0.0
tests_rows = [
{"test": "Parallelism (group × measure)", "stat": par["stat"], "f": par["f"], "df1": par["df1"], "df2": par["df2"], "p": par["p"]},
{"test": "Levels (equal group means)", "stat": None, "f": lev["f"], "df1": lev["df1"], "df2": lev["df2"], "p": lev["p"]},
{"test": "Flatness (equal measure means)", "stat": flat["t2"], "f": flat["f"], "df1": flat["df1"], "df2": flat["df2"], "p": flat["p"]},
]
cs.publish({
"method": "multivariate.profile",
"methodVersion": "1.0.1",
"title": "Profile analysis",
"engine": cs.engine_info("pandas", "numpy", "scipy"),
"n": n,
"summary": summary,
"apa": (f"parallelism F({par['df1']:.0f}, {par['df2']:.4g}) = {cs.fmt_num(par['f'])}, {cs.fmt_p(par['p'])}; "
f"levels F({lev['df1']:.0f}, {lev['df2']:.0f}) = {cs.fmt_num(lev['f'])}, {cs.fmt_p(lev['p'])}; "
f"flatness F({flat['df1']:.0f}, {flat['df2']:.0f}) = {cs.fmt_num(flat['f'])}, {cs.fmt_p(flat['p'])}"),
"statistics": [{"key": "parallel_f", "label": "F (parallelism)", "value": par["f"]}, {"key": "parallel_p", "label": "p (parallelism)", "value": par["p"], "format": "p"},
{"key": "levels_p", "label": "p (levels)", "value": lev["p"], "format": "p"}, {"key": "flat_p", "label": "p (flatness)", "value": flat["p"], "format": "p"}],
"tables": [
{"key": "tests", "title": "Profile tests",
"columns": [{"key": "test", "label": "Test", "type": "string"}, {"key": "stat", "label": f"{NAMES[test]} / T²", "type": "number"},
{"key": "f", "label": "F", "type": "number"}, {"key": "df1", "label": "df1", "type": "number"}, {"key": "df2", "label": "df2", "type": "number"},
{"key": "p", "label": "p", "type": "pvalue"}],
"rows": tests_rows},
{"key": "means", "title": "Group profiles (means)",
"columns": [{"key": "group", "label": g, "type": "string"}, {"key": "n", "label": "n", "type": "integer"}]
+ [{"key": f"m{j}", "label": m, "type": "number"} for j, m in enumerate(measures)],
"rows": [dict({"group": lv, "n": int(res["ns"][i])}, **{f"m{j}": float(res["means"][i, j]) for j in range(dims)}) for i, lv in enumerate(levels)]},
],
"effectSizes": [{"key": "parallel_eta_p", "label": "Partial η² (parallelism)", "value": par["eta"], "method": "multivariate partial η² of the group × measure interaction", "magnitude": size, "ruleSet": "Cohen (1988)"},
{"key": "levels_eta_p", "label": "η² (levels)", "value": lev["eta"], "method": "SS between / SS total of the row means"}],
"assumptions": assumptions,
"warnings": warnings,
"notes": ["Successive-difference contrasts; the parallelism test is the multivariate (sphericity-free) test of the group × measure interaction, flatness uses the pooled within-group covariance (N − k df)."],
"values": values,
"charts": [cs.chart("profile", "profile-plot", f"Mean profiles by {g} ({conf:.0%} intervals)", {
"measure": cs.col("Measure", plot["measure"], "categorical", levels=measures),
"mean": cs.col("Mean", plot["mean"], "numeric"),
"group": cs.col(g, plot["group"], "categorical", levels=levels),
"low": cs.col("CI low", plot["low"], "numeric"),
"high": cs.col("CI high", plot["high"], "numeric")})],
})
The exact script CodeSplash ran for example “Obrien kaiser post” · R version 4.5.1 (2025-06-13)
# Profile analysis
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method multivariate.profile 1.0.1 · spec 894e0f54c9d00ac5
# Dataset: mv_obrienkaiser (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_obrienkaiser.parquet", col_select = c("post_1", "post_2", "post_3", "post_4", "post_5", "treatment")))
n_input <- nrow(df)
df[["treatment"]] <- factor(df[["treatment"]], levels = c("control", "A", "B")) # stored level order
df <- df[stats::complete.cases(df[c("post_1", "post_2", "post_3", "post_4", "post_5", "treatment")]), , 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("post_1", "post_2", "post_3", "post_4", "post_5", "treatment")) # infinite values stop the run (registry/errors.yaml)
# %% Helpers
magnitude <- function(x, cuts, labels = c("negligible", "small", "medium", "large")) {
# Benchmark label for an effect size (rule set named in the result)
if (is.null(x) || !is.finite(x)) return("undetermined")
labels[findInterval(abs(x), cuts) + 1]
}
# %% Test
# Profile analysis (Morrison 2005, §4.7): parallelism = MANOVA of successive differences; levels =
# ANOVA of each row's mean; flatness = T² of the mean differences with the pooled within covariance.
measures <- c("post_1", "post_2", "post_3", "post_4", "post_5")
g <- "treatment"
test <- "pillai"
conf <- 0.95
alpha <- 1 - conf
levels_g <- levels(df[[g]])
k <- length(levels_g)
if (k < 2) cs_error("CS_E_TOO_FEW_GROUPS", column = g, min = 2, k = k)
X <- as.matrix(df[measures])
storage.mode(X) <- "double"
codes <- as.integer(df[[g]]) - 1L
n <- nrow(X)
dims <- ncol(X)
res <- cs_mv_profile(X, codes, k)
par <- res$parallel[[test]]
lev <- res$levels
flat <- res$flatness
# %% Assumptions
assumptions <- list(list(key = "commensurate", label = "Measures on one scale", status = "info",
detail = "Profile analysis compares differences between the measures — check they share units (e.g. the same scale at each time)."))
D <- res$D
gm <- t(vapply(seq_len(k) - 1L, function(c) colMeans(D[codes == c, , drop = FALSE]), numeric(ncol(D))))
if (ncol(D) == 1) gm <- matrix(gm, ncol = 1)
resid <- D - gm[codes + 1L, , drop = FALSE]
mardia <- if (n > dims && dims > 1) cs_mv_mardia(resid) else NULL
if (!is.null(mardia)) {
ok <- mardia$skew_p >= 0.05 && mardia$kurt_p >= 0.05
status <- if (ok) "pass" else if (n - k >= 50) "info" else "warn"
assumptions[[length(assumptions) + 1]] <- list(key = "mv_normality", label = "Multivariate normality of the differences", status = status, p = min(mardia$skew_p, mardia$kurt_p),
detail = sprintf("Mardia skewness %s, kurtosis z = %.2f, %s.", cs_fmt_p(mardia$skew_p), mardia$kurt_z, cs_fmt_p(mardia$kurt_p)))
}
groups <- lapply(seq_len(k) - 1L, function(c) X[codes == c, , drop = FALSE])
box <- if (min(vapply(groups, nrow, 0L)) > dims) cs_mv_box_m(groups) else NULL
if (is.null(box)) {
assumptions[[length(assumptions) + 1]] <- list(key = "equal_covariance", label = "Equal covariance matrices", status = "info", detail = "Box's M needs every group larger than the number of measures; Pillai's trace is the safest parallelism test.")
} else {
status <- if (box$p < 0.001) "warn" else "pass"
assumptions[[length(assumptions) + 1]] <- list(key = "equal_covariance", label = "Equal covariance matrices", status = status, statistic = box$chisq, p = box$p,
detail = paste0(sprintf("Box's M χ²(%.0f) = %.2f, %s", box$df, box$chisq, cs_fmt_p(box$p)), if (status == "warn") " — prefer Pillai's trace." else " (judged at α = 0.001)."))
}
# %% Result
NAMES <- c(pillai = "Pillai's trace", wilks = "Wilks' lambda", hotelling_lawley = "Hotelling–Lawley trace", roy = "Roy's largest root")
size <- magnitude(par$eta, c(0.01, 0.06, 0.14))
parts <- c(
paste0(if (par$p < alpha) "not parallel" else "compatible with parallel", sprintf(" (%s, %s)", NAMES[[test]], cs_fmt_p(par$p))),
paste0(if (lev$p < alpha) "the group levels differ" else "the group levels do not differ significantly", sprintf(" (%s)", cs_fmt_p(lev$p))),
paste0(if (flat$p < alpha) "the common profile is not flat" else "the common profile is compatible with flat", sprintf(" (%s)", cs_fmt_p(flat$p)))
)
summary <- sprintf("Profiles of %s across %d groups of %s: the profiles are %s, %s, and %s.", paste(measures, collapse = ", "), k, g, parts[1], parts[2], parts[3])
if (par$p < alpha) summary <- paste(summary, "Because the profiles are not parallel, read the levels and flatness tests with care (they average over a group × measure interaction).")
values <- list(parallel_stat = par$stat, parallel_f = par$f, parallel_df1 = par$df1, parallel_df2 = par$df2, parallel_p = par$p, parallel_eta_p = par$eta,
levels_f = lev$f, levels_df1 = lev$df1, levels_df2 = lev$df2, levels_p = lev$p, levels_eta_p = lev$eta,
flat_t2 = flat$t2, flat_f = flat$f, flat_df1 = flat$df1, flat_df2 = flat$df2, flat_p = flat$p,
k = k, n = n, dims = dims, mardia_skew_p = if (is.null(mardia)) NULL else mardia$skew_p,
mardia_kurt_p = if (is.null(mardia)) NULL else mardia$kurt_p, box_m_p = if (is.null(box)) NULL else box$p)
pm <- character(0)
pg <- character(0)
pmean <- numeric(0)
plow <- numeric(0)
phigh <- numeric(0)
for (i in seq_len(k)) {
ni <- res$ns[i]
tcrit <- if (ni > 1) stats::qt(1 - alpha / 2, ni - 1) else NA_real_
for (j in seq_len(dims)) {
mu <- res$means[i, j]
half <- if (ni > 1) tcrit * res$sds[i, j] / sqrt(ni) else NA_real_
values[[sprintf("mean[%s|%s]", levels_g[i], measures[j])]] <- mu
pm <- c(pm, measures[j])
pg <- c(pg, levels_g[i])
pmean <- c(pmean, mu)
plow <- c(plow, mu - half)
phigh <- c(phigh, mu + half)
}
}
values$missing_share <- if (n_input > 0) n_dropped / n_input else 0
tests_rows <- list(
list(test = "Parallelism (group × measure)", stat = par$stat, f = par$f, df1 = par$df1, df2 = par$df2, p = par$p),
list(test = "Levels (equal group means)", stat = NULL, f = lev$f, df1 = lev$df1, df2 = lev$df2, p = lev$p),
list(test = "Flatness (equal measure means)", stat = flat$t2, f = flat$f, df1 = flat$df1, df2 = flat$df2, p = flat$p)
)
means_rows <- lapply(seq_len(k), function(i) {
row <- list(group = levels_g[i], n = res$ns[i])
for (j in seq_len(dims)) row[[sprintf("m%d", j - 1L)]] <- res$means[i, j]
row
})
cs_publish(list(
method = "multivariate.profile",
methodVersion = "1.0.1",
title = "Profile analysis",
engine = cs_engine_info("stats", "nanoparquet"),
n = n,
summary = summary,
apa = sprintf("parallelism F(%.0f, %s) = %s, %s; levels F(%.0f, %.0f) = %s, %s; flatness F(%.0f, %.0f) = %s, %s",
par$df1, format(signif(par$df2, 4)), cs_fmt_num(par$f), cs_fmt_p(par$p), lev$df1, lev$df2, cs_fmt_num(lev$f), cs_fmt_p(lev$p),
flat$df1, flat$df2, cs_fmt_num(flat$f), cs_fmt_p(flat$p)),
statistics = list(list(key = "parallel_f", label = "F (parallelism)", value = par$f), list(key = "parallel_p", label = "p (parallelism)", value = par$p, format = "p"),
list(key = "levels_p", label = "p (levels)", value = lev$p, format = "p"), list(key = "flat_p", label = "p (flatness)", value = flat$p, format = "p")),
tables = list(
list(key = "tests", title = "Profile tests",
columns = list(list(key = "test", label = "Test", type = "string"), list(key = "stat", label = sprintf("%s / T²", NAMES[[test]]), type = "number"),
list(key = "f", label = "F", type = "number"), list(key = "df1", label = "df1", type = "number"), list(key = "df2", label = "df2", type = "number"),
list(key = "p", label = "p", type = "pvalue")),
rows = tests_rows),
list(key = "means", title = "Group profiles (means)",
columns = c(list(list(key = "group", label = g, type = "string"), list(key = "n", label = "n", type = "integer")),
lapply(seq_len(dims), function(j) list(key = sprintf("m%d", j - 1L), label = measures[j], type = "number"))),
rows = means_rows)
),
effectSizes = list(list(key = "parallel_eta_p", label = "Partial η² (parallelism)", value = par$eta, method = "multivariate partial η² of the group × measure interaction", magnitude = size, ruleSet = "Cohen (1988)"),
list(key = "levels_eta_p", label = "η² (levels)", value = lev$eta, method = "SS between / SS total of the row means")),
assumptions = assumptions,
warnings = warnings,
notes = list("Successive-difference contrasts; the parallelism test is the multivariate (sphericity-free) test of the group × measure interaction, flatness uses the pooled within-group covariance (N − k df)."),
values = values,
charts = list(cs_chart("profile", "profile-plot", sprintf("Mean profiles by %s (%.0f%% intervals)", g, conf * 100), list(
measure = cs_col("Measure", pm, "categorical", levels = measures),
mean = cs_col("Mean", pmean, "numeric"),
group = cs_col(g, pg, "categorical", levels = levels_g),
low = cs_col("CI low", plow, "numeric"),
high = cs_col("CI high", phigh, "numeric"))))
))
Sources
- Morrison, D. F. (2005). Multivariate Statistical Methods (4th ed.), §4.7 (profile analysis). Thomson.
- Johnson, R. A., & Wichern, D. W. (2007). Applied Multivariate Statistical Analysis (6th ed.), §6.8. Pearson.
- Tabachnick, B. G., & Fidell, L. S. (2019). Using Multivariate Statistics (7th ed.), ch. 8. Pearson.
From the CodeSplash method registry · multivariate.profile v1.0.1.