Created
March 17, 2022 12:18
-
-
Save zdealveindy/3426f11ce5774742b953c82b03e43b03 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Euclidean vs Hellinger vs Bray-Curtis distances and double zero problem | |
library (vegan) | |
library (pals) | |
vltava.spe <- read.delim ('https://raw.githubusercontent.com/zdealveindy/anadat-r/master/data/vltava-spe.txt', row.names = 1) | |
prop_dz <- function (com) | |
(nrow (com)-designdist (x = com, method = "A+B-J", terms = "binary"))/nrow (com) # calculates proportion of double zeros | |
D_eucl <- dist (vltava.spe, method = 'euclidean') | |
D_hell <- dist (decostand (vltava.spe, method = 'hell'), method = 'euclidean') | |
D_bray <- vegdist (vltava.spe, method = 'bray') | |
D_eucl_log <- dist (log1p (vltava.spe), method = 'euclidean') | |
D_hell_log <- dist (decostand (log1p (vltava.spe), method = 'hell'), method = 'euclidean') | |
D_bray_log <- vegdist (log1p (vltava.spe), method = 'bray') | |
D_eucl_pa <- dist (decostand (vltava.spe, 'pa'), method = 'euclidean') | |
D_hell_pa <- dist (decostand (decostand (vltava.spe, method = 'pa'), method = 'hell'), method = 'euclidean') | |
D_bray_pa <- vegdist (decostand (vltava.spe, method = 'pa'), method = 'bray') | |
double_zeros <- prop_dz (vltava.spe) | |
png ('dist_vs_doublezeros.png', width = 10, height = 10, res = 300, units = 'in', pointsize = 16) | |
par (mfrow = c(3,3)) | |
plot (D_eucl ~ double_zeros, main = 'Raw data') | |
legend ('topright', bty = 'n', legend = '(a)') | |
plot (D_eucl_log ~ double_zeros, main = 'Log-transformed data') | |
legend ('topright', bty = 'n', legend = '(b)') | |
plot (D_eucl_pa ~ double_zeros, main = 'Presence-absence data') | |
legend ('topright', bty = 'n', legend = '(c)') | |
plot (D_hell ~ double_zeros) | |
legend ('topright', bty = 'n', legend = '(d)') | |
plot (D_hell_log ~ double_zeros) | |
legend ('topright', bty = 'n', legend = '(e)') | |
plot (D_hell_pa ~ double_zeros) | |
legend ('topright', bty = 'n', legend = '(f)') | |
plot (D_bray ~ double_zeros) | |
legend ('topright', bty = 'n', legend = '(g)') | |
plot (D_bray_log ~ double_zeros) | |
legend ('topright', bty = 'n', legend = '(h)') | |
plot (D_bray_pa ~ double_zeros) | |
legend ('topright', bty = 'n', legend = '(i)') | |
dev.off () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment