Learn R Programming

TSdist (version 3.7.1)

LPDistance: Lp distances.

Description

Computes the distance based on the chosen Lp norm between a pair of numeric vectors.

Usage

LPDistance(x, y, method="euclidean", ...)

Value

d

The computed distance between the pair of series.

Arguments

x

Numeric vector containing the first time series.

y

Numeric vector containing the second time series.

method

A value in "euclidean", "manhattan", "infnorm", "minkowski".

...

If method="minkowski" a positive integer value must be specified for p.

Author

Usue Mori, Alexander Mendiburu, Jose A. Lozano.

Details

The distances based on Lp norms are computed between two numeric vectors using the following formulas:

Euclidean distance: \(\sqrt{(x_i-y_i)^2)}\)

Manhattan distance: \(\sum{|x_i-y_i|}\)

Infinite norm distance: \(\max{|x_i-y_i|}\)

Minkowski distance: \(\sqrt[p]{(x_i-y_i)^p)}\)

The two series must have the same length. Furthermore, in the case of the Minkowski distance, p must be specified as a positive integer value.

See Also

These distances are also implemeted in separate functions. For more information see EuclideanDistance, ManhattanDistance, MinkowskiDistance and InfNormDistance

To calculate this distance measure using ts, zoo or xts objects see TSDistances. To calculate distance matrices of time series databases using this measure see TSDatabaseDistances.

Examples

Run this code

# The objects example.series1 and example.series2 are two 
# numeric series of length 100 contained in the TSdist package. 

data(example.series1)
data(example.series2)

# For information on their generation and shape see help 
# page of example.series.

help(example.series)

# Compute the different Lp distances

# Euclidean distance

LPDistance(example.series1, example.series2, method="euclidean")

# Manhattan distance

LPDistance(example.series1, example.series2, method="manhattan")

# Infinite norm distance

LPDistance(example.series1, example.series2, method="infnorm")

# Minkowski distance with p=3.

LPDistance(example.series1, example.series2, method="minkowski", p=3)

Run the code above in your browser using DataLab