July 2, 2008

Hotelling T2 test

Filed under: R project — izabela @ 12:06 pm

This time an easy assignment for R project. I needed Hotelling T-test, to compare multivariate means between two data sets. It turns out, all you need to do is to load the package ICSNP, and use function HotellingsT2. OK, with R there always needs to be a trick, and you always have to learn something else meantime. And here, you need to have you data divided into two sets, by group, with no group labels. So, if you have everything in one data frame, function subset comes in handy. Nicely described in Verzani book, the function allows you to restrict rows using logical phrase in subset= or columns, using numbers in select= as in example below:

X <- subset(data, subset = group == 'group1', select = 2:10)
Y <- subset(data, subset = group == 'group2', select = 2:10)

and then it is simple as that:

HotellingsT2 ( X, Y, test = ‘f’ )

The other option for test is ‘chi’, if your data is not-so-perfectly-normal (you can check package manual for more details).

Short note- this needs to be told what to do with outliers. na.action=na.omit or similar solves the problem.

Technorati Tags: , , , ,

No Comments »

Darn, no comments yet.

Powered by WordPress.
Theme by Ron and Andrea. Background image from Gimp Patterns. Theme images created using The GIMP 2.2.8.