Hello,
i am trying to calculate the Mahalanobis distance between two sets of variables i have for each observation in my sample.
----------------------- copy starting from the next line -----------------------
------------------ copy up to and including the previous line ------------------
specifically, i want to compute the mahalanobis distance between these 6 variables: moffsiterecoveryA monsiterecoveryA moffsiterecyclingA monsiterecyclingA moffsitetreatmentA monsitetreatmentA and these 6 variables: moffsiterecoveryT monsiterecoveryT moffsiterecyclingT monsiterecyclingT moffsitetreatmentT monsitetreatmentT for every observation in my dataset.
i tried using mahascore or mahascore2 from the mahapick package but i am struggling with creating the distance from one set of variables (or one vector) to another set of variables (or vector) and NOT to the mean of the first defined varlist. the idea is to create two vectors and then calculate the mahalanobis distance between them.
if someone has an example of how to generate vectors out of variables, and then calculate the mahalanobis distance, i would be very greatful !
i am trying to calculate the Mahalanobis distance between two sets of variables i have for each observation in my sample.
----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(moffsiterecoveryA monsiterecoveryA moffsiterecyclingA monsiterecyclingA moffsitetreatmentA monsitetreatmentA moffsiterecoveryT monsiterecoveryT moffsiterecyclingT monsiterecyclingT moffsitetreatmentT monsitetreatmentT) 0 0 0 0 0 0 0 1 1 0 0 0 .2 0 .8 0 0 0 . . . . . . 0 0 1 0 0 0 1 0 1 0 0 0 0 0 0 0 .5 .25 0 0 0 0 1 0 0 .1 .3 0 .1 .1 0 0 .7142857 0 .14285715 0 end
specifically, i want to compute the mahalanobis distance between these 6 variables: moffsiterecoveryA monsiterecoveryA moffsiterecyclingA monsiterecyclingA moffsitetreatmentA monsitetreatmentA and these 6 variables: moffsiterecoveryT monsiterecoveryT moffsiterecyclingT monsiterecyclingT moffsitetreatmentT monsitetreatmentT for every observation in my dataset.
i tried using mahascore or mahascore2 from the mahapick package but i am struggling with creating the distance from one set of variables (or one vector) to another set of variables (or vector) and NOT to the mean of the first defined varlist. the idea is to create two vectors and then calculate the mahalanobis distance between them.
if someone has an example of how to generate vectors out of variables, and then calculate the mahalanobis distance, i would be very greatful !
Comment