]> git.donarmstrong.com Git - ape.git/blobdiff - R/birthdeath.R
final version for ape 2.6-1
[ape.git] / R / birthdeath.R
index 469eef5d4089de159da3edad877904d70ccc0584..b4a25e17505aa835af535fd694c80ecabd609b73 100644 (file)
@@ -1,4 +1,4 @@
-## birthdeath.R (2007-10-30)
+## birthdeath.R (2010-10-17)
 
 ##   Estimation of Speciation and Extinction Rates
 ##             with Birth-Death Models
@@ -6,17 +6,18 @@
 ## birthdeath: standard model
 ## bd.ext: extended version
 
-## Copyright 2002-2007 Emmanuel Paradis
+## Copyright 2002-2010 Emmanuel Paradis
 
 ## This file is part of the R-package `ape'.
 ## See the file ../COPYING for licensing issues.
 
 birthdeath <- function(phy)
 {
-    if (class(phy) != "phylo") stop('object "phy" is not of class "phylo"')
+    if (!inherits(phy, "phylo")) stop('object "phy" is not of class "phylo"')
     N <- length(phy$tip.label)
     x <- c(NA, branching.times(phy))
     dev <- function(a, r) {
+        if (r <= 0) return(1e50)
         -2 * (lfactorial(N - 1)
               + (N - 2) * log(r)
               + r * sum(x[3:N])
@@ -80,11 +81,11 @@ print.birthdeath <- function(x, ...)
 
 bd.ext <- function(phy, S)
 {
-    if (class(phy) != "phylo") stop('object "phy" is not of class "phylo"')
+    if (!inherits(phy, "phylo")) stop('object "phy" is not of class "phylo"')
     if (!is.null(names(S))) {
         if (all(names(S) %in% phy$tip.label)) S <- S[phy$tip.label]
-        else warning('the names of argument "S" and the names of the tip labels
-did not match: the former were ignored in the analysis.')
+        else warning('the names of argument "S" and the tip labels
+did not match: the former were ignored.')
     }
     N <- length(S)
     x <- branching.times(phy)