distShell: Distance Matrix Computation

View source: R/distShell.R

distShellR Documentation

Distance Matrix Computation

Description

Produces a 'dist' object using a user-defined distance measure.

Usage

distShell(DATA, FUNC, diag = FALSE, upper = FALSE, ...)

Arguments

DATA

a matrix-like object with variables in COLUMNS, cases in ROWS.

FUNC

the distance function; takes two vector arguments and returns a single scalar distance measure. See Details.

diag

logical value indicating whether the diagonal of the distance matrix should be printed by print.dist.

upper

logical value indicating whether the upper triangle of the distance matrix should be printed by print.dist.

...

further arguments, passed to FUNC.

Details

FUNC must be a function of the form foo(x1, x2, ...). The first two arguments must be vectors of equal length, specifying the two cases to be compared. It must return a single scalar distance measure. Similarity measures will work, but for consistency stick to distance measures.

A number of example functions are provided in the package; see Distance Measures.

Value

distShell returns an object of class "dist", including the attribute call.

See dist for details of this class.

Author(s)

Mike Meredith, 10 Dec 2006, updated 1 Sept 2012.

See Also

dist in package stats. Also vegan::vegdist and labdsv::dsvdis. See Distance Measures for details of plug-in functions.

Examples

# Use the artificial data set, see ?distTestData
data(distTestData)

# Using distance measure functions in this package:
distShell(distTestData, distSorensen)
distShell(distTestData, distMorisitaHorn)

# Write a customised distance function:
K <- function(a1, a2)  {
  shared <- sum(a1 > 0 & a2 > 0)
  notshared <- sum(xor(a1 > 0, a2 > 0))
  shared / notshared
}
distShell(distTestData, K)
# This returns Inf if the number of species not shared is zero. May not be a good measure!

wiqid documentation built on Nov. 18, 2022, 1:07 a.m.