3 \title{Continuous Character Simulation}
5 rTraitCont(phy, model = "BM", sigma = 0.1, alpha = 1, theta = 0,
6 ancestor = FALSE, root.value = 0, linear = TRUE, ...)
9 \item{phy}{an object of class \code{"phylo"}.}
10 \item{model}{a character (either \code{"BM"} or \code{"OU"}) or a
11 function specifying the model (see details).}
12 \item{sigma}{a numeric vector giving the standard-deviation of the
13 random component for each branch (can be a single value).}
14 \item{alpha}{if \code{model = "OU"}, a numeric vector giving the
15 strength of the selective constraint for each branch (can be a
17 \item{theta}{if \code{model = "OU"}, a numeric vector giving the
18 optimum for each branch (can be a single value).}
19 \item{ancestor}{a logical value specifying whether to return the
20 values at the nodes as well (by default, only the values at the tips
22 \item{root.value}{a numeric giving the value at the root.}
23 \item{linear}{a logical indicating which parameterisation of the OU
24 model to use (see details).}
25 \item{\dots}{further arguments passed to \code{model} if it is a
29 This function simulates the evolution of a continuous character along a
30 phylogeny. The calculation is done recursively from the root. See
31 Paradis (2006, p. 151) for a brief introduction.
34 There are three possibilities to specify \code{model}:
37 \item{\code{"BM"}:}{a Browian motion model is used. If the arguments
38 \code{sigma} has more than one value, its length must be equal to the
39 the branches of the tree. This allows to specify a model with variable
40 rates of evolution. You must be careful that branch numbering is done
41 with the tree in ``pruningwise'' order: to see the order of the branches
42 you can use: \code{tr <- reorder(tr, "p"); plor(tr); edgelabels()}.
43 The arguments \code{alpha} and \code{theta} are ignored.}
45 \item{\code{"OU"}:}{an Ornstein-Uhlenbeck model is used. The above
46 indexing rule is used for the three parameters \code{sigma},
47 \code{alpha}, and \code{theta}. This may be more interesting for the
48 last one to model varying phenotypic optima.
50 By default the following formula is used:
52 \deqn{x_{t''} = x_{t'} - \alpha l (x_{t'} - \theta) + \sigma
53 l \epsilon}{x(t'') = x(t') - alpha l (x(t') - theta) + sigma
56 where \eqn{l (= t'' - t')} is the branch length, and \eqn{\epsilon
57 \sim N(0, 1)}{\epsilon ~ N(0, 1)}. If \eqn{\alpha > 1}{alpha > 1},
58 this may lead to chaotic oscillations. Thus an alternative
59 parameterisation is used if \code{linear = FALSE}:
61 \deqn{x_{t''} = x_{t'} - (1 - exp(-\alpha l)) * (x_{t'} - \theta) +
62 \sigma l \epsilon}{x(t'') = x(t') - (1 - exp(-alpha l)) * (x(t') -
63 theta) + sigma l epsilon}}
65 \item{A function:}{it must be of the form \code{foo(x, l)} where
66 \code{x} is the trait of the ancestor and \code{l} is the branch
67 length. It must return the value of the descendant. The arguments
68 \code{sigma}, \code{alpha}, and \code{theta} are ignored.}
71 A numeric vector with names taken from the tip labels of
72 \code{phy}. If \code{ancestor = TRUE}, the node labels are used if
73 present, otherwise, ``Node1'', ``Node2'', etc.
76 Paradis, E. (2006) \emph{Analyses of Phylogenetics and Evolution with
77 R.} New York: Springer.
79 \author{Emmanuel Paradis}
81 \code{\link{rTraitDisc}}, \code{\link{ace}}
85 rTraitCont(bird.orders) # BM with sigma = 0.1
86 ### OU model with two optima:
87 tr <- reorder(bird.orders, "p")
90 theta <- rep(0, Nedge(tr))
91 theta[c(1:4, 15:16, 23:24)] <- 2
92 ## sensitive to 'alpha' and 'sigma':
93 rTraitCont(tr, "OU", theta = theta, alpha=.1, sigma=.01)
94 ### an imaginary model with stasis 0.5 time unit after a node, then
95 ### BM evolution with sigma = 0.1:
96 foo <- function(x, l) {
97 if (l <= 0.5) return(x)
98 x + (l - 0.5)*rnorm(1, 0, 0.1)
100 tr <- rcoal(20, br = runif)
101 rTraitCont(tr, foo, ancestor = TRUE)
102 ### a cumulative Poisson process:
103 bar <- function(x, l) x + rpois(1, l)
104 (x <- rTraitCont(tr, bar, ancestor = TRUE))
105 plot(tr, show.tip.label = FALSE)