]> git.donarmstrong.com Git - ape.git/blob - man/dbd.Rd
new files for ape 3.0
[ape.git] / man / dbd.Rd
1 \name{dbd}
2 \alias{dyule}
3 \alias{dbd}
4 \alias{dbdTime}
5 \title{Probability Density Under Birth--Death Models}
6 \description{
7   These functions compute the probability density under some
8   birth--death models, that is the probability of obtaining \emph{x}
9   species after a time \emph{t} giving how speciation and extinction
10   probabilities vary through time (these may be constant, or even equal
11   to zero for extinction).
12 }
13 \usage{
14 dyule(x, lambda = 0.1, t = 1, log = FALSE)
15 dbd(x, lambda, mu, t, conditional = FALSE, log = FALSE)
16 dbdTime(x, birth, death, t, conditional = FALSE,
17         BIRTH = NULL, DEATH = NULL, fast = FALSE)
18 }
19 \arguments{
20   \item{x}{a numeric vector of species numbers (see Details).}
21   \item{lambda}{a numerical value giving the probability of speciation;
22     can be a vector with several values for \code{dyule}.}
23   \item{mu}{id. for extinction.}
24   \item{t}{id. for the time(s).}
25   \item{log}{a logical value specifying whether the probabilities should
26     be returned log-transformed; the default is \code{FALSE}.}
27   \item{conditional}{a logical specifying whether the probabilities
28     should be computed conditional under the assumption of no extinction
29     after time \code{t}.}
30   \item{birth, death}{a (vectorized) function specifying how the
31     speciation or extinction probability changes through time (see
32     \code{\link{yule.time}} and below).}
33   \item{BIRTH, DEATH}{a (vectorized) function giving the primitive
34     of \code{birth} or \code{death}.}
35   \item{fast}{a logical value specifying whether to use faster
36     integration (see \code{\link{bd.time}}).}
37 }
38 \details{
39   These three functions compute the probabilities to observe \code{x}
40   species starting from a single one after time units \code{t} (assumed
41   to be continuous). The first one is a short-cut for the second with
42   \code{mu = 0} and with default values for the two other parameters.
43   \code{dbdTime} is for time-varying \code{lambda} and \code{mu}
44   specified as \R functions.
45
46   Only \code{dyule} is vectorized simultaneously on its three arguments
47   \code{x}, \code{lambda}, and \code{t}, according to \R's rules of
48   recycling arguments. The two others are vectorized only on \code{x};
49   the other arguments are eventually shortened with a warning if
50   necessary.
51
52   The returned value is, logically, zero for values of \code{x} out of
53   range, i.e., negative or zero for \code{dyule} or if \code{conditional
54   = TRUE}. However, it is not checked if the values of \code{x} are
55   non-integers and the probabilities are computed and returned.
56
57   The details on the form of the arguments \code{birth}, \code{death},
58   \code{BIRTH}, \code{DEATH}, and \code{fast} can be found in the links
59   below.
60 }
61 \note{
62   If you use these functions to calculate a likelihood function, it is
63   strongly recommended to compute the log-likelihood with, for instance
64   in the case of a Yule process, \code{sum(dyule( , log = TRUE))} (see
65   examples).
66 }
67 \value{
68   a numeric vector.
69 }
70 \references{
71   Kendall, D. G. (1948) On the generalized ``birth-and-death''
72   process. \emph{Annals of Mathematical Statistics}, \bold{19}, 1--15.
73 }
74 \author{Emmanuel Paradis}
75 \seealso{
76   \code{\link{bd.time}},  \code{\link{yule.time}}
77 }
78 \examples{
79 x <- 0:10
80 plot(x, dyule(x), type = "h", main = "Density of the Yule process")
81 text(7, 0.85, expression(list(lambda == 0.1, t == 1)))
82
83 y <- dbd(x, 0.1, 0.05, 10)
84 z <- dbd(x, 0.1, 0.05, 10, conditional = TRUE)
85 d <- rbind(y, z)
86 colnames(d) <- x
87 barplot(d, beside = TRUE, ylab = "Density", xlab = "Number of species",
88         legend = c("unconditional", "conditional on\nno extinction"),
89         args.legend = list(bty = "n"))
90 title("Density of the birth-death process")
91 text(17, 0.4, expression(list(lambda == 0.1, mu == 0.05, t == 10)))
92
93 \dontrun{
94 ### generate 1000 values from a Yule process with lambda = 0.05
95 x <- replicate(1e3, Ntip(rlineage(0.05, 0)))
96
97 ### the correct way to calculate the log-likelihood...:
98 sum(dyule(x, 0.05, 50, log = TRUE))
99
100 ### ... and the wrong way:
101 log(prod(dyule(x, 0.05, 50)))
102
103 ### a third, less preferred, way:
104 sum(log(dyule(x, 0.05, 50)))
105 }}
106 \keyword{utilities}