PCM_ABC {pcmabc} | R Documentation |
ABC estimation for PCMs
Description
The function does parameter estimation through Approximate Bayesian Computations (ABC) for user defined models of trait and phylogeny evolution. In particular the phenotype may influence the branching dynamics.
Usage
PCM_ABC(phyltree, phenotypedata, par0, phenotype.model, fbirth, fdeath = NULL,
X0 = NULL, step = NULL, abcsteps = 200, eps = 0.25, fupdate = "standard",
typeprintprogress = "dist", tree.fixed=FALSE,
dist_method=c("variancemean","wRFnorm.dist"))
Arguments
phyltree |
The phylogeny in |
phenotypedata |
A matrix with the rows corresponding to the tip species while the columns correspond to the traits.
The rows should be in the same as the order in which the
species are in the phylogeny (i.e. correspond to the node indices |
par0 |
The starting parameters for the estimation procedure. This is a list of 1, 2 or 3 lists.
The lists have to be named as |
phenotype.model |
The name of a function to simulate the phenotype over a period of time.
The function has to have four parameters (in the following order not by name):
The phenotype is simulated prior to the simulation of the speciation/extinction events on a lineage (see Details). Hence, it is not possible (at the moment) to include some special event (e.g. a cladogenetic jump) at branching. Such dynamics are only possible at the start of the lineage, i.e. when the new lineage is separated from the main lineage. Hence, cladogenetic change can only be included as an event connected with a lineage (subpopulation) breaking off. |
fbirth |
A function that returns the birth rate at a given moment.
The fist parameter of the function has to correspond to the value of the
phenotype (it is a vector first element is time and the others the values of the trait(s))
and the second to the list of birth parameters
|
fdeath |
A function that returns the birth rate at a given moment. Its structure
is the same as |
X0 |
The value of the ancestral state at the start of the tree. If |
step |
The time step size for simulating the phenotype. If not provided,
then calculated as |
abcsteps |
The number of steps of the ABC search procedure. |
eps |
The acceptance tolerance of the ABC algorithm. |
fupdate |
How should the parameters be updated at each step of the ABC search
algorithm. The user may provide their own function that has to
handle the following call
|
typeprintprogress |
What should be printed out at each step of the ABC search algorithm.
If |
tree.fixed |
Does the trait value process influence the branching dynamics ( |
dist_method |
A vector with two entries, the first is the method for calculating
the distance between the simulated and observed trait data.
The second is is the method for calculating
the distance between the simulated and observed phylogeny.
Possible values for the phenotype distance are
|
Details
Some details of the function might change. In a future release it should
be possible for the user to provide their own custom distance function,
time-inhomogenous branching and trait simulation. The fields
sum.dists.from.data
and sum.inv.dists.from.data
will
probably be removed from the output object.
At the moment the distance function is calculated as (tree.distance+trait.distance)/2 or only with trait.distance if the tree is assumed fixed. The possible distance functions between simulates and observed phenotypes are
"variance"
calculates the Euclidean distance between covariance matrices estimated from simulated and original data. The differences between entries are weighted by the sum of their absolute values so that the distance is in [0,1],"variancemean"
calculates the Euclidean distance between mean vectors and covariance matrices estimated from simulated and original data. The differences between entries are weighted by the sum of their absolute values so that the distance is in [0,1]. The difference between the means and covariances are weighted equally."order"
calculates the mean squared difference between ordered (by absolute value) tip measurements (scaled by maximum observed trait in each dimension so that distance is in [0,1] and then the difference between each pair of traits is scaled by the sum of their absolute values to remove effects of scale).
The possible distance functions between simulates and observed phenotypes are
"bdcoeffs"
first usinggeiger::bd.km()
estimates the net diversification rate for both trees and then calculates the distance between the trees as the total variation distance between two exponential distributions with rates equalling the estimated net diversification rates."node_heights"
calculates the root mean square distance between node heights (scaled by tree height so that distance is in [0,1] and then the difference between each node height is scaled by the sum of the two heights to remove effects of scale)"logweighted_node_heights"
similarly as"node_heights"
but additionally divides the
squared scaled difference is divided by the logarithm of the inverse order (i.e. the highest is 1) statistic, to reduce the role of smaller heights."RF.dist"
callsphangorn::RF.dist()
"wRF.dist"
callsphangorn::wRF.dist()
withnormalize=FALSE
"wRFnorm.dist"
callsphangorn::wRF.dist()
withnormalize=TRUE
"KF.dist"
callsphangorn::KF.dist()
"path.dist"
callsphangorn::path.dist()
withuse.weight=FALSE
"path.dist.weights"
callsphangorn::path.dist()
withuse.weight=TRUE
"dist.topo.KF1994"
callsape::dist.topo()
withmethod="score"
"BHV"
callsdistory::dist.multiPhylo()
withmethod="geodesic"
"BHVedge"
callsdistory::dist.multiPhylo()
withmethod="edgeset"
The tree is simulated by means of a Cox process (i.e. Poisson process
with random rate). First the trait is simulated along the spine of a
tree, i.e. a lineage of duration tree.height
. Then, along this
spine the birth and death rates are calculated (they may depend
on the value of the phenotype). The maximum for each rate is calculated
and a homogeneous Poisson process with the maximum rate is simulated.
Then, these events are thinned. Each event is retained with probability
equalling true rate divided by maximum of rate (p. 32, Sheldon 2006).
All speciation events are retained until the first death event.
Value
param.estimate |
A list, in the form of |
all.accepted |
A list with all the accepted parameters during the ABC search. This will allow for the presentation of the posterior distribution of the parameters. |
sum.dists.from.data |
The sum of all the distances between the observed data and the simulated data under the accepted parameter sets in the ABC search procedure. |
sum.inv.dists.from.data |
The sum of all the inverses of the distances between the observed data and the simulated data under the accepted parameter sets in the ABC search procedure. |
Author(s)
Krzysztof Bartoszek
References
Bartoszek, K. and Lio', P (2019). Modelling trait dependent speciation with Approximate Bayesian Computation. Acta Physica Polonica B Proceedings Supplement 12(1):25-47.
Sheldon R. M. (2006). Simulation. Elsevier Academic Press.
See Also
Examples
## simulate 3d OUBM model
## This example requires the R package ape
## (to generate the tree in phylo format).
set.seed(12345)
phyltree<-ape::rphylo(n=15,birth=1,death=0)
simulate_mvsl_sde<-function(time,params,X0,step){
A <- c(paste("(-",params$a11,")*(x1-(",params$psi1,"))
-(",params$a12,")*(x2-(",params$psi2,"))-(",params$b11,")*x3",sep=""),
paste("(-",params$a21,")*(x1-(",params$psi1,"))
-(",params$a22,")*(x2-(",params$psi2,"))-(",params$b21,")*x3",sep=""),0)
S <- matrix( c( params$s11, params$s12, 0, 0, params$s22
, 0, 0, 0, params$s33), 3, 3,byrow=TRUE)
yuima.3d <- yuima::setModel(drift = A, diffusion = S,
state.variable=c("x1","x2","x3"),solve.variable=c("x1","x2","x3") )
simulate_sde_on_branch(time,yuima.3d,X0,step)
}
sde.params<-list(a11=2.569531,a12=0,a21=0,a22=28.2608,b11=-5.482939,
b21=-34.806936,s11=0.5513215,s12=1.059831,s22=1.247302,s33=1.181376,
psi1=10,psi2=-10)
X0<-c(10,4.103157,3.834698)
step<-0.5 ## for keeping example's running time short <5s as CRAN policy,
## in reality should be much smaller e.g. step<-0.001
simres<-simulate_phenotype_on_tree(phyltree, simulate_mvsl_sde, sde.params, X0, step)
## extract the measurements at the tips
phenotypedata<-get_phylogenetic_sample(simres)
birth.params<-list(rate=10,maxval=10,abcstepsd=0.01,positivevars=c(TRUE,TRUE),
fixed=c(FALSE,TRUE))
sde.params<-list(a11=2.569531,a12=0,a21=0,a22=28.2608,b11=-5.482939,
b21=-34.806936,s11=0.5513215,s12=1.059831,s22=1.247302,s33=1.181376,
psi1=10,psi2=-10,
positivevars=c(TRUE,FALSE,FALSE,TRUE,FALSE,FALSE,TRUE,FALSE,TRUE,TRUE,FALSE,FALSE),
abcstepsd=rep(0.1,12))
par0<-list(phenotype.model.params=sde.params,birth.params=birth.params)
fbirth<-"rate_const"
fdeath<-NULL
X0<-c(10,4.103157,3.834698)
step<-0.05 ## for keeping example's running time short <5s as CRAN policy,
## in reality should be much smaller e.g. step<-0.001
abcsteps<-2 ## for keeping example's running time short <5s as CRAN policy,
## in reality should be much larger e.g. abcsteps<-500
eps<-1 ## for toy example's output to be useful,
## in reality should be much smaller e.g. eps<-0.25
## estimate parameters
ABCres<-PCM_ABC(phyltree=phyltree,phenotypedata=phenotypedata,
par0=par0,phenotype.model=simulate_mvsl_sde,fbirth=fbirth,fdeath=fdeath,X0=X0,
step=step,abcsteps=abcsteps,eps=eps)