I have a data set with categorical, continuous and counting variables. I want to be able to use a method that will give me a distance for each pairwise data point.

From my understanding, each type of variable should be treated differently in order to get an equally weighted distance.


For continuous variables the standard Euclidean Distance can be used.

$d_{x,y} = \sqrt{\sum_{j=1}^j\frac{1}{s_j^2}({x_j}-{y_j})^2}$

Where $s_j$ is the standard deviation of the $j^{th}$ element.

For Counting variables, the distance can be calculated like this:

$\chi_{x,y} = \sqrt{\sum_{j=1}^j\frac{1}{c_j}(x_j-y_j)^2}$

where $c_j$ is the $j^{th}$ element of the average profile

For categorical variables:

$d_{x,y} = \frac{{\sum_{j=1}^j}(2f_j)}{2j}$

where $f_j$ is equal to 1 when the variables match and zero when they don't.

Given that all three methods listed above output distances with different scales, simply adding them together would put heavier weights on certain data types depending on the specific data set.

My question is, what are some common methods to tackle the problem of calculating a total distance given these different data types?

  • $\begingroup$ Given that you describe three distances and only one of them is Euclidean, could you please elaborate on what your understanding of "Euclidean distance" is? $\endgroup$ – whuber Jun 29 '18 at 0:35
  • 1
    $\begingroup$ @whuber After reading your comment I reread the chapter that I linked and I realized that misunderstand the definition. Thanks for pointing that out. I edited the posting. I still have the question of the best way to measure total distance with different variable types. $\endgroup$ – Jarom Jun 29 '18 at 2:11
  • $\begingroup$ There's no "best" or even standard way: it depends on what you hope to accomplish by computing a distance in the first place, as well as on the meaning and nature of the variables involved. That raises the question of what you mean by "good" in your question: if you could clarify that, you are more likely to get useful answers. $\endgroup$ – whuber Jun 29 '18 at 13:14
  • $\begingroup$ @whuber That actually answers my question. I thought that there was some kind of best practice or standard formulas for calculating the total distance given mulitple variable types. Since there is not, I will just have to come up with a way that makes sense given my context and goals. Thank you. $\endgroup$ – Jarom Jun 29 '18 at 18:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.