Learn R Programming

BioGeoBEARS (version 0.2.1)

BioGeography with Bayesian (and Likelihood) Evolutionary Analysis in R Scripts

Description

BioGeoBEARS allows probabilistic inference of both historical biogeography (ancestral geographic ranges on a phylogeny) as well as comparison of different models of range evolution. It reproduces the model available in LAGRANGE (Ree and Smith 2008), as well as making available numerous additional models. For example, LAGRANGE as typically run has two free parameters, d (dispersal rate, i.e. the rate of range addition along a phylogenetic branch) and e (extinction rate, really the rate of local range loss along a phylogenetic branch). LAGRANGE also has a fixed cladogenic model which gives equal probability to a number of allowed range inheritance events, e.g.: (1) vicariance, (2) a new species starts in a subset of the ancestral range, (3) the ancestral range is copied to both species; in all cases, at least one species must have a starting range of size 1. LAGRANGE assigns equal probability to each of these events, and zero probability to other events. BioGeoBEARS adds an additional cladogenic event: founder-event speciation (the new species jumps to a range outside of the ancestral range), and also allows the relative weighting of the different sorts of events to be made into free parameters, allowing optimization and standard model choice procedures to pick the best model. The relative probability of different descendent range sizes is also parameterized and thus can also be specified or estimated. The flexibility available in BioGeoBEARS also enables the natural incorporation of (1) imperfect detection of geographic ranges in the tips, and (2) inclusion of fossil geographic range data, when the fossils are tips on the phylogeny. Bayesian analysis has been implemented through use of the "LaplacesDemon" package, however this package is now maintained off of CRAN, so its usage is not formally included in BioGeoBEARS at the current time. CITATION INFO: This package is the result of my Ph.D. research, please cite the package if you use it! Type: citation(package="BioGeoBEARS") to get the citation information.

Copy Link

Version

Install

install.packages('BioGeoBEARS')

Monthly Downloads

22

Version

0.2.1

License

GPL (>= 2)

Maintainer

Nicholas J Matzke

Last Published

January 2nd, 2014

Functions in BioGeoBEARS (0.2.1)

calc_loglike_for_optim

Take model parameters and the data and calculate the log-likelihood
define_BioGeoBEARS_model_object

Define a BioGeoBEARS_model class and object
get_tiplabel_ranges

For each tip, get a text string of the areas in a tipranges object.
get_indices_of_branches_under_tips

Get the indices of the branches (row number in edge matrix) below each tip
BioGeoBEARS_run

An object of class BioGeoBEARS_run holding the model inputs
conditional_format_cell

Conditionally format a number (mostly)
bears_2param_standard_fast_symOnly_simp

2-parameter model, no cladogenesis model (as in BayArea or other purely continuous-time model)
LGcpp_splits_fn_to_table2

Get the ML splits per node, from Python LAGRANGE output
get_MLsplitprobs_from_results

Extract the ML probs for the base of each branch above a split
BioGeoBEARS_model_object_to_params_upper

Produce the upper limit on the parameters from a BioGeoBEARS model object
get_rownum_ref_model

Get rownum of named model
BioGeoBEARS_model_object_to_init_params

Produce initial parameters from a BioGeoBEARS model object
order_LGnodes

Order LAGRANGE-numbered nodes so that they can be plotted in R
bears_3param_standard_fast_fixnode

3-parameter model, adding j (founder-event speciation)
areas_list_to_states_list_new

Convert a list of areas to a list of geographic ranges (states); R version
BioGeoBEARS_model_defaults

Set up a default BioGeoBEARS model object
prob_of_states_from_prior_prob_areas

Calculate probability of detection data for each OTU at each range in a list of states/geographic ranges
BioGeoBEARS_model_object_to_est_params

Extract estimated parameters from a BioGeoBEARS model object
LGpy_splits_fn_to_table

Get the ML splits per node, from Python LAGRANGE output
LGcpp_MLstate_per_node

Get the ML states per node, from a states table
bears_2param_standard_fast

2-parameter model, fixed cladogenesis model (as in LAGRANGE)
bears_3param_standard_fast_noJ

3-parameter model, adding v (vicariance proportion), but no j (founder-event speciation)
calc_post_prob_presence

Calculate posterior probability of presence, given count data and parameters
AICstats_2models

Calculate all the AIC and LRT stats between two models
calc_linked_params_BioGeoBEARS_model_object

Update parameters that are deterministic functions of free parameters
bears_3param_standard_fast

3-parameter model, adding j (founder-event speciation)
binary_range_to_letter_code_txt

