]> git.donarmstrong.com Git - ape.git/blob - man/rTraitCont.Rd
6ff347846cad82bbb8a98139980b18864bb18dc2
[ape.git] / man / rTraitCont.Rd
1 \name{rTraitCont}
2 \alias{rTraitCont}
3 \title{Continuous Character Simulation}
4 \usage{
5 rTraitCont(phy, model = "BM", sigma = 0.1, alpha = 1, theta = 0,
6            ancestor = FALSE, root.value = 0, linear = TRUE)
7 }
8 \arguments{
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
16     single value).}
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
21     are returned).}
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 }
26 \description{
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.
30 }
31 \details{
32   There are three possibilities to specify \code{model}:
33
34 \itemize{
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.}
42
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.
47
48   By default the following formula is used:
49
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
52     l epsilon}
53
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}:
58
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}}
62
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.}
67 }}
68 \value{
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.
72 }
73 \references{
74   Paradis, E. (2006) \emph{Analyses of Phylogenetics and Evolution with
75     R.} New York: Springer.
76 }
77 \author{Emmanuel Paradis}
78 \seealso{
79   \code{\link{rTraitDisc}}, \code{\link{ace}}
80 }
81 \examples{
82 data(bird.orders)
83 rTraitCont(bird.orders) # BM with sigma = 0.1
84 ### OU model with two optima:
85 tr <- reorder(bird.orders, "p")
86 plot(tr)
87 edgelabels()
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)
97 }
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)
104 Y <- x[1:20]
105 A <- x[-(1:20)]
106 nodelabels(A)
107 tiplabels(Y)
108 }
109 \keyword{datagen}