gower_dist: Calculate Gower distance

View source: R/M_statistic.R

gower_distR Documentation

Calculate Gower distance

Description

gower_dist() calculates Gower distance among observations or species.

Usage

gower_dist(x, type = list(), dist_format = c("matrix", "dist"))

Arguments

x

A data frame. The columns usually represent trait data, and the row names are species names.

type

A list for specifying the variable types of the columns in x. Default is numeric type. More details in cluster::daisy().

dist_format

The class of the return value. Default is "matrix".

Value

A matrix or dist object containing the Gower distance among the rows of x.

References

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

Kaufman, L. & Rousseeuw, P.J. (1990) Finding Groups in Data: An Introduction to Cluster Analysis. Wiley, New York.

See Also

cluster::daisy() which this function wraps.

Examples

data("turtles")
# Continuous trait
trait_df <- data.frame(M1 = turtles$traits$M1, row.names = turtles$traits$specie)
trait_dist <- gower_dist(x = trait_df)

# Nominal discrete trait
trait_df <- data.frame(B1 = turtles$traits$B1, row.names = turtles$traits$specie)
trait_dist <- gower_dist(x = trait_df, type = list(factor = 1))

# Ordinal discrete trait
trait_df <- data.frame(CS1 = turtles$traits$CS1, row.names = turtles$traits$specie)
trait_dist <- gower_dist(x = trait_df, type = list(ordered = 1))

# Multi-trait Combinations
trait_df <- data.frame(turtles$traits[, c("M1", "M2", "M3", "M4", "M5")],
                       row.names = turtles$traits$specie)
trait_dist <- gower_dist(x = trait_df, type = list(factor = c("M4", "M5")))


phylosignalDB documentation built on April 4, 2025, 6:04 a.m.