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).}
27 This function simulates the evolution of a continuous character along a
28 phylogeny. The calculation is done recursively from the root. See
29 Paradis (2006, p. 151) for a brief introduction.
32 There are three possibilities to specify \code{model}:
35 \item{\code{"BM"}:}{a Browian motion model is used. If the arguments
36 \code{sigma} has more than one value, its length must be equal to the
37 the branches of the tree. This allows to specify a model with variable
38 rates of evolution. You must be careful that branch numbering is done
39 with the tree in ``pruningwise'' order: to see the order of the branches
40 you can use: \code{tr <- reorder(tr, "p"); plor(tr); edgelabels()}.
41 The arguments \code{alpha} and \code{theta} are ignored.}
43 \item{\code{"OU"}:}{an Ornstein-Uhlenbeck model is used. The above
44 indexing rule is used for the three parameters \code{sigma},
45 \code{alpha}, and \code{theta}. This may be more interesting for the
46 last one to model varying phenotypic optima.
48 By default the following formula is used:
50 \deqn{x_{t''} = x_{t'} - \alpha l (x_{t'} - \theta) + \sigma
51 l \epsilon}{x(t'') = x(t') - alpha l (x(t') - theta) + sigma
54 where \eqn{l (= t'' - t')} is the branch length, and \eqn{\epsilon
55 \sim N(0, 1)}{\epsilon ~ N(0, 1)}. If \eqn{\alpha > 1}{alpha > 1},
56 this may lead to chaotic oscillations. Thus an alternative
57 parameterisation is used if \code{linear = FALSE}:
59 \deqn{x_{t''} = x_{t'} - (1 - exp(-\alpha l)) * (x_{t'} - \theta) +
60 \sigma l \epsilon}{x(t'') = x(t') - (1 - exp(-alpha l)) * (x(t') -
61 theta) + sigma l epsilon}}
63 \item{A function:}{it must be of the form \code{foo(x, l)} where
64 \code{x} is the trait of the ancestor and \code{l} is the branch
65 length. It must return the value of the descendant. The arguments
66 \code{sigma}, \code{alpha}, and \code{theta} are ignored.}
69 A numeric vector with names taken from the tip labels of
70 \code{phy}. If \code{ancestor = TRUE}, the node labels are used if
71 present, otherwise, ``Node1'', ``Node2'', etc.
74 Paradis, E. (2006) \emph{Analyses of Phylogenetics and Evolution with
75 R.} New York: Springer.
77 \author{Emmanuel Paradis}
79 \code{\link{rTraitDisc}}, \code{\link{ace}}
83 rTraitCont(bird.orders) # BM with sigma = 0.1
84 ### OU model with two optima:
85 tr <- reorder(bird.orders, "p")
88 theta <- rep(0, Nedge(tr))
89 theta[c(1:4, 15:16, 23:24)] <- 2
90 ## sensitive to 'alpha' and 'sigma':
91 rTraitCont(tr, "OU", theta = theta, alpha=.1, sigma=.01)
92 ### an imaginary model with stasis 0.5 time unit after a node, then
93 ### BM evolution with sigma = 0.1:
94 foo <- function(x, l) {
95 if (l <= 0.5) return(x)
96 x + (l - 0.5)*rnorm(1, 0, 0.1)
98 tr <- rcoal(20, br = runif)
99 rTraitCont(tr, foo, ancestor = TRUE)
100 ### a cumulative Poisson process:
101 bar <- function(x, l) x + rpois(1, l)
102 (x <- rTraitCont(tr, bar, ancestor = TRUE))
103 plot(tr, show.tip.label = FALSE)