Convert binary presence/absence codes (1/0) to text area names
add_corners

Iterate up through a plotted tree, getting the coordinates of the corners
get_all_node_ages

Get the ages of all the nodes in the tree (above the root)
cls.df

Get the class for each column in a list
bears_4param_standard_fast

4-parameter model, adding j (founder-event speciation) and v (vicariance proportion)
calc_loglike_for_optim_stratified

Take model parameters and the data and calculate the log-likelihood -- stratified version
LGcpp_splits_fn_to_table

Get the ML splits per node, from C++ LAGRANGE output
BioGeoBEARS_model_object_to_params_lower

Produce the lower limit on the parameters from a BioGeoBEARS model object
binary_ranges_to_letter_codes

Convert binary presence/absence codes (1/0) to a list of text area names
get_Akaike_weights_from_rel_likes

Calculate the Akaike Weights, from the relative likelihoods of the models
calc_obs_like

Calculate likelihood of count data given true presence/absence and parameters
getAICc

Calculate AICc
Pdata_given_rangerow_dp

Calculate probability of detection data given a true geographic range and a detection probability
get_APE_nodenums

Get R internal node numbers
adf2

Convert to data.frame, without factors
BioGeoBEARS_model

An object of class BioGeoBEARS_model holding the model inputs
adf

Convert to data.frame, without factors
get_level

Get a node's level in the tree
get_indices_of_tip_nodes

Get TRUE/FALSE for nodes being tips
nullsym_to_NA

Convert a specified null range code to NA
corner_coords

Get the corner coordinates
calcP_n

Calculate Z (part of equation 6.4 of Harte 2011)
get_Akaike_weight_ratio_from_Akaike_pairwise_weights

Get the ratio between the pairwise Akaike Weights
get_ML_state_indices

Extract the indices for the ML states at each node, given a row of relative probabilities
dfnums_to_numeric

Get the class for each column in a list
calc_loglike_sp_stratified

Calculate log-likelihood with a transition matrix and speciation events, and with stratification
get_ML_states_from_relprobs

Extract the ML states at each node, from a table of relative probabilities -- old version
get_indices_where_list1_occurs_in_list2

Return (first!) indices in second list matching the first list
calc_prob_forward_onebranch_dense

Dense matrix exponentiation forward on a branch, with rexpokit
bears_2param_standard_fast_fixnode

2-parameter model, fixed cladogenesis model (as in LAGRANGE)
divide_probs_by_number_of_options_txt

Divide each type of event by its frequency
bears_9param_standard_fast_ys_v_cb

6-parameter model, adding j (founder-event speciation), v (vicariance proportion), and both maxent_constraint_01 and maxent_constraint_01v
calc_AICc_vals

Calculate AICc values for a list of models
getranges_from_LagrangePHYLIP

Read a LAGRANGE PHYLIP-style file containing geographic ranges into a tipranges object
get_edge_times_before_present

Get the times of the top and bottom of each edge
BioGeoBEARS-package

BioGeography with Bayesian (and likelihood) Evolutionary Analysis of RangeS
bears_5param_standard_fast_diffstart

5-parameter model, with different starting points for optimization
LGpy_MLsplit_per_node

Get the ML splits per node, from a splits table
np

normalizePath shortcut
infprobs_to_probs_of_each_area_from_relprobs

Convert relative probabilities matrix to the probabilities of presence in each area
calc_AICc_column

Calculate AICc values for a list of models
mapply_calc_obs_like

Mapply version of calc_obs_like()
average_tr_tips

Average the heights of (non-fossil) tips to make ultrametric-ish.
cornerpies

Make pie charts for plotting ranges on corners
define_tipranges_object

Define a tipranges class and object
AkaikeWeights_and_Ratios_pairwise_on_summary_table_compared_to_ref

Get the ratio between the pairwise Akaike Weights
order_tipranges_by_tr

Order the tipranges in a tipranges object so they match the order of tips in a tree
binary_range_to_letter_code_list

Convert binary presence/absence codes (1/0) to a list of text area names
infprobs_to_probs_of_each_area

Convert probabilities of each state, to the probabilities of presence in each area
bears_optim_run

Run ML search from BioGeoBEARS_run object
chainsaw2

Saw a tree off at a particular time before present
bears_6param_standard_fast_ys_v

6-parameter model, adding j (founder-event speciation), v (vicariance proportion), and both maxent_constraint_01 and maxent_constraint_01v
add_to_downpass_labels

Iterate up and down a tree in C++ LAGRANGE downpass order
cornerlabels

Make labels for plotting ranges on corners
expokit_dgpadm_Qmat2_prebyte

