BCompare groups · Guide test 152
One sample Hotelling T squared test
Tests a multivariate population mean against a specified vector.
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 Design = One sample or choose Design = Paired (difference vectors).
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 · One sample Hotelling T squared test
Your data
Simulated with a known ρ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 = .051).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- vector of sample means
- sample covariance matrix
- number of variables
The verdict
F(2, 28) = 3.33, p = .051
p > α = .050: compatible with H₀
One test for both means that respects their correlation — more powerful than two t tests when the shift runs against the correlation.
- Statistic
- 3.326
- p-value
- 0.0506
One sample Hotelling T squared test on 30 (x, y) pairs: F(2, 28) = 3.33, p = .051. The p-value is above α = .050, so the data are compatible with H₀.
Question and hypotheses
H0: p-dimensional population mean μ=μ0.
Assumptions
Independent multivariate normal observations; n>p and nonsingular covariance for classical exact inference.
Formula
Parameters and notation
S is unbiased sample covariance; p response dimensions,n observations.
Structure of the method
Estimate a multivariate sample mean and unbiased covariance, solve a covariance-weighted quadratic form for the difference from the target vector and apply the finite-sample F conversion. Solving a linear system is preferable to explicitly forming a matrix inverse.
Estimated and nuisance parameters
Estimate p means and p(p+1)/2 covariance entries. The target vector is externally specified under the null; selecting it from the tested observations would change the problem.
Settings and design choices
Choose response variables, target means, alpha and any simultaneous follow-up contrasts before testing. Rank tolerance is numerical, while regularizing covariance is a methodological change requiring a different null reference.
Fitting and adaptation
Fit mean and covariance on each new independent sample. The classical exact test assumes multivariate normality and n>p with nonsingular covariance. If resampling is used, impose the null mean and reproduce covariance estimation. This is multivariate nuisance estimation, not neural fine-tuning; report vector effect estimates and uncertainty alongside the global p-value.
Sensitivity and robustness
Near-collinear responses amplify numerical error and small covariance-estimation errors. As p approaches n, the test can become unstable and low-powered. Heavy tails and dependence weaken finite-sample validity; replacing the covariance by a pseudoinverse does not preserve the ordinary exact F law.
How to use and calibrate
Use the upper F tail; report the mean vector difference and simultaneous/individual uncertainty clearly.
Example application
Test whether several correlated quality measurements jointly meet a target vector.
Interpretation and pitfalls
Watch out
High dimension or collinearity makes S singular. Separate unadjusted t tests do not reproduce the multivariate test.
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
Tests a zero mean vector under multivariate normality; n must exceed dimension and covariance must be nonsingular.
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;d=X.mean(0);T2=n*d@np.linalg.solve(np.cov(X,rowvar=False),d);F=(n-p)*T2/(p*(n-1))
print(T2,F,stats.f.sf(F,p,n-p))
Output
0.39971821911167255 0.1264066163002725 0.9438685901272371
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);p<-ncol(X);d<-colMeans(X);T2<-n*drop(t(d)%*%solve(cov(X),d));F<-(n-p)*T2/(p*(n-1));print(c(T2=T2,F=F,p=pf(F,p,n-p,lower.tail=FALSE)))
Output
T2 F p 1.4360301 0.4541292 0.7159442
Sources
- mvhtests — mvhtests · hotel1T2Author documentation/source reviewed: mvhtests 1.2.search.r-project.org
- hotel1T2search.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 152, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT152.