Given two multivariate data \(X\) and \(Y\) of same dimension, it tests $$H_0 : \mu_x = \mu_y\quad vs\quad H_1 : \mu_x \neq \mu_y$$ using the procedure by Hotelling (1931).

mean2.1931Hotelling(X, Y, paired = FALSE, var.equal = TRUE)

Arguments

X

an \((n_x \times p)\) data matrix of 1st sample.

Y

an \((n_y \times p)\) data matrix of 2nd sample.

paired

a logical; whether you want a paired Hotelling's test.

var.equal

a logical; whether to treat the two covariances as being equal.

Value

a (list) object of S3 class htest containing:

statistic

a test statistic.

p.value

\(p\)-value under \(H_0\).

alternative

alternative hypothesis.

method

name of the test.

data.name

name(s) of provided sample data.

References

Hotelling H (1931). “The Generalization of Student's Ratio.” The Annals of Mathematical Statistics, 2(3), 360--378. ISSN 0003-4851.

Examples

## CRAN-purpose small example
smallX = matrix(rnorm(10*3),ncol=3)
smallY = matrix(rnorm(10*3),ncol=3)
mean2.1931Hotelling(smallX, smallY) # run the test
#> 
#> 	Hotelling's T-squared Test for Independent Samples with Equal
#> 	Covariance Assumption.
#> 
#> data:  smallX and smallY
#> T2 = 0.70875, p-value = 0.888
#> alternative hypothesis: true means are different.
#> 

# \donttest{
## generate two samples from standard normal distributions.
X = matrix(rnorm(50*5), ncol=5)
Y = matrix(rnorm(77*5), ncol=5)

## run single test
print(mean2.1931Hotelling(X,Y))
#> 
#> 	Hotelling's T-squared Test for Independent Samples with Equal
#> 	Covariance Assumption.
#> 
#> data:  X and Y
#> T2 = 3.4069, p-value = 0.6548
#> alternative hypothesis: true means are different.
#> 

## empirical Type 1 error 
niter   = 1000
counter = rep(0,niter)  # record p-values
for (i in 1:niter){
  X = matrix(rnorm(50*5), ncol=5)
  Y = matrix(rnorm(77*5), ncol=5)
  
  counter[i] = ifelse(mean2.1931Hotelling(X,Y)$p.value < 0.05, 1, 0)
}

## print the result
cat(paste("\n* Example for 'mean2.1931Hotelling'\n","*\n",
"* number of rejections   : ", sum(counter),"\n",
"* total number of trials : ", niter,"\n",
"* empirical Type 1 error : ",round(sum(counter/niter),5),"\n",sep=""))
#> 
#> * Example for 'mean2.1931Hotelling'
#> *
#> * number of rejections   : 50
#> * total number of trials : 1000
#> * empirical Type 1 error : 0.05
# }