ape (version 1.5)

Moran.I: Moran's I Autocorrelation Index

Description

Computes Moran's I autocorrelation index of a given vector x according to a distance weights matrix dist using the method described by Gittleman and Kot (1990).

Usage

Moran.I(x, dist, scaled = FALSE, na.rm = FALSE)

Arguments

x
a numeric vector.
dist
a distance weigths matrix.
scaled
logical, indicate whether the index should be scaled to allow comparisons between indices (default to FALSE).
na.rm
a logical value indicating whether 'NA' values in 'x' should be stripped before the computation proceeds.

Value

  • A list containing the attributes:
  • observedMoran's I index of x.
  • expectedExpected value of I under the null hypothesis.
  • sdThe standard deviation of I under the null hypothesis.
  • p.valueThe p-value of having the observed value under the null hypothesis.

Details

The dist matrix is used as distance weights, and Moran's I indice is computed using the formula: $$I = \frac{n}{S_0} \frac{\sum_{i=1}^n\sum_{j=1}^n w_{i,j}(y_i - \overline{y})(y_j - \overline{y})}{\sum_{i=1}^n {(y_i - \overline{y})}^2}$$ with
  • $y_i$= observations
  • $w_{i,j}$= distance weight
  • $n$= number of observations
  • $S_0$=$\sum_{i=1}^n\sum_{j=1}^n wij$
The value of I may be evaluated under two null hypotheses, normality and randomization. Only the randomization hypothesis is implemented for now.

The 'na.rm' option is forwarded to all 'sd', 'sum' and 'mean' functions used in computations. Note that 'NA' values are allowed only in 'x' and not in 'dist'.

References

Gittleman, J. L. and Kot, M. (1990) Adaptation: statistics and a null model for estimating phylogenetic effects. Systematic Zoology, 39, 227--241.

See Also

dist.phylo, discrete.dist, dist.taxo

Examples

Run this code
### This will draw the correlogram from Gittleman and Kot 1990
### This is only for example, consider function plot.correlogram()
### to draw correlograms.
library(ape)
data(carnivora)
attach(carnivora)
# Compute distance matrix for each taxonomic level:
dG  <- dist.taxo(Genus)
dF  <- dist.taxo(Family)
dSF <- dist.taxo(SuperFamily)
dO  <- dist.taxo(Order)
# We draw the correlogram of average body weights,
# with log10-transformed variable:
IG  <- Moran.I(log10(SW), dG        , scale=TRUE)
IF  <- Moran.I(log10(SW), dF  & !dG , scale=TRUE)
ISF <- Moran.I(log10(SW), dSF & !dF , scale=TRUE)
IO  <- Moran.I(log10(SW), dO  & !dSF, scale=TRUE)
# All Moran's I indices:
i <- c(IG$obs, IF$obs, ISF$obs, IO$obs)
# With their corresponding p-values:
p <- c(IG$p.v, IF$p.v, ISF$p.v, IO$p.v)
# Here's the legend:
l <- c("G", "F", "SF", "O")
# Draw the correlogram (using lattice library):
library(lattice)
# New Black & White device:
trellis.device(device=X11, new=FALSE, color=FALSE)
# Black circles are significant at the 5% level:
pch <- ifelse(p < 0.05, 19, 21)
# Plot it!
xyplot(i~ordered(l,levels=l), type="b", xlab="Rank", ylab="I / Imax",
    lty=2, lwd=2, cex=1.5, pch=pch, ylim=c(-0.75,0.75))

Run the code above in your browser using DataCamp Workspace