0

I am trying too use the Hotellings T2 test in r too compare two vectors. Will the hotellings t2 test automatically calculated the mean of the 2 vectors I am comparing or will I have too do it myself? Many thanks The function I am using is ICSNP::HotellingsT2

  • Hi Conor, at the very least, please provide the name of the function you are trying to use. Function documentation might also be a good place to check out, you can get to it by calling `?my_function` or `help("my_function")`. – jakub Feb 06 '21 at 19:03
  • Apologies I am using the ICSNP HotellingsT2 function – Conor Murphy Feb 06 '21 at 19:06
  • Looking at the function documentation, mean is not listed amongst the the output values. I recommend trying to run the function and then inspecting the output yourself though. – jakub Feb 06 '21 at 19:21

1 Answers1

0

The ICSNP::HotellingsT2() function returns an object of type htest(), a list of seven items, none of which are means for the objects being compared. We can validate this by using the function to compare average mpg in the mtcars data frame by transmission type (manual or automatic).

library(ICSNP)
aResult <- HotellingsT2(mtcars$mpg ~ mtcars$am)
str(aResult)

...and the result:

> str(aResult)
List of 7
 $ statistic  : num [1, 1] 16.9
  ..- attr(*, "names")= chr "T.2"
 $ p.value    : num [1, 1] 0.000285
 $ method     : chr "Hotelling's two sample T2-test"
 $ parameter  : Named num [1:2] 1 30
  ..- attr(*, "names")= chr [1:2] "df1" "df2"
 $ data.name  : chr "mtcars$mpg by mtcars$am"
 $ alternative: chr "two.sided"
 $ null.value : Named chr "c(0)"
  ..- attr(*, "names")= chr "location difference"
 - attr(*, "class")= chr "htest"

You can calculate the means by group with base::aggregate().

aggregate(mpg ~ am,data = mtcars,mean)

> aggregate(mpg ~ am,data = mtcars,mean)
  am      mpg
1  0 17.14737
2  1 24.39231
Len Greski
  • 10,505
  • 2
  • 22
  • 33