X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=R%2Fvcv.phylo.R;h=2473280424f7545ba9ae08e8be20bf422c538958;hb=f3304b6f40610d9b7306a9275d593b5c038ab0a0;hp=09e4dc3248bb4b356cce6b585ac1c160e976c93e;hpb=c827059eeafc8cbe41c812b26979543ab287803e;p=ape.git diff --git a/R/vcv.phylo.R b/R/vcv.phylo.R index 09e4dc3..2473280 100644 --- a/R/vcv.phylo.R +++ b/R/vcv.phylo.R @@ -1,16 +1,16 @@ -## vcv.phylo.R (2006-10-04) +## vcv.phylo.R (2009-11-19) ## Phylogenetic Variance-Covariance or Correlation Matrix -## Copyright 2002-2006 Emmanuel Paradis +## Copyright 2002-2009 Emmanuel Paradis ## This file is part of the R-package `ape'. ## See the file ../COPYING for licensing issues. -vcv.phylo <- function(phy, model = "Brownian", cor = FALSE) +vcv <- function(phy, ...) UseMethod("vcv") + +vcv.phylo <- function(phy, model = "Brownian", corr = FALSE, ...) { - if (class(phy) != "phylo") - stop('object "phy" is not of class "phylo"') if (is.null(phy$edge.length)) stop("the tree has no branch lengths") @@ -37,6 +37,7 @@ vcv.phylo <- function(phy, model = "Brownian", cor = FALSE) } } + phy <- reorder(phy) n <- length(phy$tip.label) n.node <- phy$Nnode N <- n.node + n @@ -44,7 +45,7 @@ vcv.phylo <- function(phy, model = "Brownian", cor = FALSE) foo(n + 1, 0, dim(phy$edge)[1]) vcv <- vcv[1:n, 1:n] - if (cor) { + if (corr) { ## This is inspired from the code of `cov2cor' (2005-09-08): M <- vcv Is <- sqrt(1/M[1 + 0:(n - 1)*(n + 1)]) @@ -54,3 +55,12 @@ vcv.phylo <- function(phy, model = "Brownian", cor = FALSE) rownames(vcv) <- colnames(vcv) <- phy$tip.label vcv } + +vcv.corPhyl <- function(phy, corr = FALSE, ...) +{ + labels <- attr(phy, "tree")$tip.label + dummy.df <- data.frame(1:length(labels), row.names = labels) + res <- nlme::corMatrix(Initialize.corPhyl(phy, dummy.df), corr = corr) + dimnames(res) <- list(labels, labels) + res +}