Last data update: 2014.03.03

R: Two-sample Hotelling's T-squared test
hotelling.testR Documentation

Two-sample Hotelling's T-squared test

Description

Performs a two-sample Hotelling's T-squared test for the difference in two multivariate means

Usage

hotelling.test(x, ...)
## Default S3 method:
hotelling.test(x, y, shrinkage = FALSE, perm = FALSE,
                                 B = 10000, progBar = (perm && TRUE), ...)
## S3 method for class 'formula'
hotelling.test(x, data = NULL, pair = c(1, 2), ...)

Arguments

x

a matrix containing the data points from sample 1 or a formula specifying the elements to be used as a response and the grouping variable as a predictor

y

a matrix containing the data points from sample 2

shrinkage

if TRUE then Shaefer and Strimmer's James-Stein shrinkage estimator is used to calculate the sample covariance matrices

perm

if TRUE then permutation testing is used to estimate the non-parametric P-value for the hypothesis test

B

if perm is TRUE, then B is the number of permutations to perform

progBar

if TRUE and perm is TRUE then a progress bar will be displayed whilst the permutation procedure is carried out

data

a data frame needs to be specified if a formula is to be used to perform the test

pair

a vector of length two which can be used when the grouping factor has more than two levels to select different pairs of groups. For example for a 3-level factor, pairs could be set to c(1,3) to perform Hotelling's test between groups 1 an 3

...

any additional arguments. This is useful to pass the optional arguments for the default call from the formula version

Value

A list (which is also of class 'hotelling.test') with the following elements:

stats

a list containing all of the output from hotelling.stat

pval

the P-value from the test

results

if perm = TRUE, then all of the permuation test statisics are stored in results

Author(s)

James M. Curran

References

Hotelling, H. (1931). “The generalization of Student's ratio.” Annals of Mathematical Statistics 2 (3): 360–378.

Schaefer, J., and K. Strimmer (2005). “A shrinkage approach to large-scale covariance matrix estimation and implications for functional genomics.” Statist. Appl. Genet. Mol. Biol. 4: 32.

Opgen-Rhein, R., and K. Strimmer (2007). “Accurate ranking of differentially expressed genes by a distribution-free shrinkage approach.” Statist. Appl. Genet. Mol. Biol. 6: 9.

Campbell, G.P. and J. M. Curran (2009). “The interpretation of elemental composition measurements from forensic glass evidence III.” Science and Justice, 49(1),2-7.

See Also

hotelling.stat

Examples

data(container.df)
fit = hotelling.test(.~gp, data = container.df)
fit

subs.df = container.df[1:10,]
subs.df$gp = rep(1:2, c(5,5))
fitPerm = hotelling.test(Al+Fe~gp, data  = subs.df, perm =  TRUE)
fitPerm
plot(fitPerm)

data(bottle.df)
fit12 = hotelling.test(.~Number, data = bottle.df)
fit12

