Skip to content

BCompare groups · Guide test 152

One sample Hotelling T squared test

Tests a multivariate population mean against a specified vector.

Runs in CodeSplashPython example validatedR example validated

Do it in CodeSplash

In the app, set it up in Analyze with this method:

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

30
0.40
0.25
0.40
0.00
0.050

Your data

Simulated with a known ρ

If H₀ were true

F = 3.33
  1. The reference: how F varies across samples when H₀ is true.
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .051).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

T2=n xˉ⊤S−1xˉ,F=n−pp(n−1)T2T^2 = n\,\bar{\mathbf x}^{\top}\mathbf S^{-1}\bar{\mathbf x},\qquad F = \dfrac{n-p}{p(n-1)}T^2

With your numbers

T2=6.89,F=3.33T^2 = 6.89,\quad F = 3.33
xˉ\bar{\mathbf x}
vector of sample means
S\mathbf S
sample covariance matrix
p=2p = 2
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 H0.

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

T2=n(xˉ−μ0)TS−1(xˉ−μ0)F=n−pp(n−1)T2∼Fp,n−p\begin{gathered}T^2=n(\bar x-\mu_0)^TS^{-1}(\bar x-\mu_0)\\[5pt] F=\frac{n-p}{p(n-1)}T^2\sim F_{p,n-p}\end{gathered}

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.

Python · native

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
R

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

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.