]> git.donarmstrong.com Git - ape.git/blobdiff - R/ace.R
adding lmorigin + final correction to dist.topo
[ape.git] / R / ace.R
diff --git a/R/ace.R b/R/ace.R
index 91994bed1ffeb9a35fd2dfdc9a9bc20aa2d11384..c9a45110ca7eb926c0ca406494b30cf9cb9e9553 100644 (file)
--- a/R/ace.R
+++ b/R/ace.R
@@ -1,4 +1,4 @@
-## ace.R (2009-06-10)
+## ace.R (2009-11-12)
 
 ##   Ancestral Character Estimation
 
@@ -59,6 +59,7 @@ did not match: the former were ignored in the analysis.')
             if (model == "BM") {
                 tip <- phy$edge[, 2] <= nb.tip
                 dev.BM <- function(p) {
+                    if (p[1] < 0) return(1e100) # in case sigma² is negative
                     x1 <- p[-1][phy$edge[, 1] - nb.tip]
                     x2 <- numeric(length(x1))
                     x2[tip] <- x[phy$edge[tip, 2]]
@@ -130,9 +131,10 @@ did not match: the former were ignored in the analysis.')
             }
             if (model == "SYM") {
                 np <- nl * (nl - 1)/2
-                rate[col(rate) < row(rate)] <- 1:np
+                sel <- col(rate) < row(rate)
+                rate[sel] <- 1:np
                 rate <- t(rate)
-                rate[col(rate) < row(rate)] <- 1:np
+                rate[sel] <- 1:np
             }
         } else {
             if (ncol(model) != nrow(model))
@@ -144,9 +146,10 @@ as the number of categories in `x'")
             np <- max(rate)
         }
         index.matrix <- rate
-        index.matrix[cbind(1:nl, 1:nl)] <- NA
-        rate[cbind(1:nl, 1:nl)] <- 0
-        rate[rate == 0] <- np + 1 # to avoid 0's since we will use this an numeric indexing
+        tmp <- cbind(1:nl, 1:nl)
+        index.matrix[tmp] <- NA
+        rate[tmp] <- 0
+        rate[rate == 0] <- np + 1 # to avoid 0's since we will use this as numeric indexing
 
         liks <- matrix(0, nb.tip + nb.node, nl)
         TIPS <- 1:nb.tip