-## ace.R (2012-06-25)
+## ace.R (2013-01-31)
## Ancestral Character Estimation
-## Copyright 2005-2012 Emmanuel Paradis and Ben Bolker
+## Copyright 2005-2013 Emmanuel Paradis and Ben Bolker
## This file is part of the R-package `ape'.
## See the file ../COPYING for licensing issues.
ace <- function(x, phy, type = "continuous", method = "ML", CI = TRUE,
model = if (type == "continuous") "BM" else "ER",
- scaled = TRUE, kappa = 1, corStruct = NULL, ip = 0.1)
+ scaled = TRUE, kappa = 1, corStruct = NULL, ip = 0.1,
+ use.expm = FALSE)
{
if (!inherits(phy, "phylo"))
stop('object "phy" is not of class "phylo"')
liks[cbind(TIPS, x)] <- 1
phy <- reorder(phy, "pruningwise")
+ E <- if (use.expm) expm::expm else ape::matexpo
+
Q <- matrix(0, nl, nl)
dev <- function(p, output.liks = FALSE) {
if (any(is.nan(p)) || any(is.infinite(p))) return(1e50)
anc <- phy$edge[i, 1]
des1 <- phy$edge[i, 2]
des2 <- phy$edge[j, 2]
- v.l <- matexpo(Q * phy$edge.length[i]) %*% liks[des1, ]
- v.r <- matexpo(Q * phy$edge.length[j]) %*% liks[des2, ]
+ v.l <- E(Q * phy$edge.length[i]) %*% liks[des1, ]
+ v.r <- E(Q * phy$edge.length[j]) %*% liks[des2, ]
v <- v.l * v.r
comp[anc] <- sum(v)
liks[anc, ] <- v/comp[anc]