fit23 = hotelling.test(.~Number, data = bottle.df, pair = c(2,3))
fit23

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(Hotelling)
Loading required package: corpcor
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/Hotelling/hotelling.test.Rd_%03d_medium.png", width=480, height=480)
> ### Name: hotelling.test
> ### Title: Two-sample Hotelling's T-squared test
> ### Aliases: hotelling.test hotelling.test.default hotelling.test.formula
> ###   hotel.test
> ### Keywords: htest
> 
> ### ** Examples
> 
> data(container.df)
> fit = hotelling.test(.~gp, data = container.df)
> fit
Test stat:  126.11 
Numerator df:  9 
Denominator df:  10 
P-value:  4.233e-09 
> 
> subs.df = container.df[1:10,]
> subs.df$gp = rep(1:2, c(5,5))
> fitPerm = hotelling.test(Al+Fe~gp, data  = subs.df, perm =  TRUE)
   |                                                                               |                                                                      |   0%   |                                                                               |=                                                                     |   1%   |                                                                               |=                                                                     |   2%   |                                                                               |==                                                                    |   3%   |                                                                               |===                                                                   |   4%   |                                                                               |====                                                                  |   5%   |                                                                               |====                                                                  |   6%   |                                                                               |=====                                                                 |   7%   |                                                                               |======                                                                |   8%   |                                                                               |======                                                                |   9%   |                                                                               |=======                                                               |  10%   |                                                                               |========                                                              |  11%   |                                                                               |========                                                              |  12%   |                                                                               |=========                                                             |  13%   |                                                                               |==========                                                            |  14%   |                                                                               |==========                                                            |  15%   |                                                                               |===========                                                           |  16%   |                                                                               |============                                                          |  17%   |                                                                               |=============                                                         |  18%   |                                                                               |=============                                                         |  19%   |                                                                               |==============                                                        |  20%   |                                                                               |===============                                                       |  21%   |                                                                               |===============                                                       |  22%   |                                                                               |================                                                      |  23%   |                                                                               |=================                                                     |  24%   |                                                                               |==================                                                    |  25%   |                                                                               |==================                                                    |  26%   |                                                                               |===================                                                   |  27%   |                                                                               |====================                                                  |  28%   |                                                                               |====================                                                  |  29%   |                                                                               |=====================                                                 |  30%   |                                                                               |======================                                                |  31%   |                                                                               |======================                                                |  32%   |                                                                               |=======================                                               |  33%   |                                                                               |========================                                              |  34%   |                                                                               |========================                                              |  35%   |                                                                               |=========================                                             |  36%   |                                                                               |==========================                                            |  37%   |                                                                               |===========================                                           |  38%   |                                                                               |===========================                                           |  39%   |                                                                               |============================                                          |  40%   |                                                                               |=============================                                         |  41%   |                                                                               |=============================                                         |  42%   |                                                                               |==============================                                        |  43%   |                                                                               |===============================                                       |  44%   |                                                                               |================================                                      |  45%   |                                                                               |================================                                      |  46%   |                                                                               |=================================                                     |  47%   |                                                                               |==================================                                    |  48%   |                                                                               |==================================                                    |  49%   |                                                                               |===================================                                   |  50%   |                                                                               |====================================                                  |  51%   |                                                                               |====================================                                  |  52%   |                                                                               |=====================================                                 |  53%   |                                                                               |======================================                                |  54%   |                                                                               |======================================                                |  55%   |                                                                               |=======================================                               |  56%   |                                                                               |========================================                              |  57%   |                                                                               |=========================================                             |  58%   |                                                                               |=========================================                             |  59%   |                                                                               |==========================================                            |  60%   |                                                                               |===========================================                           |  61%   |                                                                               |===========================================                           |  62%   |                                                                               |============================================                          |  63%   |                                                                               |=============================================                         |  64%   |                                                                               |==============================================                        |  65%   |                                                                               |==============================================                        |  66%   |                                                                               |===============================================                       |  67%   |                                                                               |================================================                      |  68%   |                                                                               |================================================                      |  69%   |                                                                               |=================================================                     |  70%   |                                                                               |==================================================                    |  71%   |                                                                               |==================================================                    |  72%   |                                                                               |===================================================                   |  73%   |                                                                               |====================================================                  |  74%   |                                                                               |====================================================                  |  75%   |                                                                               |=====================================================                 |  76%   |                                                                               |======================================================                |  77%   |                                                                               |=======================================================               |  78%   |                                                                               |=======================================================               |  79%   |                                                                               |========================================================              |  80%   |                                                                               |=========================================================             |  81%   |                                                                               |=========================================================             |  82%   |                                                                               |==========================================================            |  83%   |                                                                               |===========================================================           |  84%   |                                                                               |============================================================          |  85%   |                                                                               |============================================================          |  86%   |                                                                               |=============================================================         |  87%   |                                                                               |==============================================================        |  88%   |                                                                               |==============================================================        |  89%   |                                                                               |===============================================================       |  90%   |                                                                               |================================================================      |  91%   |                                                                               |================================================================      |  92%   |                                                                               |=================================================================     |  93%   |                                                                               |==================================================================    |  94%   |                                                                               |==================================================================    |  95%   |                                                                               |===================================================================   |  96%   |                                                                               |====================================================================  |  97%   |                                                                               |===================================================================== |  98%   |                                                                               |===================================================================== |  99%   |                                                                               |======================================================================| 100%> fitPerm
Test stat:  4.6039 
Numerator df:  2 
Denominator df:  7 
Permutation P-value:  0.0221 
Number of permutations : 10000 
> plot(fitPerm)
> 
> data(bottle.df)
> fit12 = hotelling.test(.~Number, data = bottle.df)
> fit12
Test stat:  4.5041 
Numerator df:  5 
Denominator df:  34 
P-value:  0.002949 
> 
> fit23 = hotelling.test(.~Number, data = bottle.df, pair = c(2,3))
> fit23
Test stat:  57.519 
Numerator df:  5 
Denominator df:  34 
P-value:  1.332e-15 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>