ape (version 1.2-6)

Correlogram: Compute a correlogram

Description

Compute a correlogram from taxonomic variables or from a phylogenetic tree with branch lengths. The first method relies on the dist.taxo function, and the second relies on the discrete.dist function. Both methods send an object of class 'correlogram' to be plotted by the plot.correlogram method.

Usage

correlogram.formula(formula, data)
  correlogram.phylo(x, phy, nclass = NULL, breaks = NULL)

Arguments

x
a vector containing the data to plot
formula
a formula of the kind y ~ g1/../gn, where y is the data to plot and all g are the nested levels
data
a dataframe containing all variables in the formula
phy
an object of class "phylo" width edge lengths
breaks,nclass
The class bounds or the number of classes to use. If both are NULL, compute Moran's I on the whole distance matrix.

Value

  • An object of class 'correlogram', containing:
  • obsall measured Moran's I
  • p.valuesthe p-values of each I
  • labelsthe names of each level

Warning

correlogram.phylo will return NAs if void classes are used. This may happen if breaks if not properly defined, or sometimes with the nclass= argument, depending on the tree used. Usually, you'll have to pull classes.

Details

See example of the Moran.I function to see how the correlogram.formula function works. To deal with phylogenies, the correlogram.phylo function creates classes according to distances intervals. Such intervals may be specified using the breaks argument or by giving a number of classes (nclass argument).

See Also

plot.correlogram

Examples

Run this code
library(ape)### (the same analysis than in help(pic)...)
  data(carnivora)
  # Using the formula interface:
  co <- correlogram.formula(log10(SW) ~ Order/SuperFamily/Family/Genus, data=carnivora)
  co
  plot(co)

  # Using the phylo interface:
  cat("((((Homo:0.21,Pongo:0.21):0.28,",
     "Macaca:0.49):0.13,Ateles:0.62):0.38,Galago:1.00);",
     file = "ex.tre", sep = "")
  tree.primates <- read.tree("ex.tre")
  X <- c(4.09434, 3.61092, 2.37024, 2.02815, -1.46968)
  Y <- c(4.74493, 3.33220, 3.36730, 2.89037, 2.30259)
  # Since this is a small tree, 2 classes is a reasonable number:
  coX <- correlogram.phylo(X, tree.primates, nclass=2)
  coY <- correlogram.phylo(Y, tree.primates, nclass=2)
  plot(coX)
  plot(coY)
  # Nothing significant...
  # Computing Moran's I on the whole matrix:
  coX2 <- correlogram.phylo(X, tree.primates); coX2
  # Significant at the 5% level
  coY2 <- correlogram.phylo(Y, tree.primates); coY2
  # Not significant
  unlink("ex.tre") # delete the file "ex.tre"

Run the code above in your browser using DataCamp Workspace