]> git.donarmstrong.com Git - ape.git/blobdiff - R/chronopl.R
final update for ape 2.7-1
[ape.git] / R / chronopl.R
index 3139906c2e76af61601061bb9e4cceda99582f40..570fa2602fbd9166199c5f68dc6e81fb6b73a4f6 100644 (file)
@@ -1,15 +1,16 @@
-## chronopl.R (2008-03-26)
+## chronopl.R (2009-07-06)
 
 ##   Molecular Dating With Penalized Likelihood
 
-## Copyright 2005-2008 Emmanuel Paradis
+## Copyright 2005-2009 Emmanuel Paradis
 
 ## This file is part of the R-package `ape'.
 ## See the file ../COPYING for licensing issues.
 
-chronopl <- function(phy, lambda, age.min = 1, age.max = NULL,
-                     node = "root", S = 1, tol = 1e-8,
-                     CV = FALSE, eval.max = 500, iter.max = 500, ...)
+chronopl <-
+    function(phy, lambda, age.min = 1, age.max = NULL,
+             node = "root", S = 1, tol = 1e-8,
+             CV = FALSE, eval.max = 500, iter.max = 500, ...)
 {
     n <- length(phy$tip.label)
     ROOT <- n + 1
@@ -84,27 +85,23 @@ chronopl <- function(phy, lambda, age.min = 1, age.max = NULL,
         real.edge.length <- ini.time[e[, 1]] - ini.time[e[, 2]]
         while (any(real.edge.length <= 0)) {
             for (i in EDGES) {
-                if (real.edge.length[i] <= 0) {
-                    if (e[i, 1] %in% node) {
-                        ini.time[e[i, 2]] <-
-                            ini.time[e[, 2]] - 2*real.edge.length[i]
-                        next
-                    }
-                    if (e[i, 2] %in% node) {
-                        ini.time[e[i, 1]] <-
-                            ini.time[e[, 1]] + 2*real.edge.length[i]
-                        next
-                    }
-                    ini.time[e[i, 2]] <-
-                        ini.time[e[, 2]] - real.edge.length[i]
-                    ini.time[e[i, 1]] <-
-                        ini.time[e[, 1]] + real.edge.length[i]
+                if (real.edge.length[i] > 0) next
+                if (e[i, 1] %in% node) {
+                    ini.time[e[i, 2]] <- ini.time[e[1, 2]] - 2 * real.edge.length[i]
+                    next
                 }
+                if (e[i, 2] %in% node) {
+                    ini.time[e[i, 1]] <- ini.time[e[1, 1]] + 2 * real.edge.length[i]
+                    next
+                }
+                browser()
+                ini.time[e[i, 2]] <- ini.time[e[1, 2]] - real.edge.length[i]
+                ini.time[e[i, 1]] <- ini.time[e[1, 1]] + real.edge.length[i]
             }
             real.edge.length <- ini.time[e[, 1]] - ini.time[e[, 2]]
+            print(min(real.edge.length))
         }
     }
-
     ## `unknown.ages' will contain the index of the nodes of unknown age:
     unknown.ages <- n + 1:m
 
@@ -231,6 +228,8 @@ chronopl.cv <- function(ophy, lambda, age.min, age.max, nodes,
         if (length(node)) {
             chr <- chronopl(tr, lambda, age.min, age.max, node,
                             S, tol, FALSE, eval.max, iter.max, ...)
+            tmp <-
+                if (Nnode(chr) == Nnode(ophy)) BT else BT[-(ophy$edge[j, 1] - n)]
             D2[i] <- sum((tmp - branching.times(chr))^2 / tmp)
         } else D2[i] <- 0
     }