R Under development (unstable) (2024-05-20 r86569 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > # Test data > # data(varespec) > testdata <- matrix(round(runif(1000, 0, 100)), nrow=20) > testdata <- testdata - 50 > testdata[testdata < 0] <- 0 > rownames(testdata) <- paste0("row", seq_len(nrow(testdata))) > colnames(testdata) <- paste0("col", seq_len(ncol(testdata))) > > # Calculates relative abundance table > relative <- vegan::decostand(testdata, "total") > > # Count and relative data with pseudocount > testdata.with.pseudo <- testdata + 1 > relative.with.pseudo <- vegan::decostand(testdata+1, "total") > > # aitchison equals to CLR + Euclid (pseudocount is necessary with clr) > a1 <- vegan::vegdist(testdata+1, method = "aitchison") > a2 <- vegan::vegdist(vegan::decostand(testdata+1, "clr"), method = "euclidean") > max(abs(a1-a2)) < 1e-6 # Tolerance [1] TRUE > > # Robust aitchison equals to rCLR + Euclid > # and works without pseudocount > a1 <- vegan::vegdist(testdata, method = "robust.aitchison") > a2 <- vegan::vegdist(vegan::decostand(testdata, "rclr"), method = "euclidean") > max(abs(a1-a2)) < 1e-6 # Tolerance [1] TRUE > > # Robust aitchison and aitchison are equal when there are no zeroes > a1 <- vegan::vegdist(testdata.with.pseudo, method = "robust.aitchison") > a2 <- vegan::vegdist(testdata.with.pseudo, method = "aitchison") > max(abs(a1-a2)) < 1e-6 # Tolerance [1] TRUE > > # It is possible to pass pseudocount as a function argument to vegan::decostand > a1 <- vegan::vegdist(testdata, method = "aitchison", pseudocount=1) > a2 <- vegan::vegdist(testdata+1, method = "aitchison") > max(abs(a1-a2)) < 1e-6 # Tolerance [1] TRUE > > > # Compare the outcomes with an external package that also provides compositional transformations > # Adding these would demand adding Suggested packages in DESCRIPTION; skipped for now but can be > # useful for manual testing. > #skip <- TRUE > #if (!skip) { > # > # sum(compositions::clr(testdata.with.pseudo) - vegan::decostand(testdata.with.pseudo, "clr")) < 1e-6 > # sum(compositions::clr(testdata.with.pseudo) - vegan::decostand(testdata.with.pseudo, "clr", MARGIN=1)) < 1e-6 > # sum(t(compositions::clr(t(testdata.with.pseudo))) - vegan::decostand(testdata.with.pseudo, "clr", MARGIN=2)) < 1e-6 > # sum(rgr::clr(testdata.with.pseudo) - vegan::decostand(testdata.with.pseudo, "clr"))<1e-6# > # > # sum(compositions::alr(testdata.with.pseudo, ivar=1) - vegan::decostand(testdata.with.pseudo, "alr")) < 1e-6 > # sum(compositions::alr(testdata.with.pseudo, ivar=1) - vegan::decostand(testdata.with.pseudo, "alr", MARGIN=1)) < 1e-6 > # sum(t(compositions::alr(t(testdata.with.pseudo), ivar=1)) - vegan::decostand(testdata.with.pseudo, "alr", MARGIN=2)) < 1e-6 > # sum(rgr::alr(testdata.with.pseudo, j=1) - vegan::decostand(testdata.with.pseudo, "alr", reference=1))<1e-6# > # > #} > > # -------------------------------------------------------------------------------------------------------------- > > > proc.time() user system elapsed 0.84 0.12 0.95