# leastCostPath: Find the least cost path in a least cost matrix. In distantia: Assessing Dissimilarity Between Multivariate Time Series

## Description

Uses the original distance matrix created by `distanceMatrix` and the least cost path matrix created by `leastCostMatrix` to find the least cost path between the first and the last cells of the matrix. If `diagonal` was `TRUE` in `leastCostMatrix`, then it must be `TRUE` when using this function. Otherwise, the default is `FALSE` in both.

## Usage

 ```1 2 3 4 5 6``` ```leastCostPath( distance.matrix = NULL, least.cost.matrix = NULL, diagonal = FALSE, parallel.execution = TRUE ) ```

## Arguments

 `distance.matrix` numeric matrix or list of numeric matrices, a distance matrix produced by `distanceMatrix`. `least.cost.matrix` numeric matrix or list of numeric matrices produced by `leastCostMatrix`. `diagonal` boolean, if `TRUE`, diagonals are included in the computation of the least cost path. Defaults to `FALSE`, as the original algorithm did not include diagonals in the computation of the least cost path. `parallel.execution` boolean, if `TRUE` (default), execution is parallelized, and serialized if `FALSE`.

## Value

Alist of dataframes if `least.cost.matrix` is a list, or a dataframe if `least.cost.matrix` is a matrix. The dataframe/s have the following columns:

• A row/sample of one of the sequences.

• B row/sample of one the other sequence.

• distance distance between both samples, extracted from `distance.matrix`.

• cumulative.distance cumulative distance at the samples `A` and `B`.

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40``` ```#loading data data(sequenceA) data(sequenceB) #preparing datasets AB.sequences <- prepareSequences( sequence.A = sequenceA, sequence.A.name = "A", sequence.B = sequenceB, sequence.B.name = "B", merge.mode = "complete", if.empty.cases = "zero", transformation = "hellinger" ) #computing distance matrix AB.distance.matrix <- distanceMatrix( sequences = AB.sequences, grouping.column = "id", method = "manhattan", parallel.execution = FALSE ) #computing least cost matrix AB.least.cost.matrix <- leastCostMatrix( distance.matrix = AB.distance.matrix, diagonal = FALSE, parallel.execution = FALSE ) AB.least.cost.path <- leastCostPath( distance.matrix = AB.distance.matrix, least.cost.matrix = AB.least.cost.matrix, parallel.execution = FALSE ) #plot plotMatrix(distance.matrix = AB.distance.matrix, least.cost.path = AB.least.cost.path, ) ```

distantia documentation built on Oct. 30, 2019, 10:05 a.m.