I am trying to transform a distance matrix from the qiime2 pathway using a centred log ratio in R. I uploaded the matrix directly from a qiime2 output file, and have converted to a data matrix and have checked that it is symmetrical.
structure(list(X1 = c(0, 0.2177609998, 0.2133361674, 0.1549136105, 0.1400395799), X11 = c(0.2177609998, 0, 0.07805820645, 0.1418994689, 0.1934668819), X12 = c(0.2133361674, 0.07805820645, 0, 0.1475390242, 0.1857477705), X13 = c(0.1549136105, 0.1418994689, 0.1475390242, 0, 0.1046740994), X14 = c(0.1400395799, 0.1934668819, 0.1857477705, 0.1046740994, 0)), row.names = c("X1", "X11", "X12", "X13", "X14"), class = "data.frame")
dm <- read.csv(file = "dm.csv", header = TRUE, row.names = 1)
isSymmetric(as.matrix(dm)) [1] TRUE
dm_matrix <- (data.matrix(dm, rownames.force = NA))
I then tried to transform the dataset using the dm_matrix_clr <- data.frame(clr(dm_matrix))
function from the 'compositions' package. This produced an output, however it was not symmetrical. From my understanding, the transformed distance matrix should be symmetric like the input matrix. The same numbers on opposing sides of the diagonal are being transformed, but are resulting in different outputs.
structure(list(X1 = c(0, 0.0457712675241166, 0.0645864307368655, -0.132814225855358, -0.169506999372974), X11 = c(0.145063977547214, 0, -0.940827956615993, -0.220562994401166, 0.153674249252163), X12 = c(0.124535019646299, -0.980172077729657, 0, -0.181589124148918, 0.11295758523629), X13 = c(-0.195466542710371, -0.382508021279277, -0.304190029913364, 0, -0.460580387503147), X14 = c(-0.296409056413787, -0.0725205178117472, -0.0738930607139561, -0.524830127688946, 0)), row.names = c("X1", "X11", "X12", "X13", "X14"), class = "data.frame")
Any help on how resolve this problem so I have a symmetrical transformed distance matrix would be greatly appreciated.