data(Doubs)
## Removing any species that have not been not observed:
Doubs.fish -> x
x[rowSums(x)!=0,] -> x
## Transforming the abundances
LGTransforms(x,"chord") -> chord
LGTransforms(x,"chord",offset=1,power=0) -> log.chord
LGTransforms(x,"chord",power=0.25) -> pow.chord
LGTransforms(x,"chisq") -> chisq
LGTransforms(x,"profile") -> sp_pr
LGTransforms(x,"Hellinger") -> Helli
dist(chord)
dist(log.chord)
dist(pow.chord)
dist(chisq)
dist(sp_pr)
dist(Helli)
## Legendre & Gallagher synthetic examples:
data(LGDat)
## Diastemograms:
as.matrix(dist(LGDat[,1L])) -> geo
geo[upper.tri(geo)] -> geo
## Raw Euclidean distances
par(mfrow=c(1,1), mar=c(5,5,4,2))
as.matrix(dist(LGDat[,-1L])) -> eco
eco[upper.tri(eco)] -> eco
plot(eco~geo, data=data.frame(geo=geo, eco=eco),
xaxp=c(1,18,17), las=1, ylim=c(0,max(eco)),
xlab="True geographic distance",
ylab="Euclidean distance")
## Euclidean distances on the transformed abundances:
par(mfrow=c(3,2), mar=c(3,5,4,2))
LGTransforms(LGDat[,-1L],"chord") -> chord
as.matrix(dist(chord)) -> eco
eco[upper.tri(eco)] -> eco
plot(eco~geo,data=data.frame(geo=geo,eco=eco),
xaxp=c(1,18,17),las=1,xlab="",ylab="",
main="Chord distance",ylim=c(0,max(eco)))
LGTransforms(LGDat[,-1L],"chord",offset=1,power=0) -> log.chord
as.matrix(dist(log.chord)) -> eco
eco[upper.tri(eco)] -> eco
plot(eco~geo,data=data.frame(geo=geo,eco=eco),
xaxp=c(1,18,17),las=1,xlab="",ylab="",
main="Chord distance (log(x+1))",ylim=c(0,max(eco)))
par(mar=c(4,5,3,2))
LGTransforms(LGDat[,-1L],"chord",power=0.25) -> pow.chord
as.matrix(dist(pow.chord)) -> eco
eco[upper.tri(eco)] -> eco
plot(eco~geo,data=data.frame(geo=geo,eco=eco),
xaxp=c(1,18,17),las=1,xlab="",ylab="",
main="Chord distance (power=0.25)",ylim=c(0,max(eco)))
LGTransforms(LGDat[,-1L],"chisq") -> chisq
as.matrix(dist(chisq)) -> eco
eco[upper.tri(eco)] -> eco
plot(eco~geo,data=data.frame(geo=geo,eco=eco),
xaxp=c(1,18,17),las=1,xlab="",ylab="",
main="Chi-square distance",ylim=c(0,max(eco)))
par(mar=c(5,5,2,2))
LGTransforms(LGDat[,-1L],"profile") -> sp_pr
as.matrix(dist(sp_pr)) -> eco
eco[upper.tri(eco)] -> eco
plot(eco~geo,data=data.frame(geo=geo,eco=eco),
xaxp=c(1,18,17),las=1,xlab="",ylab="",
main="Dist. between profiles",ylim=c(0,max(eco)))
LGTransforms(LGDat[,-1L],"Hellinger") -> Helli
as.matrix(dist(Helli)) -> eco
eco[upper.tri(eco)] -> eco
plot(eco~geo,data=data.frame(geo=geo,eco=eco),
xaxp=c(1,18,17),las=1,xlab="",ylab="",
main="Hellinger distance",ylim=c(0,max(eco)))
mtext(text="True geographic distance", side=1, line=-1.5, outer=TRUE)
mtext(text="Ecological distance", side=2, line=-1.5, outer=TRUE)
## Examples from Legendre & Legendre 2012, page 329 (Figure 7.8):
matrix(c(0,0,1,4,1,0,8,1,0),3L,3L) -> LL329
## D1: Euclidean distance
dist(LL329)
## Chord transformation (D3: chord distance)
LGTransforms(LL329,"chord") -> tr
tr
dist(tr)
## "Species profile" transformation (D18)
LGTransforms(LL329,"profile") -> tr
tr
dist(tr)
## Hellinger transformation (D17: Hellinger distance)
LGTransforms(LL329,"Hellinger") -> tr
tr
dist(tr)
## Chi-square transformation (D16: Chi-square distance)
LGTransforms(LL329,"chisq") -> tr
tr
dist(tr)
Run the code above in your browser using DataLab