R/is.metric.R

Defines functions is.metric

Documented in is.metric

#' Metricity
#' 
#' Checks whether the input dissimilarity matrix is metric (i.e. all triplets fulfill the triangle inequality).
#' 
#' @param x Either an object of class \code{trajectories},  a symmetric \code{\link{matrix}} or an object of class \code{\link{dist}} containing the distance values between pairs of ecological states.
#' @param tol Tolerance value for metricity
#' 
#' @return A boolean indicating metric property
#' 
#' @author 
#' Miquel De \enc{Cáceres}{Caceres}, CREAF
#' 
#' @encoding UTF-8
#' @export
is.metric<-function(x, tol=0.0001) {
  if(inherits(x, "trajectories")) {
    return(.ismetricC(as.matrix(x$d), tol))
  } else if(inherits(x, "dist")) {
    return(.ismetricC(as.matrix(x), tol))
  } else if(inherits(x, "matrix")) {
    return(.ismetricC(x, tol))
  }
  stop("'x' should be of class `trajectories`, `dist` or `matrix`")
}

Try the ecotraj package in your browser

Any scripts or data that you put into this service are public.

ecotraj documentation built on June 8, 2025, 11:24 a.m.