dgower: Gower Distance for Mixed Variables

View source: R/dgower.R

dgowerR Documentation

Gower Distance for Mixed Variables


dgower computes and returns the Gower distance matrix for mixed variables.


dgower(x, type = list())



data matrix.


it is a list with components cuant, bin, nom. Each component indicates the column position of the quantitative, binary or nominal variables, respectively.


The distance between two pairs of objects i and j is obtained as √{2(1-s_{ij})} where s_{ij} is the Gower's similarity coefficient for mixed data. This function allows to include missing values (as NA) and therefore calculates distances based on Gower's weighted similarity coefficient.


A dist object with distance information.


There is the function daisy() in cluster package which can perform the Gower distance for mixed variables. The difference is that in daisy() the distance is calculated as d(i,j)=1-s_{ij} and in dgower() it is calculated as dij=sqrt(1-s_{ij}).


Itziar Irigoien itziar.irigoien@ehu.eus; Konputazio Zientziak eta Adimen Artifiziala, Euskal Herriko Unibertsitatea (UPV/EHU), Donostia, Spain.

Conchita Arenas carenas@ub.edu; Departament d'Estadistica, Universitat de Barcelona, Barcelona, Spain.


Gower, J.C. (1971). A general coefficient of similarity and some of its properties. Biometrics, 27, 857–871.

See Also

dist, dmahal, dbhatta, dcor, dproc2


#Generate 10 objects in dimension 6
# Quantitative variables
mu <- sample(1:10, 2, replace=TRUE)
xc <- matrix(rnorm(10*2, mean = mu, sd = 1), ncol=2, byrow=TRUE)

# Binary variables
xb <- cbind(rbinom(10, 1, 0.1), rbinom(10, 1, 0.5), rbinom(10, 1, 0.9))

# Nominal variables
xn <- matrix(sample(1:3, 10, replace=TRUE), ncol=1)

x <- cbind(xc, xb, xn)

# Distances
d <- dgower(x, type=list(cuant=1:2, bin=3:5, nom=6))

ICGE documentation built on Oct. 17, 2022, 5:10 p.m.

Related to dgower in ICGE...