dot-getDistMat: Get Distances between 2D Points and a Loess Fit

.getDistMatR Documentation

Get Distances between 2D Points and a Loess Fit

Description

This function gets the euclidean (by default) distances between all points in a 2-D coordinate system (x,y) to a group of points that fall on a fitted loess curve. It uses the dist.matrix function from the wordspace package.It is used in the selVarGenes function.

Usage

.getDistMat(
  loessModel = NULL,
  x = NULL,
  y = NULL,
  x_curve = NULL,
  method = "euclidean",
  ...
)

Arguments

loessModel

the loess fit to all points.

x

the x values of all points.

y

the y values of all points.

x_curve

the x values of the points on the loess curve.

method

distance measure to be used.

...

additional parameters for the dist.matrix function.

Value

An object of class matrix and dist.matrix, containing the distances between all points to the specified points on the loess curve.

Author(s)

Dania Machlab

Examples

  library(stats)
  
  # create data
  x <- 1:1000
  y <- sort(rnorm(n = 1000, mean = 0, sd = 5)) + runif(n = 1000, min = 0, max = 10)
  lo <- loess(y ~ x)
  x_curve <- seq(range(x)[1], range(x)[2], length.out = 100)
  
  # plot
  plot(x, y, pch = 16, col = "#BEBEBE90")
  lines(x_curve, predict(lo, newdata = x_curve), col = "red")
  
  # get euclidean distance of all points to the curve (red)
  euclMat <- swissknife:::.getDistMat(loessModel = lo, x = x, y = y, x_curve = x_curve)
  euclMat[1:6, 1:6]


fmicompbio/swissknife documentation built on June 11, 2025, 4:17 p.m.