This function, given parameters on the Relative weight of different geographic range inheritance scenarios at cladogenesis (speciation) events, calculates the probability of each possible ancestral state given the probabilities of each possible combination of tip states.
1 2 3 4 5 6 7 
Rcpp_leftprobs 
Probabilities of the states at the base of the left descendant branch 
Rcpp_rightprobs 
Probabilities of the states at the base of the right descendant branch 
l 
List of state indices (0based) 
s 
Relative weight of sympatric "subset"
speciation. Default 
v 
Relative weight of vicariant speciation. Default

j 
Relative weight of "founder event
speciation"/jump speciation. Default 
y 
Relative weight of fully sympatric speciation
(rangecopying). Default 
dmat 
If given, a matrix of rank numareas giving
multipliers for the probability of each dispersal event
between areas. Default NULL, which sets every cell of the

maxent01s 
Matrix giving the relative weight of
each possible descendant rangesize for the smaller range,
for a given ancestral rangesize, for a subsetsympatric
speciation event. Default is 
maxent01v 
Matrix giving the relative weight of
each possible descendant rangesize for the smaller range,
for a given ancestral rangesize, for a vicariance
speciation event. Default is 
maxent01j 
Matrix giving the relative weight of
each possible descendant rangesize for the smaller range,
for a given ancestral rangesize, for a founderevent
speciation event. Default is 
maxent01y 
Matrix giving the relative weight of
each possible descendant rangesize for the smaller range,
for a given ancestral rangesize, for a fullsympatric
(rangecopying) speciation event. Default is 
max_minsize_as_function_of_ancsize 
If given, any state with a range larger that this value will be given a probability of zero (for the branch with the smaller rangesize). This means that not every possible combination of ranges has to be checked, which can get very slow for large state spaces. 
Rsp_rowsums 
A vector of size (numstates) giving the sum of the relative probabilites of each combination of descendant states, assuming the probabilities of the left and rightstates are all equal (set to 1). This is thus the sum of the weights, and dividing by this normalization vector means that the each row of the speciation probability matrix will sum to 1. Default assumes the weights sum to 1 but this is not usually the case. Rsp_rowsums need only be calculated once per tree+model combination, stored, and then reused for each node in the tree, yielding significant time savings. 
printmat 
Should the probability matrix output be printed to screen? (useful for debugging, but can be dramatically slow in R.app for some reason for even moderate numbers of states; perhaps overrunning the line length...) 
The Python/C++ program LAGRANGE (Ree & Smith 2008) gives a fixed equal probability to each rangeinheritance scenario it allows:
(1) sympatric speciation with 1 area (e.g. A –> A,A);
(2) sympatric speciation where one species inherits the
ancestral range, and the other inherits a 1area subset
of the ancestral range (e.g. ABC –> ABC,B);
(3)
vicariant speciation with one daughter occupying an area
of size 1 (e.g. ABCD –> ACD,B)
For example, if the ancestral range is ABC, the possible daughters are:
(Left, Right)
Vicariance: A,BC AB,C AC,B BC,A C,AB B,AC
Sympatric subset: A,ABC B,ABC C,ABC ABC,A ABC,B ABC,C
There are 12 possibilities, so LAGRANGE would give each a probability of 1/12, conditional on the ancestor having range ABC. All other imaginable scenarios are given probability 0 – e.g., sympatric speciation of a widespread range (ABC –> ABC,ABC), or jump dispersal leading to founderevent speciation (ABC –> ABC,D).
In BioGeoBEARS
, the relative probability (or
weight) of these categories is set by the s
(sympatricsubset), v
(vicariance), j
(jump/founderevent), and y
(sympatricrangecopying) parameters. These parameters do
not have to sum to 1, they just give the relative
weight of an event of each type. E.g., if s=1
,
v=1
, j=0
, y=1
, then each allowed
sympatricrangecopying, sympatricsubset, and vicariance
event is given equal probability (this is the LAGRANGE
cladogenesis model) .
The rcpp_calc_anclikes_sp
function gets slow for
large state spaces, as every possible combination of
states at Left and Right branches is checked. Even in
C++ this will get slow, as the (number of states) =
2^(number of areas)
, and as the number of possible
combinations of (ancestor, left,right) states is
(number of states)*(number of states)*(number of
states)
.
Note: the maxent
parameters allow the user to
specify the probability distribution for different range
sizes of the smallerranged descendant lineage. The
defaults set these parameters so that the LAGRANGE model
is implemented (the smaller descendant always has range
size 1).
See rcpp_calc_anclikes_sp_COOprobs
and
rcpp_calc_anclikes_sp_COOweights_faster
for
successively faster solutions to this problem.
This is the bytecompiled version of
rcpp_calc_anclikes_sp_prebyte
.
rcpp_calc_anclikes_sp
is bytecompiled,
which (might) make it faster.
For information on bytecompiling, see
http://www.rstatistics.com/2012/04/speedupyourrcodeusingajustintimejitcompiler/
and cmpfun
in the
compiler
package.
prob_ancestral_states
The probabilities of the
ancestral states.
Nicholas Matzke matzke@berkeley.edu
Matzke N (2012). "Founderevent speciation in BioGeoBEARS package dramatically improves likelihoods and alters parameter inference in DispersalExtinctionCladogenesis (DEC) analyses." _Frontiers of Biogeography_, *4*(suppl. 1), pp. 210. ISSN 19486596, Poster abstract published in the Conference Program and Abstracts of the International Biogeography Society 6th Biannual Meeting, Miami, Florida. Poster Session P10: Historical and PaleoBiogeography. Poster 129B. January 11, 2013, <URL: http://phylo.wikidot.com/matzke2013internationalbiogeographysocietyposter>.
Ree RH and Smith SA (2008). "Maximum likelihood inference of geographic range evolution by dispersal, local extinction, and cladogenesis." _Systematic Biology_, *57*(1), pp. 414. <URL: http://dx.doi.org/10.1080/10635150701883881>, <URL: http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Retrieve&db=PubMed&dopt=Citation&list_uids=18253896>.
rcpp_calc_anclikes_sp
,
rcpp_calc_anclikes_sp_COOprobs
,
rcpp_calc_anclikes_sp_COOweights_faster
1 2 3 4 5  # For the basic logic of a probablistic cladogenesis model, see
?rcpp_calc_anclikes_sp
# For examples of running the functions, see the comparison of all functions at:
# ?cladoRcpp

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.
Please suggest features or report bugs with the GitHub issue tracker.
All documentation is copyright its authors; we didn't write any of that.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.