A version of expokit_dgpadm_Qmat to byte-compile
bears_2param_standard_fast_fortest

2-parameter model, fixed cladogenesis model (as in LAGRANGE) -- older test version
default_states_list

Default input for a states_list
colors_legend

Plot a colors legend for geographic ranges
calc_loglike_sp_prebyte

Calculate log-likelihood with a transition matrix and speciation events -- pre-byte-compiled
get_Akaike_weights_from_rel_likes_pairwise

Calculate the Akaike Weights, from the relative likelihoods of the models
axisPhylo2

axisPhylo with more flexibility in labeling
LGcpp_states_fn_to_table

Get the ML states per node, from C++ LAGRANGE output
bears_5param_standard_fast_v

5-parameter model, adding j (founder-event speciation), v (vicariance proportion), and maxent_constraint_01v (vicariance daughter sizes)
findall

Get indices of all matches to a list
divide_probs_by_number_of_options_nums

Divide each type of event by its frequency, return calculated probabilities
calcZ_part

Calculate Z (equation 6.3 of Harte 2011)
parse_lagrange_output_old

Parse the output file from python LAGRANGE -- older version
calc_AIC_vals

Calculate AICs for a list of models
get_TF_tips

Get TRUE/FALSE for nodes being tips
getareas_from_tipranges_object

Get the names of the areas in a tipranges object
get_inf_LgL_etc_optimx

Get the inferred parameters from a results object (utility function)
prt_tree_to_phylo4

prt_tree_to_phylo4
check_if_state_is_allowed

Check if a geographic range/state is allowed, given an areas-allowed matrix.
conditional_format_table

Conditionally format the numbers (mostly) in a table
get_infparams_optimx

Get the inferred parameters from an ML optimization
get_indices_where_list1_occurs_in_list2_noNA

Return (first!) indices in second list matching the first list, excluding NAs
extract_numbers

Extract just the numbers from a string, including decimal points
get_nodenums

Get the unique node numbers in a tree
get_parent

Get the direct parent node of a node
simstates_to_probs_of_each_area

Convert simulated states to probabilities of each area
is.not.na

Check for not NA
get_AICweight_ratio_model1_over_model2

Calculate ratio of Akaike Weights
calc_prob_forward_onebranch_sparse

Sparse matrix exponentiation forward on a branch, with rexpokit
get_daughters

Get all the direct daughters nodes of a node
get_ML_probs

Get the probability of the ML state for each node, from a BioGeoBEARS model results list
expand.grid.jc

An even faster version of expand.grid
get_path_last

Get the text that comes after the last slash
get_lagrange_nodenums

Get internal node numbers in LAGRANGE's downpass order
get_relative_prob_model1old

Calculate relative probability of model 1 (=Akaike Weight)
getname

Collapse range abbreviations to strings
get_colors_for_numareas

Get colors for a certain number of single areas
make_relprob_matrix_bi

Make a relative probability matrix for a single speciation (bifurcation) event
parse_lagrange_output

Parse the output file from python LAGRANGE
get_leftright_nodes_matrix_from_results

Make a table of the Right and Left nodes descending from each node
make_relprob_txtmatrix_sp1

Convert a observed-speciation transition matrix to an unobserved-speciation transition matrix (text version)
rangestxt_to_colors

Convert a list of ranges text (KOM, MH, KOMIH, etc.)
meval

eval() function for use in sapply
get_fn_prefix

Get everything BEFORE the last suffix (.nex or whatever)
prt

Print tree in table format
get_sister_node

Get the node sister to two nodes
calc_AIC_column

Calculate AICs to make a column in a table
get_statesColors_table

Make a color table for each area and their combinations
prflag

Utility function to conditionally print intermediate results
read_detections

Read a file with detection counts per area
make_relprob_matrix_de

Make a relative dispersal probability matrix (in text form)
get_probvals

Calculate probability of ordered discrete states using a maxent distribution (equations 6.3-6.4 of Harte 2011)
match_list1_in_list2

Return TRUE for list1 items when they occur in list2
letter_string_to_binary

Convert ranges in the form of letters (A, AB, BFG, etc.) to binary state number codes
params_into_BioGeoBEARS_model_object

Feed modified parameters back into a BioGeoBEARS model object
map_LG_MLsplits_to_tree_corners

Map splits to the corners on a phylogeny
tipranges_to_area_strings

Convert tipranges binary coding to range strings
rel_likes_from_deltaAICs

Calculate the relative likelihoods of the models, from the deltaAIC
get_simparams

Get the simulated model parameters from the row of a table
merge_words_nonwords

