View source: R/simulateWithPriors.R
simulateWithPriors | R Documentation |
The simulateWithPriors
function pulls parameters from prior
distributions and conducts a single simulation of continuous trait evolution
(using the doSimulation
function),
returning useful summary statistics for ABC.
parallelSimulateWithPriors
is a wrapper function for
simulateWithPriors
that allows for multithreading and
checkpointing. This family of functions is mostly used as
internal components, generating simulations within ABC analyses
using the doRun
functions. See Note below.
simulateWithPriors(
phy = NULL,
intrinsicFn,
extrinsicFn,
startingPriorsFns,
startingPriorsValues,
intrinsicPriorsFns,
intrinsicPriorsValues,
extrinsicPriorsFns,
extrinsicPriorsValues,
generation.time = 1000,
TreeYears = max(branching.times(phy)) * 1e+06,
timeStep = NULL,
giveUpAttempts = 10,
verbose = FALSE,
checks = TRUE,
taxonDF = NULL,
freevector = NULL
)
parallelSimulateWithPriors(
nrepSim,
multicore,
coreLimit,
phy,
intrinsicFn,
extrinsicFn,
startingPriorsFns,
startingPriorsValues,
intrinsicPriorsFns,
intrinsicPriorsValues,
extrinsicPriorsFns,
extrinsicPriorsValues,
generation.time = 1000,
TreeYears = max(branching.times(phy)) * 1e+06,
timeStep = NULL,
checkpointFile = NULL,
checkpointFreq = 24,
verbose = TRUE,
checkTimeStep = TRUE,
verboseNested = FALSE,
freevector = NULL,
taxonDF = NULL,
giveUpAttempts = 10
)
phy |
A phylogenetic tree, in package |
intrinsicFn |
Name of (previously-defined) function that governs how traits evolve within a lineage, regardless of the trait values of other taxa. |
extrinsicFn |
Name of (previously-defined) function that governs how traits evolve within a lineage, based on their own ('internal') trait vlaue and the trait values of other taxa. |
startingPriorsFns |
Vector containing names of prior distributions to
use for root states: can be one of
|
startingPriorsValues |
A list of the same length as
the number of prior distributions specified in
|
intrinsicPriorsFns |
Vector containing names of prior distributions to
use for intrinsic function parameters: can be one of
|
intrinsicPriorsValues |
A list of the same length
as the number of prior distributions specified
in |
extrinsicPriorsFns |
Vector containing names of prior distributions to
use for extrinsic function parameters: can be one of
|
extrinsicPriorsValues |
A list of the same length as
the number of prior distributions specified in |
generation.time |
The number of years per generation.
This sets the coarseness of the simulation; if it's set to 1000,
for example, the population's trait values change every 1000
calendar years. Note that this is in calendar years (see description
for argument |
TreeYears |
The amount of calendar time from the root
to the furthest tip. Most trees in macroevolutionary studies are dated with
branch lengths in units of millions of years, and thus the
default for this argument is |
timeStep |
This value corresponds to the length
of intervals between discrete evolutionary events ('generations')
simulated along branches, relative to a rescaled tree
where the root to furthest tip distance is 1. For example,
|
giveUpAttempts |
Value for when to stop the
analysis if |
verbose |
If |
checks |
If |
taxonDF |
A data.frame containing data on nodes (both
tips and internal nodes) output by various internal functions.
Can be supplied as input to spead up repeated calculations, but by default is
|
freevector |
A logical vector
(with length equal to the number of parameters),
indicating free ( |
nrepSim |
Number of replicated simulations to run. |
multicore |
Whether to use multicore, default is |
coreLimit |
Maximum number of cores to be used. |
checkpointFile |
Optional file name for checkpointing simulations |
checkpointFreq |
Saving frequency for checkpointing |
checkTimeStep |
If |
verboseNested |
Should looped runs of |
Function simulateWithPriors
returns a
vector of trueFreeValues
, the true generating parameters
used in the simulation (a set of values as long as
the number of freely varying parameters), concatenated with
a set of summary statistics for the simulation.
Function parallelSimulateWithPriors
returns a matrix
of such vectors bound together, with each row representing
a different simulation.
By default, both functions also assign a logical vector named
freevector
, indicating the total number of parameters and
which parameters are freely-varying (have TRUE
values),
as an attribute of the output.
The simulateWithPriors
functions are effectively the
engine that powers the doRun
functions, while the
doSimulation
function is the pistons within the
simulateWithPriors
engine. In general, most users
will just drive the car - they will just use doRun
,
but some users may want to use simulateWithPriors
or doSimulation
to do various simulations.
Brian O'Meara and Barb Banbury
set.seed(1)
tree <- rcoal(20)
# get realistic edge lengths
tree$edge.length <- tree$edge.length*20
# example simulation
# NOTE: the example analyses involve too few simulations,
# as well as overly coarse time-units...
# ...all for the sake of examples that reasonably test the functions
simData <- simulateWithPriors(
phy = tree,
intrinsicFn = brownianIntrinsic,
extrinsicFn = nullExtrinsic,
startingPriorsFns = "normal",
startingPriorsValues = list(
c(mean(simCharExample[, 1]), sd(simCharExample[, 1]))),
intrinsicPriorsFns = c("exponential"),
intrinsicPriorsValues = list(10),
extrinsicPriorsFns = c("fixed"),
extrinsicPriorsValues = list(0),
generation.time = 100000,
freevector = NULL,
giveUpAttempts = 10,
verbose = TRUE)
simData
simDataParallel <- parallelSimulateWithPriors(
nrepSim = 2,
multicore = FALSE,
coreLimit = 1,
phy = tree,
intrinsicFn = brownianIntrinsic,
extrinsicFn = nullExtrinsic,
startingPriorsFns = "normal",
startingPriorsValues = list(
c(mean(simCharExample[, 1]), sd(simCharExample[, 1]))),
intrinsicPriorsFns = c("exponential"),
intrinsicPriorsValues = list(10),
extrinsicPriorsFns = c("fixed"),
extrinsicPriorsValues = list(0),
generation.time = 100000,
checkpointFile = NULL, checkpointFreq = 24,
verbose = TRUE,
freevector = NULL,
taxonDF = NULL)
simDataParallel
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.