rdistanceprofilesmahalanobis

Mahalanobis distance between profiles in R


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.


Solution

  • 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))