Compute a distance matrix for compositional data using selected CoDa distances.
Arguments
- x
A data matrix whose rows are compositions.
- method
The distance measure to be used. This must be one of
"aitchison"(or"L2"),"L1","L1-pw", or"L1-clr". Any unambiguous abbreviation can be given.- ...
Additional arguments.
diagandupperare passed toas.distfor L1 distances and all arguments are passed todistfor the Aitchison distance.
References
Saperas-Riera, J.; Mateu-Figueras, G.; Martín-Fernández, J.A. (2024). Lp-Norm for Compositional Data: Exploring the CoDa L1-Norm in Penalised Regression. Mathematics, 12(9), 1388. doi:10.3390/math12091388 .
Examples
set.seed(1)
X <- exp(matrix(rnorm(10 * 5), ncol = 5, nrow = 10))
dist_coda(X, method = "aitchison")
#> 1 2 3 4 5 6
#> 2 1.8106122
#> 3 2.1951515 1.8354877
#> 4 4.9583708 3.8970971 3.5026878
#> 5 2.6690937 1.4848858 3.1176463 4.6873327
#> 6 1.3293793 0.5925359 1.5350142 4.0011085 1.7975919
#> 7 2.5713124 1.2254830 1.6803281 2.9037110 1.9971639 1.3362563
#> 8 3.1486205 2.5951883 2.6875395 3.0319299 2.8747477 2.4404921
#> 9 1.9249338 1.7972965 2.1375214 3.3314986 2.6657260 1.5511140
#> 10 1.6002137 1.4440083 0.8048182 3.7544933 2.5833424 0.9732031
#> 7 8 9
#> 2
#> 3
#> 4
#> 5
#> 6
#> 7
#> 8 1.7054263
#> 9 1.6577150 1.7182338
#> 10 1.4434763 2.2492387 1.6407526
dist_coda(X, method = "L2")
#> 1 2 3 4 5 6
#> 2 1.8106122
#> 3 2.1951515 1.8354877
#> 4 4.9583708 3.8970971 3.5026878
#> 5 2.6690937 1.4848858 3.1176463 4.6873327
#> 6 1.3293793 0.5925359 1.5350142 4.0011085 1.7975919
#> 7 2.5713124 1.2254830 1.6803281 2.9037110 1.9971639 1.3362563
#> 8 3.1486205 2.5951883 2.6875395 3.0319299 2.8747477 2.4404921
#> 9 1.9249338 1.7972965 2.1375214 3.3314986 2.6657260 1.5511140
#> 10 1.6002137 1.4440083 0.8048182 3.7544933 2.5833424 0.9732031
#> 7 8 9
#> 2
#> 3
#> 4
#> 5
#> 6
#> 7
#> 8 1.7054263
#> 9 1.6577150 1.7182338
#> 10 1.4434763 2.2492387 1.6407526
dist_coda(X, method = "L1")
#> 1 2 3 4 5 6 7
#> 2 3.304664
#> 3 3.756342 3.471140
#> 4 9.577732 7.597693 5.947985
#> 5 3.916781 2.590618 6.061758 8.537836
#> 6 2.593403 1.095393 2.798592 7.782897 3.263166
#> 7 4.923929 2.265695 3.042451 5.480402 3.952850 2.458937
#> 8 6.105558 3.785990 5.131332 4.539600 5.046708 4.093764 2.428039
#> 9 3.342100 2.753462 4.215896 6.235632 4.455180 2.738142 3.131010
#> 10 2.880080 2.853659 1.217861 6.792119 4.876024 1.777623 2.043849
#> 8 9
#> 2
#> 3
#> 4
#> 5
#> 6
#> 7
#> 8
#> 9 3.195364
#> 10 4.104831 3.107565
dist_coda(X, method = "L1-pw")
#> 1 2 3 4 5 6 7
#> 2 2.788114
#> 3 3.375425 2.720369
#> 4 7.762974 5.890409 5.221406
#> 5 3.804241 2.299989 4.786330 6.600361
#> 6 2.086531 0.893649 2.389679 6.184206 2.697548
#> 7 3.895391 1.910785 2.573735 4.393382 3.073654 1.933250
#> 8 4.930033 3.530387 4.125302 4.277546 4.297287 3.533590 2.351511
#> 9 2.970731 2.608281 3.233834 5.145526 4.015120 2.337592 2.551127
#> 10 2.421796 2.238580 1.124429 5.750695 3.825578 1.446078 1.997066
#> 8 9
#> 2
#> 3
#> 4
#> 5
#> 6
#> 7
#> 8
#> 9 2.617791
#> 10 3.518619 2.491094
dist_coda(X, method = "L1-clr")
#> 1 2 3 4 5 6
#> 2 3.567621
#> 3 3.941528 3.919283
#> 4 9.969341 8.267753 6.027813
#> 5 4.275474 2.626512 6.545795 10.206127
#> 6 2.626793 1.249958 3.017168 8.156465 3.528627
#> 7 5.456157 2.414449 3.389492 6.150813 4.055314 2.896145
#> 8 6.257936 4.474239 5.303422 5.106456 5.273089 4.489604
#> 9 3.382368 2.964188 4.487410 6.586973 4.588523 2.814186
#> 10 3.251572 2.919854 1.372039 6.866468 5.546366 2.017740
#> 7 8 9
#> 2
#> 3
#> 4
#> 5
#> 6
#> 7
#> 8 2.883871
#> 9 3.366816 3.515159
#> 10 2.411636 4.278278 3.423726