Merge lists of words and nonwords (numbers) that may be of different length
symbolic_cell_to_relprob_cell

Convert symbolic cell (a text equation) to relprob matrix (a numeric value).
make_relprob_nummatrix_sp1

Convert a observed-speciation transition matrix to an unobserved-speciation transition matrix (numeric version)
relative_probabilities_of_subsets

Calculate probability of different descendant rangesizes, for the smaller descendant, in subset speciation
get_ML_states

Get ML states from a BioGeoBEARS model results list
unlist_df3

Unlist the columns in a data.frame, with more checks and adf
get_simstates

Load the simulation information from an underscore delimited text string.
save_tipranges_to_LagrangePHYLIP

Save a tipranges object to a LAGRANGE PHYLIP-style file containing binary-encoded geographic ranges
slashslash

Remove double slash (slash a slash)
get_deltaAIC

Calculate deltaAIC
remove_null_rowcols_from_mat

Remove rows or columns representing a null geographic range from a matrix
getAIC_weight_for_model1

Calculate Akaike Weight
label_nodes_postorder_phylo3

Add postorder node number labels to a phylo3 tree object.
calc_loglike_sp

Calculate log-likelihood with a transition matrix and speciation events -- byte-compiled
get_max_height_tree

Get the maximum age of all the nodes (above the root)
read_dispersal_multipliers_fn

Read in the hard-coded dispersal multipliers from file
map_LGpy_MLsplits_to_tree

Take the table of ML splits and node number and map on tree (Python version)
read_times_fn

Read in the stratification time breakpoints
mix_colors_for_states

Mix colors logically to produce colors for multi-area ranges
read_area_of_areas_fn

Read in the area areas by time
lrttest

Calculate Likelihood Ratio Test (LRT)
map_LG_MLsplits_to_tree

Take the table of ML splits and node number and map on tree (C++ LAGRANGE version)
symbolic_to_relprob_matrix_sp

Convert symbolic matrix (with text equations) to relprob matrix (numeric values) -- speciation matrix version
nodenums_bottom_up

Assign node labels in bottom-up, left-first format (as in e.g. r8s)
mapply_calc_post_prob_presence

Mapply version of calc_post_prob_presence()
get_node_ages_of_tips

Get the ages of each tip above the root
vfunc

Extract the appropriate probability for a vicariant speciation event, given text code for rangesize of smaller descendant, and ancestor
given_a_starting_state_simulate_branch_end

Given the state at the start of a branch, simulate the state at the end of the branch
pdftable

Print a table to LaTeX format
tipranges_to_tip_condlikes_of_data_on_each_state

Convert a tipranges object to the tip likelihoods
make_spmat_row

Construct a (text) cell of the cladogenesis/speciation matrix
post_prob_states_matrix

Calculate posterior probability of each states/geographic ranges, given prior probabilities and data likelihoods
get_all_daughter_tips_of_a_node

Get all the daughter tips of a node
states_list_indexes_to_areastxt

States (ranges) lists to txt string of the areas
traverse_up

Traverse the tree from node up to the tips
make_dispersal_multiplier_matrix

Make a default matrix of relative dispersal probabilities between areas
moref

print to screen the header of a file
mapply_likelihoods_prebyte

Use mapply on matrix exponentiations -- pre-byte-compiling
yfunc

Extract the appropriate probability for a sympatric/range-copying speciation event, given text code for rangesize of smaller descendant, and ancestor
mapply_likelihoods

Use mapply on matrix exponentiations -- post-byte-compiling
get_path_first

Get the text that comes before the last slash
list2str

Convert a list of items to a string
maxsize

Get the maximum rangesize for a given ancestral rangesize
order_tipranges_by_tree_tips

Reorder the rows in a tipranges object, to correspond to tree tips
letter_strings_to_tipranges_df

Convert ranges in the form of letters (A, AB, BFG, etc.) to a tipranges object
simulated_indexes_to_tipranges_object

Convert simulated Qmat 0-based indexes to a tipranges object
process_optim

Extract optim results to a row
return_items_not_NA

Remove NAs from a vector/list
strsplit2

String splitting shortcut
prune_states_list

Cut down the states list according to areas_allowed_mat
get_infprobs_of_simstates

Get the probabilities of the true (simulated) states
read_controls

Read a file with the total number of detections in a taphonomic control
unlist_df

Unlist the columns in a data.frame
symbolic_cell_to_relprob_cell_sp

Convert symbolic cell (a text equation) to relprob cell (a numeric value) -- speciation matrix version
simulated_indexes_to_tipranges_file

