Skip to contents

Computes the log-ratio variance matrix.

Usage

# S4 method for CompositionMatrix
dist(x, method = "euclidean", diag = FALSE, upper = FALSE, p = 2)

Arguments

x

A CompositionMatrix object.

method

A character string specifying the distance measure to be used. See stats::dist() for the available distances.

diag

A logical scalar indicating whether the diagonal of the distance matrix should be printed.

upper

A logical scalar indicating whether the upper triangle of the distance matrix should be printed.

p

An integer giving the power of the Minkowski distance.

Value

A stats::dist object.

Details

Distances are computed on CLR-transformed data.

References

Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall, p. 64-91. doi:10.1007/978-94-009-4109-0 .

Greenacre, M. J. (2019). Compositional Data Analysis in Practice. Boca Raton: CRC Press.

See also

Author

N. Frerebeau

Examples

## Coerce to compositional data
data("hongite")
coda <- as_composition(hongite)

## Distance
dist(coda)
#>            H1        H2        H3        H4        H5        H6        H7
#> H2  0.8767510                                                            
#> H3  2.5214253 1.6650912                                                  
#> H4  0.7906400 0.2952543 1.8639740                                        
#> H5  0.4739924 1.1608245 2.8213666 0.9854538                              
#> H6  0.9678208 1.0017438 2.4503854 0.7106924 0.8126273                    
#> H7  0.8391283 0.9264506 2.4466687 0.6726300 0.6518013 0.3068355          
#> H8  3.0681017 2.2077617 0.5985190 2.3755249 3.3531743 2.9031508 2.9350491
#> H9  2.1567755 1.3025730 0.3646671 1.5092037 2.4608605 2.1188602 2.1067706
#> H10 1.5855253 2.3852360 4.0452164 2.1890800 1.2401119 1.7847939 1.7285362
#> H11 1.1710927 0.3101166 1.3704961 0.5142905 1.4599034 1.1921282 1.1626052
#> H12 0.3727262 1.2405255 2.8797113 1.1509884 0.4539174 1.1923398 1.0473042
#> H13 2.6796901 1.8462061 0.2974720 2.0700018 3.0032107 2.6883648 2.6669260
#> H14 2.1787003 1.3234987 0.8580849 1.4065875 2.3581311 1.8190796 1.8478752
#> H15 1.4784947 0.6708213 1.0579099 0.9297665 1.8185451 1.6194568 1.5714340
#> H16 2.9044778 2.0288430 0.6027605 2.1709606 3.1392211 2.6453694 2.6681226
#> H17 1.4546884 2.1462022 3.7770078 1.9169098 1.0304796 1.4107166 1.3729948
#> H18 0.5245452 1.0606339 2.7007677 0.8376898 0.2629770 0.5769217 0.4884938
#> H19 1.7602135 0.9534581 0.8105519 1.2096096 2.0997516 1.8869609 1.8364379
#> H20 2.1115841 1.2415737 0.5413915 1.3933788 2.3711124 1.9319745 1.9510350
#> H21 1.6327549 0.7593779 0.9906382 0.9018811 1.8714132 1.4647356 1.4581381
#> H22 0.8008035 0.4134000 1.9478272 0.1333961 0.9287606 0.5909027 0.5497058
#> H23 0.7451072 1.2918095 2.9137094 1.0529779 0.3583952 0.6293206 0.5735426
#> H24 1.6082346 0.7503990 0.9163484 0.9700216 1.9090190 1.6170556 1.5859866
#> H25 0.9383107 0.1051583 1.6279995 0.3274461 1.1953636 1.0126284 0.9224570
#>            H8        H9       H10       H11       H12       H13       H14
#> H2                                                                       
#> H3                                                                       
#> H4                                                                       
#> H5                                                                       
#> H6                                                                       
#> H7                                                                       
#> H8                                                                       
#> H9  0.9397076                                                            
#> H10 4.5619484 3.6846865                                                  
#> H11 1.9033794 1.0096405 2.6762596                                        
#> H12 3.4332992 2.5152272 1.2980229 1.5387862                              
#> H13 0.6382499 0.5712106 4.2301042 1.5639306 3.0279063                    
#> H14 1.1707267 0.7298713 3.5473128 1.0636854 2.5411784 1.1433041          
#> H15 1.6287975 0.6973619 3.0370608 0.4288520 1.8301814 1.2017611 1.0344674
#> H16 0.4545771 0.8638763 4.3488475 1.7374933 3.2690987 0.7689998 0.8360769
#> H17 4.2728994 3.4243251 0.4863777 2.4251205 1.2552674 3.9824638 3.2094091
#> H18 3.2105210 2.3441270 1.3561461 1.3391357 0.6366131 2.8999267 2.1988548
#> H19 1.3980195 0.4714590 3.3222469 0.7032641 2.1054467 0.9228103 0.9859377
#> H20 0.9877633 0.3329260 3.5815737 0.9408789 2.4792771 0.8218637 0.4308744
#> H21 1.4914563 0.6632621 3.0879216 0.4819969 1.9980537 1.2277365 0.5920798
#> H22 2.4502129 1.5980522 2.1227178 0.6233978 1.1448814 2.1615401 1.4406247
#> H23 3.4120401 2.5610218 1.1797726 1.5632549 0.7625165 3.1207729 2.3708636
#> H24 1.4738079 0.5530808 3.1343759 0.4647774 1.9682225 1.1021347 0.8059578
#> H25 2.1729555 1.2681367 2.4277793 0.3059376 1.2955966 1.8116276 1.2646069
#>           H15       H16       H17       H18       H19       H20       H21
#> H2                                                                       
#> H3                                                                       
#> H4                                                                       
#> H5                                                                       
#> H6                                                                       
#> H7                                                                       
#> H8                                                                       
#> H9                                                                       
#> H10                                                                      
#> H11                                                                      
#> H12                                                                      
#> H13                                                                      
#> H14                                                                      
#> H15                                                                      
#> H16 1.5257009                                                            
#> H17 2.8148034 4.0297987                                                  
#> H18 1.7276112 2.9936000 1.0890523                                        
#> H19 0.2925366 1.3251713 3.0989710 2.0135135                              
#> H20 0.7661338 0.8061360 3.2888972 2.2273992 0.6511045                    
#> H21 0.4989043 1.2756316 2.7966378 1.7339926 0.5870924 0.5064689          
#> H22 1.0426202 2.2267808 1.8298329 0.7673337 1.3160904 1.4643450 0.9696446
#> H23 1.9607003 3.1805225 0.8658073 0.2491895 2.2446978 2.4281713 1.9360069
#> H24 0.2290380 1.3313017 2.8816469 1.7984553 0.3052918 0.5584031 0.3003119
#> H25 0.6589617 1.9776437 2.1771982 1.0988769 0.9297336 1.2023185 0.7102152
#>           H22       H23       H24
#> H2                               
#> H3                               
#> H4                               
#> H5                               
#> H6                               
#> H7                               
#> H8                               
#> H9                               
#> H10                              
#> H11                              
#> H12                              
#> H13                              
#> H14                              
#> H15                              
#> H16                              
#> H17                              
#> H18                              
#> H19                              
#> H20                              
#> H21                              
#> H22                              
#> H23 0.9671322                    
#> H24 1.0663845 2.0204099          
#> H25 0.4247642 1.3238750 0.7183694

## Mahalanobis distance
mahalanobis(coda)
#>         H1         H2         H3         H4         H5         H6         H7 
#>  1.9709079  0.8438243  0.9421982  2.8803179 59.3339067  3.2346153 97.1211672 
#>         H8         H9        H10        H11        H12        H13        H14 
#> 49.1635974  0.5901016 67.4288815  0.9004588  2.5335404  2.0322110 46.8670451 
#>        H15        H16        H17        H18        H19        H20        H21 
#>  1.0886501 48.2413850 19.9301611  1.0113684  1.0481611  2.0022595  2.3207166 
#>        H22        H23        H24        H25 
#>  1.9723197 24.6876086 13.4500205 19.1349096