Gower's distance explained

In statistics, Gower's distance between two mixed-type objects is a similarity measure that can handle different types of data within the same dataset and is particularly useful in cluster analysis or other multivariate statistical techniques. Data can be binary, ordinal, or continuous variables. It works by normalizing the differences between each pair of variables and then computing a weighted average of these differences. The distance was defined in 1971 by Gower[1] and it takes values between 0 and 1 with smaller values indicating higher similarity.

Definition

For two objects

i

and

j

having

p

descriptors, the similarity

S

is defined as:S_ = \frac,

where the

wijk

are non-negative weights usually set to

1

[2] and

sijk

is the similarity between the two objects regarding their

k

-th variable. If the variable is binary or ordinal, the values of

sijk

are 0 or 1, with 1 denoting equality. If the variable is continuous,

sijk=1-

|xi-xj|
Rk
with

Rk

being the range of

k

-th variable and thus ensuring

0\leqsijk\leq1

. As a result, the overall similarity

Sij

between two objects is the weighted average of thesimilarities calculated for all their descriptors.[3]

In its original exposition, the distance does not treat ordinal variables in a special manner. In the 1990s, first Kaufman and Rousseeuw[4] and later Podani[5] suggested extensions where the ordering of an ordinal feature is used. For example, Podani obtains relative rank differences as

sijk=1-

|ri-rj|
max{\{r\
}- \min} with

r

being the ranks corresponding to the ordered categories of the

k

-th variable.

Software implementations

Many programming languages and statistical packages, such as R, Python, etc., include implementations of Gower's distance.

Language/program Function Ref.
StatMatch::gower.dist(X) https://search.r-project.org/CRAN/refmans/StatMatch/html/gower.dist.html
gower.gower_matrix(X) https://pypi.org/project/gower/

Notes and References

  1. Gower. John C. 1971. A general coefficient of similarity and some of its properties. Biometrics. 27. 4. 857–871. 10.2307/2528823 . 2528823 . 2024-06-03.
  2. Book: Borg . Ingwer . Groenen . Patrick J. F. . Modern multidimensional scaling: theory and applications . 2005 . Springer . New York [Heidelberg] . 978-0387-25150-9 . 124–125 . 2.
  3. Book: Legendre . Pierre . Legendre . Louis . Numerical ecology . 2012 . Elsevier . Amsterdam . 978-0-444-53868-0 . 278–280 . Third English.
  4. Book: Kaufman . Leonard . Rousseeuw . Peter J. . Finding groups in data: an introduction to cluster analysis . 1990. 35–36 . Wiley . New York . 9780471878766.
  5. Podani . János . Extending Gower's general coefficient of similarity to ordinal characters . Taxon . May 1999 . 1224438. 48 . 2 . 331–340. 10.2307/1224438 .