1

A sample of 100 subjects responded to two personality tests. These tests have slightly different wordings but are generally the same, i.e. they both measure the same 4 attitudes. Therefore, I have 2 matrices like this, with 4 scores per subject:

>test1
subj     A1     A2     A3     A4
   1  -2.14   1.21   0.93  -1.72
   2   0.25   1.17   0.67   0.67

>test2
subj     A1     A2     A3     A4
   1  -1.99   1.11   1.00  -1.52
   2   0.24   1.20   0.71   0.65

I'd like to evaluate the similarity of profiles in the two tests, i.e. the similarity of two sets of 4 scores for each individual. I feel like the mahalanobis distance is the measure I need and I checked some packages (HDMD, StatMatch) but couldn't find the right function.

ekad
  • 14,436
  • 26
  • 44
  • 46
achmed
  • 35
  • 4
  • 1
    There's a mahalanobis function in the base installation of R, is that what you want? If not, there are some functions discussed in this post: http://stackoverflow.com/questions/18658961/mahalanobis-distance-in-r?rq=1 – andrechalom Apr 04 '16 at 17:48
  • As I understand it, the function in the base installation computes the distance of all rows within one single matrix and the discussion in the other post is about computing the distance of one observation in one matrix to all observations in another matrix. What I'd like to to is compare a set of values in one matrix to a set of values in another matrix to end up with 100 distance values - one for each subject. – achmed Apr 05 '16 at 09:52

1 Answers1

0

One approach to this is to create a difference score matrix and then calculate the Mahalanobis distances on the difference scores.

testDiff <- test1 - test2
testDiffMahalanobis <- mahalanobis(testDiff, 
                                   center = colMeans(testDiff),
                                   cov = cov(testDiff))
W. Joel Schneider
  • 1,711
  • 13
  • 14