BookmarkSubscribeRSS Feed
rtaylor
Calcite | Level 5

Background:

I need to compute Mahalanobis distance for a dataset with about 200 observations and 17 variables. The goal is to identify 10 closest observations for each row. Variables have very different scales, and there are no missing values. Variables are of un-equal 'importance'.

As recommended in:  30662 - Mahalanobis distance: from each observation to the mean, from each observation to a specific..., I used Proc PRINCOMP with std option and used prin1:prin17 for computing Euclidean distance. As expected first three components accounted for most of the variance. In particular, the first two were correlated highly with the key variables.

It seems that the weight option in the var statement could be used to assign greater importance to the first three components. However, there does not seem to be a rational basis for picking reasonable weight values.

Any feedback, suggestions will be greatly appreciated.

Thanks.

RT

5 REPLIES 5
Ksharp
Super User

IML function ?

MAHALANOBIS Function

MAHALANOBIS(x, < , center > < , cov > );

The MAHALANOBIS function is part of the IMLMLIB library. The MAHALANOBIS function returns the

Mahalanobis distance between center and the rows of x, measured according to the Mahalanobis metric. The

rtaylor
Calcite | Level 5

Thanks Xia,

I have already computed Mahalanobis distance  - as the Euclidean distance with principal components. My questions pertains to the use of the 'weight' option in 'var' statement in PROC DISTANCE. Particularly, I am trying to find out if it is possible and reasonable to 'weight' the first principal component more heavily.

Rick_SAS
SAS Super FREQ

I 'm not sure what you want us to say.  You want to weight the variables. The WEIGHTS= option in the VARS statement enables you to do it. From a SAS sytax point of view, your problem is solved.

If you are asking what relative weights you should use, then that depends on what you are trying to accomplish, and we don't have that information.

Are you trying to compute the distance in the PCA system? If so, you can use the distance between the PCA scores, which are the coordinates in the basis for the PCA vectors.

One possible interpretation of your request is "how do I  assign relative importance to the PCA vectors?" You can use the "proportion of variance explained".  Geometrically, I think that would undo the standardization and result in a coordinate system that is orthogonal but not orthonormal.

rtaylor
Calcite | Level 5

Thank you Dr. Wicklin,

I indeed meant the last interpretation.  The goal is to find observations that are similar to each other, considering redundancy among variables as well importance from a substantive perspective. From a data-reduction view point, distance using first 4-5 scores could be used, which would be equivalent to assigning zero weight to the rest of the variable. Proportion of variance seems more justifiable. In the end, the two may result in fairly similar values given that the first five factors explain over 80% of variance.

I have not seen any examples of weighting. Are there concrete examples that you could point me to.

Rick_SAS
SAS Super FREQ

I think you can just use the Euclidean distance between coordinates of the first 4-5 PCA scores.  A simple way to do this is to specify N=4 or N=5 in the PROC PRINCOMP statement. No need to use the WEIGHTS= option at all.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 2518 views
  • 0 likes
  • 3 in conversation