Skip to contents

This function constructs an object representing a distance function, which can be used with generic functions like `pairwise_dist` for computing distances. The object stores the method of distance calculation, labels associated with data points, and any additional parameters that may affect the distance computation.

Usage

create_dist(name, labels, ...)

Arguments

name

A character string specifying the method of distance computation. This method name is used to dispatch the appropriate distance calculation function. Common methods might include "euclidean", "manhattan", "mahalanobis", etc.

labels

A vector of labels or identifiers associated with the rows of the data matrix. These labels are important for reference in distance computations, particularly when adjustments or restrictions based on groupings or identifiers are needed.

...

Additional parameters relevant to the specific distance method. These could include tuning parameters like `lambda` for shrinkage in covariance estimation or parameters controlling the behavior of the distance computation.

Value

Returns an object of class `distfun` and the specific method class (as specified by the `method` parameter). This object encapsulates all information necessary to compute distances between data points according to the specified method and additional parameters.

Details

The `create_dist` function enables the flexible creation of distance function objects. By specifying a method and associated parameters, users can customize the behavior of distance calculations. This functionality is especially useful in statistical and machine learning applications where different distance metrics can have significant impacts on the results.

Examples

# Create a Euclidean distance function object
dist_obj_euc <- create_dist("euclidean", labels = c("A", "B", "C", "D"))

# Create a Mahalanobis distance function object with additional parameters
dist_obj_maha <- create_dist("mahalanobis", labels = c("A", "B", "C", "D"))