Convert simulated Qmat 0-based indexes to a tipranges file
parse_lagrange_python_output_old

Parse the output file from python LAGRANGE -- old version
sfunc

Extract the appropriate probability for a subset speciation event, given text code for rangesize of smaller descendant, and ancestor
simulate_biogeog_history

Simulate a biogeographical history, given a transition matrix and cladogenesis model
symbolic_to_P_matrix

Convert symbolic matrix to relprob matrix
unlist_df2

Unlist the columns in a data.frame, with more checks
get_perEvent_probs

Get the per-event probabilities at cladogenesis
expokit_dgpadm_Qmat2

A byte-compiled version of expokit_dgpadm_Qmat2_prebyte
relative_probabilities_of_vicariants

Calculate probability of different descendant rangesizes, for the smaller descendant, in vicariant speciation
tipranges

The tipranges class
get_nodenum_structural_root

Gets the root node
plot_cladogenesis_size_probabilities

Graphical display of P(daughter rangesize) for your input or inferred speciation model
normat

Utility functions to help deal with matrices Normalize a transition matrix
symbolic_to_Q_matrix

Convert symbolic matrix to an instantaneous rate matrix (Q matrix)
pdfit

Print a table to LaTeX format
size_species_matrix

Calculate the dimensions of the cladogenesis/speciation matrix
plot_BioGeoBEARS_model

Graphical display of your anagenetic and cladogenetic biogeography models
printall

Print an entire table to screen
section_the_tree

Section a tree for stratified analysis
strsplit_whitespace

Split strings on whitespace
read_areas_allowed_fn

Read in the area areas by time
parse_lagrange_python_output

Parse the output file from python LAGRANGE
bears_5param_standard_fast

5-parameter model, adding j (founder-event speciation), v (vicariance proportion), and maxent_constraint_01 (weighting for size of smaller-ranged descendant lineage)
readfiles_BioGeoBEARS_run

Read in the extra input files, if any
lrttest_on_summary_table

Calculate Likelihood Ratio Test (LRT) results, and add to table
paste_rows_without_zeros

Concatenate cells in each row of a text-based transition matrix, excluding zeros
get_relative_prob_model2old

Calculate relative probability of model 1 (Akaike Weight)
get_pruningwise_nodenums

Get internal node numbers in pruningwise order
postorder_nodes_phylo4_return_table

Get a table of node numbers, including DIVA node numbers
bears_2param_standard_slowQ_slowSP

2-parameter model, fixed cladogenesis model -- slow version
post_prob_states

Calculate posterior probability of each states/geographic ranges, given prior probabilities and data likelihoods
prune_specimens_to_species

Take a tree and species names/geography table and produce a pruned tree and tipranges object
read_distances_fn

Read in the distances by time
rel_likes_from_deltaAICs_pairwise

Calculate the relative likelihoods of the models, from the deltaAICs, pairwise
AkaikeWeights_on_summary_table

Calculate Akaike Weights, and add to table
addslash

Add a slash to a directory name if needed
Pdata_given_rangerow

Calculate probability of detection data given a true geographic range and a detection probability
bears_2param_DIVA_fast

2-parameter model, fixed cladogenesis model (as in LAGRANGE)
check_BioGeoBEARS_run

Check the inputs for various problems
bears_2param_standard_fast_symOnly

2-parameter model, no cladogenesis model (as in BayArea or other purely continuous-time model)
expand.grid.alt

A faster version of expand.grid
define_BioGeoBEARS_run

Define a maximum likelihood search, perhaps stratified
extend_tips_to_ultrametricize

Take a tree, extend all tips (including fossils) up to 0.0 my before present
getAIC

Calculate AIC
get_deltaAIC_pairwise_w_ref_model

Calculate deltaAIC
get_infparams_optimx_nosim

Get the inferred parameters from an ML optimization (different filenames)
given_a_starting_state_simulate_split

Given the state just below a node, simulate the states after speciation
map_LG_MLstates_to_tree

Map states to the nodes on a phylogeny
plot_BioGeoBEARS_results

Plot the results of a BioGeoBEARS run
symbolic_to_Q_matrix_exper

Experimental version of symbolic_to_Q_matrix_exper, including base frequencies
sourceall

Source all .R files in a directory, except "compile" and "package" files
read_PHYLIP_data

Read a PHYLIP-format file
unlist_df4

Unlist the columns in a data.frame, with more checks, adf, and dfnums_to_numeric
unlist_dtf_cols

Unlist the columns in a data.frame
tiplikes_wDetectionModel

Calculate probability of detection data for each OTU at each range in a list of states/geographic ranges