Calculates a distance matrix based on an object of class lsp.

lsp_to_dist(x, dist_fun, unit = "log2", p = NULL)

Arguments

x

An object of class lsp - usually the output of the lsp_signature() function

dist_fun

A distance/dissimilarity method used. All possible values can be found using the philentropy::getDistMethods() function

unit

A character string specifying the logarithm unit that should be used to compute distances that depend on log computations: "log", "log2", "log10". The default is "log"

p

Power of the Minkowski distance. Used only when the dist_fun = "minkowski"

Value

An object of class `"dist"“

Examples

library(stars)
landcover = read_stars(system.file("raster/landcover2015s.tif", package = "motif"))

landcover_cove = lsp_signature(landcover, type = "cove", threshold = 0.9, window = 400)
landcover_cove
#> # A tibble: 4 × 3
#>      id na_prop signature     
#> * <int>   <dbl> <list>        
#> 1     1   0     <dbl [1 × 28]>
#> 2     2   0.33  <dbl [1 × 28]>
#> 3     3   0.485 <dbl [1 × 28]>
#> 4     4   0.551 <dbl [1 × 28]>

dist_cov = lsp_to_dist(landcover_cove, dist_fun = "jensen-shannon")
#> Metric: 'jensen-shannon' using unit: 'log2'; comparing: 4 vectors.
dist_cov
#>            1          2          3
#> 2 0.03792103                      
#> 3 0.05198706 0.09418310           
#> 4 0.02349854 0.06928839 0.01541222

# \donttest{
# larger data example
library(stars)
landcover = read_stars(system.file("raster/landcover2015.tif", package = "motif"))

landcover_cove = lsp_signature(landcover, type = "cove", threshold = 0.9, window = 2000)
landcover_cove
#> # A tibble: 6 × 3
#>      id na_prop signature     
#> * <int>   <dbl> <list>        
#> 1     1   0.659 <dbl [1 × 28]>
#> 2     2   0.374 <dbl [1 × 28]>
#> 3     3   0.705 <dbl [1 × 28]>
#> 4     6   0.671 <dbl [1 × 28]>
#> 5     7   0.509 <dbl [1 × 28]>
#> 6     8   0.804 <dbl [1 × 28]>

dist_cov = lsp_to_dist(landcover_cove, dist_fun = "jensen-shannon")
#> Metric: 'jensen-shannon' using unit: 'log2'; comparing: 6 vectors.
dist_cov
#>             1           2           3           6           7
#> 2 0.005410106                                                
#> 3 0.044243759 0.043963412                                    
#> 6 0.087887867 0.081803787 0.036074087                        
#> 7 0.041908697 0.041230398 0.004322015 0.031106539            
#> 8 0.023493738 0.017818474 0.023754159 0.030754786 0.022549318
# }