BCompare groups · Guide test 153
Two sample Hotelling T squared test
Compares independent multivariate mean vectors under a common covariance assumption.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Hotelling's T² (one-sample, two-sample, paired) — Does a mean vector of several outcomes differ from a target, between two groups, or before and after?
In Hotelling's T² (one-sample, two-sample, paired), choose Covariance matrices = Equal (pooled T²) or choose Design = Two independent samples.
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 · Two sample Hotelling T squared test
Your data
Simulated with known truth2 groups on two measurements; crosses mark the group means.
If H₀ were true
- The reference: how F varies across samples when H₀ is true.
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .022).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- pooled covariance matrix
- mean vector of group g
- number of variables
The verdict
F(2, 42) = 4.21, p = .022
p ≤ α = .050: reject H₀
One test for both variables that uses their correlation; it assumes equal covariance matrices (Box's M) and roughly normal data.
- Statistic
- 4.207
- p-value
- 0.0216
Two sample Hotelling T squared test on two groups of 20 and 25 rows on two variables: F(2, 42) = 4.21, p = .022. The p-value is below α = .050, so the data are hard to reconcile with H₀.
Question and hypotheses
H0: two population mean vectors are equal.
Assumptions
Independent multivariate normal samples with equal covariance matrices; n1+n2>p+1.
Formula
Parameters and notation
Sp=[(n1−1)S1+(n2−1)S2]/(n1+n2−2); F df=p,n1+n2−p−1.
Structure of the method
Estimate two mean vectors and pool their unbiased within-group covariances under a common-covariance assumption. Form the covariance-standardized difference with the two-sample effective size, then use its F transformation with the declared response dimension.
Estimated and nuisance parameters
Both population means and the common covariance are estimated. Separate sample covariances are intermediate quantities. Group labels and response selection are design information, not trained features.
Settings and design choices
Fix the variable set, group definition, alpha and covariance assumptions. Choosing a ridge parameter or dimension-reduction basis after viewing the group separation changes the statistic and needs selection-aware calibration.
Fitting and adaptation
For new independent samples refit both means and the pooled covariance. Under a null bootstrap, impose a common mean and retain the intended covariance model; ordinary label permutations require exchangeability, which equality of means alone does not imply under unequal covariances. Paired data instead call for a one-sample analysis of vector differences. No neural adaptation is involved.
Sensitivity and robustness
Unequal covariances combined with unequal sample sizes can distort inference. Collinearity, p near available residual degrees of freedom, nonnormal tails and dependent observations also matter. A significant global mean difference does not identify which response changed without justified simultaneous follow-up analysis.
How to use and calibrate
Use the upper F tail; for matched multivariate data apply entry 152 to difference vectors.
Example application
Compare correlated outcome profiles in two independent groups.
Interpretation and pitfalls
Watch out
Unequal covariances need a multivariate Welch/James-type method or valid resampling.
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
Pooled two-sample Hotelling test assumes equal covariance matrices and independent multivariate normal groups.
Validated — Executed successfully in the validation environment · needs numpy, scipy
import numpy as np
from scipy import stats
rng = np.random.default_rng(2026)
X=rng.normal(size=(40,3));Y=rng.normal(.3,1,size=(50,3))
n,p=X.shape;m=len(Y);S=((n-1)*np.cov(X,rowvar=False)+(m-1)*np.cov(Y,rowvar=False))/(n+m-2);d=X.mean(0)-Y.mean(0);T2=n*m/(n+m)*d@np.linalg.solve(S,d);F=(n+m-p-1)*T2/(p*(n+m-2))
print(T2,F,stats.f.sf(F,p,n+m-p-1))
Output
7.803785261277084 2.542142168446323 0.06156789422477455
Validated — Executed successfully in the validation environment · needs Base/standard library
set.seed(2026)
X<-matrix(rnorm(120),ncol=3);Y<-matrix(rnorm(150,mean=.3),ncol=3)
n<-nrow(X);m<-nrow(Y);p<-ncol(X);S<-((n-1)*cov(X)+(m-1)*cov(Y))/(n+m-2);d<-colMeans(X)-colMeans(Y);T2<-n*m/(n+m)*drop(t(d)%*%solve(S,d));F<-(n+m-p-1)*T2/(p*(n+m-2));print(c(T2=T2,F=F,p=pf(F,p,n+m-p-1,lower.tail=FALSE)))
Output
T2 F p 2.439872e+01 7.948068e+00 9.729572e-05
Sources
- mvhtests — mvhtests · hotel2T2Author documentation/source reviewed: mvhtests 1.2.search.r-project.org
- hotel2T2search.r-project.org
- Statistics guide v4 (historical):
- R: Executed successfully in the validation environment
- Reference's record:
- Edition 2 review: Python: executed · R: not executed (Rscript unavailable). Python: Ran in the reference's review, on this exact code. R: Reviewed but not run: R wasn't available to the reference's authors.
From the CodeSplash statistics guide (v4), entry 153, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT153.