Learn R Programming

ecodist (version 1.01)

ecodist-package: Dissimilarity-based functions for ecological analysis

Description

Dissimilarity-based analysis functions including ordination and Mantel test functions with multiple partials, intended for use with spatial and community data.

Arguments

Details

ll{ Package: ecodist Version: 1.00 Date: 2006-03-02 Depends: stats License: GPL version 2 or newer Packaged: Mon Mar 27 10:50:11 2006; sarahg Built: R 2.2.1; i686-redhat-linux-gnu; 2006-03-27 10:54:52; unix }

Index: bcdist Bray-Curtis distance cor2m Generates a correlation table between the variables of 2 matrices crosstab Data formatting distance Calculate dissimilarity/distance metrics fixdmat Distance matrix conversion full Full symmetric matrix lower Lower-triangular matrix mantel Mantel test mgram Mantel correlogram nmds Non-metric multidimensional scaling nmds.min Find minimum stress configuration pco Principal coordinates analysis plotmgram Plot a Mantel correlogram plotvf Plots fitted vectors onto an ordination diagram pmgram Partial Mantel correlogram vf Vector fitting

Examples

Run this code
## Distance example using a subset of the built-in iris dataset
data(iris)
iris <- iris[seq(1, 150, by=3),]
iris.md <- distance(iris[,1:4], "mahal")
iris.bc <- bcdist(iris[,1:4])

# compare Mahalanobis and Bray-Curtis dissimilarities
plot(iris.md, iris.bc, xlab="Mahalanobis", ylab="Bray-Curtis")


## NMDS example
# Example of multivariate analysis using built-in iris dataset

# Minimum-stress 2-dimensional nonmetric multidimensional scaling configuration
# Uses small number of separate ordinations (5) to increase speed of example.
# Use more for final analysis.
iris.nmds <- nmds(iris.md, mindim=2, maxdim=2, nits=3)
iris.nmin <- nmds.min(iris.nmds)

# Plot NMDS result with symbols denoting species
plot(iris.nmin, pch=as.numeric(iris[,5]))

# Fit vectors for the main variables to the NMDS configuration
iris.vf <- vf(iris.nmin, iris[,1:4], nperm=10)
plotvf(iris.vf, col="blue")


## PCO example

iris.pco <- pco(iris.md)
# scatterplot of the first two dimensions
plot(iris.pco$vectors[,1], iris.pco$vectors[,2], pch=as.numeric(iris[,5]))


## Mantel test example

# Example of multivariate analysis using built-in iris dataset

# Create a model matrix for testing species differences
iris.model <- distance(as.numeric(iris[,5]), "eucl")
iris.model[iris.model > 0] <- 1

# Test whether samples within the same species are more similar than those not
# Use very low numbers of permutations to increase speed.
# Use many permutations for final analyses!
mantel(iris.md ~ iris.model, nperm=100, nboot=0)


## Mantel correlogram example

# generate a simple surface
x <- matrix(1:10, nrow=10, ncol=10, byrow=FALSE)
y <- matrix(1:10, nrow=10, ncol=10, byrow=TRUE)
z <- x + 3*y
image(z)

# analyze the pattern of z across space
space <- cbind(as.vector(x), as.vector(y))
z <- as.vector(z)
space.d <- distance(space, "eucl")
z.d <- distance(z, "eucl")
z.mgram <- mgram(z.d, space.d, nperm=0)
plotmgram(z.mgram)


## Partial Mantel correlogram example
# generate a simple surface
x <- matrix(1:10, nrow=10, ncol=10, byrow=FALSE)
y <- matrix(1:10, nrow=10, ncol=10, byrow=TRUE)
z1 <- x + 3*y
z2 <- 2*x - y

# look at patterns
par(mfrow=c(1,2))
image(z1)
image(z2)

# analyze the pattern of z across space
z1 <- as.vector(z1)
z2 <- as.vector(z2)
z1.d <- distance(z1, "eucl")
z2.d <- distance(z2, "eucl")

space <- cbind(as.vector(x), as.vector(y))
space.d <- distance(space, "eucl")

# take partial correlogram of z2 on the residuals of z1 ~ space.d
z.pmgram <- pmgram(z1.d, space.d, z2.d, nperm=0)
par(mfrow=c(1,1))
plotmgram(z.pmgram, pval=0.1)

Run the code above in your browser using DataLab