View source: R/sample.clade.traits.R
sample.clade.traits | R Documentation |
Generates occurrence times or time ranges (as most empirical fossil
occurrences) for each of the desired species using a Poisson process.
Poisson rate should be dependent on some discrete trait, the value of which
for each species will be supplied using the parameter traits
. Rate
can be dependent on observed traits only, or on a combination of observed
and hidden traits (in which case the supplied trait data frame traits
should have all possible states, observed or hidden, see examples for more
details).
sample.clade.traits(
sim,
rho,
tMax,
traits,
nFocus = 1,
nStates = 2,
nHidden = 1,
S = NULL,
returnTrue = TRUE,
returnAll = FALSE,
bins = NULL
)
sim |
A |
rho |
Sampling rate (per species per million years) over time. It is
a |
tMax |
The maximum simulation time, used by |
traits |
List of trait data frames, usually one of the returns of
|
nFocus |
Trait of focus, i.e. the one that |
nStates |
Number of possible states for categorical trait. The range
of values will be assumed to be |
nHidden |
Number of hidden states for categorical trait. Default is
Note that since the |
S |
A vector of species numbers to be sampled. The default is all
species in |
returnTrue |
If set to |
returnAll |
If set to |
bins |
A vector of time intervals corresponding to geological time
ranges. It must be supplied if |
Optionally takes a vector of time bins reppointEstimatesenting geologic periods, if the user wishes occurrence times to be reppointEstimatesented as a range instead of true points.
A data.frame
containing species names/numbers, whether each
species is extant or extinct, and the true occurrence times of each fossil,
a range of occurrence times based on bins
, or both. Also a list
object with the trait data frames describing the trait value for each
species at each specified interval. Note that this list will only be
different from the supplied traits
parameter if nHidden > 1
,
in which case it will transform hidden traits into observed ones (see
details for parameter nHidden
).
Bruno do Rosario Petrucci.
###
# first a simple BiSSE simulation, with
# binary state-dependent fossil sampling
# initial number of species
n0 <- 1
# maximum simulation time
tMax <- 20
# speciation, higher for state 1
lambda <- c(0.1, 0.2)
# extinction, highe for state 0
mu <- c(0.06, 0.03)
# number of traits and states (1 binary trait)
nTraits <- 1
nStates <- 2
# initial value of the trait
X0 <- 0
# transition matrix, with symmetrical transition rates
Q <- list(matrix(c(0, 0.1,
0.1, 0), ncol = 2, nrow = 2))
# set seed
set.seed(1)
# run the simulation
sim <- bd.sim.traits(n0, lambda, mu, tMax = tMax, nTraits = nTraits,
nStates = nStates, X0 = X0, Q = Q, nFinal = c(2, Inf))
# now a fossil sampling rate, with higher rate for state 1
rho <- c(0.5, 1)
# run fossil sampling
fossils <- sample.clade.traits(sim$SIM, rho, tMax, sim$TRAITS)
# draw simulation with fossil occurrences as time points
draw.sim(sim$SIM, traits = sim$TRAITS,
fossils = fossils$FOSSILS, traitLegendPlacement = "bottomleft")
###
# can also run a HiSSE model, with hidden traits having an effect on rates
# initial number of species
n0 <- 1
# maximum simulation time
tMax <- 20
# speciation, higher for state 1A, highest for 1B
lambda <- c(0.1, 0.2, 0.1, 0.3)
# extinction, lowest for 0B
mu <- c(0.03, 0.03, 0.01, 0.03)
# number of traits and states--in this case, we just run with 4 observed
# states, so that our traits data frames will include that info for sampling
nTraits <- 1
nStates <- 4
# initial value of the trait
X0 <- 0
# transition matrix, with symmetrical transition rates. Only one transition
# is allowed at a time, i.e. 0A can go to 0B and 1A,
# but not to 1B, and similarly for others
Q <- list(matrix(c(0, 0.1, 0.1, 0,
0.1, 0, 0, 0.1,
0.1, 0, 0, 0.1,
0, 0.1, 0.1, 0), ncol = 4, nrow = 4))
# set seed
set.seed(1)
# run the simulation
sim <- bd.sim.traits(n0, lambda, mu, tMax, nTraits = nTraits,
nStates = nStates,
X0 = X0, Q = Q, nFinal = c(2, Inf))
# note how sim$TRAITS contains states 2 and 3, even though this
# is a HiSSE model, because we need that information to run hidden states
# on fossil sampling as well (see below)
# now a fossil sampling rate, with higher rate for state 1A,
# and highest yet for state 1B
rho <- c(0.5, 1, 0.5, 2)
# bins for fossil occurrences
bins <- seq(tMax, 0, -1)
# run fossil sampling, with returnAll = TRUE to include ranges
fossils <- sample.clade.traits(sim$SIM, rho, tMax, sim$TRAITS,
nStates = 2, nHidden = 2,
returnAll = TRUE, bins = bins)
# note how fossils$TRAITS only contains trait values 0 and 1, similar to
# if we had ran bd.sim.traits with nHidden = 2, since sample.clade.traits
# did the job of transforming observed into hidden states
# draw simulation with fossil occurrences as time points AND ranges
draw.sim(sim$SIM, traits = sim$TRAITS, fossils = fossils$FOSSILS,
fossilsFormat = "all", traitLegendPlacement = "bottomleft")
# note that there are a lot of fossils, so the ranges are difficult to see
# see ?sample.clade for further examples using different return types
# (fossil ranges etc.), and ?bd.sim.traits for more examples using
# higher numbers of states (hidden or observed), though in
# sample.clade.traits we always have only one trait of focus
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.