Title: | Dynamic Assembly Model of Colonization, Local Extinction and Speciation |
---|---|
Description: | Simulates and computes (maximum) likelihood of a dynamical model of community assembly that takes into account phylogenetic history. |
Authors: | Rampal S. Etienne & Alex L. Pigot |
Maintainer: | Rampal S. Etienne <[email protected]> |
License: | GPL-2 |
Version: | 2.3 |
Built: | 2024-11-04 04:19:23 UTC |
Source: | https://github.com/rsetienne/damocles |
This function computes the maximum likelihood estimates of colonisation and local extinction rate for a given phylogeny and presence-absence data under the DAMOCLES model. These rate estimates are used to simulate null communities under the DAMOCLES model. Standardized effect size of mean nearest taxon distance (mntd), mean phylogentic distance (mpd) and loglikelihood are calculated For comparison, standardised effect sizes are also calculated relative to a "Random-Draw" null model i.e. presence absence randomised across tips
DAMOCLES_bootstrap( phy = ape::rcoal(10), pa = matrix(c(phy$tip.label, sample(c(0, 1), ape::Ntip(phy), replace = T)), nrow = ape::Ntip(phy), ncol = 2), initparsopt = c(0.1, 0.1), idparsopt = 1:length(initparsopt), parsfix = NULL, idparsfix = NULL, pars2 = c(0.001, 1e-04, 1e-05, 1000), pchoice = 0, runs = 999, estimate_pars = FALSE, conf.int = 0.95 )
DAMOCLES_bootstrap( phy = ape::rcoal(10), pa = matrix(c(phy$tip.label, sample(c(0, 1), ape::Ntip(phy), replace = T)), nrow = ape::Ntip(phy), ncol = 2), initparsopt = c(0.1, 0.1), idparsopt = 1:length(initparsopt), parsfix = NULL, idparsfix = NULL, pars2 = c(0.001, 1e-04, 1e-05, 1000), pchoice = 0, runs = 999, estimate_pars = FALSE, conf.int = 0.95 )
phy |
phylogeny in phylo format |
pa |
presence-absence table. |
initparsopt |
The initial values of the parameters that must be optimized |
idparsopt |
The ids of the parameters that must be optimized, e.g. 1:2
for extinction rate, and offset of immigration rate The ids are defined as
follows: |
parsfix |
The values of the parameters that should not be optimized. See idparsfix. |
idparsfix |
The ids of the parameters that should not be optimized, e.g. c(1) if mu should not be optimized, but only gamma_0. In that case idparsopt must be c(2). The default is to fix the parameters not specified in idparsopt. |
pars2 |
Vector of settings: |
pchoice |
sets which p-value to optimize and with which root state to
simulate (default pchoice = 0) |
runs |
the number null communities to generate. |
estimate_pars |
Whether to estimate parameters on the simulated datasets (default = FALSE). |
conf.int |
The width of the conifdence intervals calculated on bootstrapped parameter estimates |
The output is a list of two dataframes. The first dataframe, summary_table, contains the summary results. The second dataframe, null_community_data, contains decsriptive statistics for each null community.
summary_table |
|
null_community_data |
|
Rampal S. Etienne
Pigot, A.L. & R.S. Etienne (2015). A new dynamic null model for phylogenetic community structure. Ecology Letters 18: 153-163.
Computes likelihood for the presence-absence data of species in a local community for a given phylogeny of species in the region.
DAMOCLES_loglik( phy, pa, pars, pchoice = 0, edgeTList = NULL, methode = "analytical", model = 0, Mlist = NULL, verbose = FALSE )
DAMOCLES_loglik( phy, pa, pars, pchoice = 0, edgeTList = NULL, methode = "analytical", model = 0, Mlist = NULL, verbose = FALSE )
phy |
phylogeny in phylo format |
pa |
presence-absence table with the first column the species labels and the second column the presence (1) or absence (0) of the species |
pars |
Vector of model parameters: |
pchoice |
sets the p-value to optimize: |
edgeTList |
list of edge lengths that need to be succesively pruned; if not specified, it will computed using compute_edgeTList |
methode |
method used to solve the ODE. Either 'analytical' for the analytical solution, 'Matrix' for matrix exponentiation using package Matrix or 'expm' using package 'expm' or any of the numerical solvers, used in deSolve. |
model |
model used. Default is 0 (standard null model). Other options are 1 (binary traits) 2 (trinary environmental trait) or 3 (diversity-dependent colonization - beta version) |
Mlist |
list of M matrices that can be specified when methode = 'analytical'. If set at NULL (default) and methode = 'analytical', Mlist will be computed. |
verbose |
Whether intermediate output should be printed. Default is FALSE. |
The loglikelihood
Rampal S. Etienne
Pigot, A.L. & R.S. Etienne (2015). A new dynamic null model for phylogenetic community structure. Ecology Letters 18: 153-163.
#TEST IT WORKS library(ape) phy = ape::rcoal(100) pars = c(0.5,0.1,0.1) pa = rbinom(100,c(0,1),0.5) pa = matrix(c(phy$tip.label,pa),nrow = length(phy$tip.label),ncol = 2) # - without a root edge loglik = DAMOCLES_loglik(phy,pa,pars) loglik # - with a root edge phy$root.edge = 2 loglik = DAMOCLES_loglik(phy,pa,pars) loglik
#TEST IT WORKS library(ape) phy = ape::rcoal(100) pars = c(0.5,0.1,0.1) pa = rbinom(100,c(0,1),0.5) pa = matrix(c(phy$tip.label,pa),nrow = length(phy$tip.label),ncol = 2) # - without a root edge loglik = DAMOCLES_loglik(phy,pa,pars) loglik # - with a root edge phy$root.edge = 2 loglik = DAMOCLES_loglik(phy,pa,pars) loglik
This function computes the maximum likelihood estimates of the parameters of the DAMOCLES model for a given phylogeny and presence-absence data. It also outputs the corresponding loglikelihood that can be used in model comparisons.
DAMOCLES_ML( phy, pa, initparsopt, idparsopt = 1:length(initparsopt), parsfix = NULL, idparsfix = NULL, idparsequal = NULL, pars2 = c(0.001, 1e-04, 1e-05, 1000), optimmethod = "subplex", pchoice = 0, edgeTList = NULL, methode = "analytical", model = 0, verbose = FALSE )
DAMOCLES_ML( phy, pa, initparsopt, idparsopt = 1:length(initparsopt), parsfix = NULL, idparsfix = NULL, idparsequal = NULL, pars2 = c(0.001, 1e-04, 1e-05, 1000), optimmethod = "subplex", pchoice = 0, edgeTList = NULL, methode = "analytical", model = 0, verbose = FALSE )
phy |
phylogeny in phylo format |
pa |
presence-absence table. |
initparsopt |
The initial values of the parameters that must be optimized |
idparsopt |
The ids of the parameters that must be optimized, e.g. 1:2
for extinction rate, and offset of immigration rate The ids are defined as
follows: |
parsfix |
The values of the parameters that should not be optimized. See idparsfix. |
idparsfix |
The ids of the parameters that should not be optimized, e.g. c(1,3) if mu and gamma_1 should not be optimized, but only gamma_0. In that case idparsopt must be c(2). The default is to fix all parameters not specified in idparsopt. |
idparsequal |
The ids of the parameters that should be set equal to the first parameter of the same type. |
pars2 |
Vector of settings: |
optimmethod |
Method used in optimization of the likelihood. Current default is 'subplex'. Alternative is 'simplex' (default of previous version) |
pchoice |
sets the p-value to optimize: |
edgeTList |
list of edge lengths that need to be succesively pruned; if not specified, it will computed using compute_edgeTList |
methode |
method used to solve the ODE. Either 'analytical' for the analytical solution, 'Matrix' for matrix exponentiation using package Matrix or 'expm' using package 'expm' or any of the numerical solvers, used in deSolve. |
model |
model used. Default is 0 (standard null model). Other options are 1 (binary traits) 2 (trinary environmental trait) or 3 (diversity-dependent colonization - beta version) |
verbose |
Whether intermediate output should be printed. Default is FALSE. |
The output is a dataframe containing estimated parameters and maximum loglikelihood.
mu |
gives the maximum likelihood estimate of mu |
gamma_0 |
gives the maximum likelihood estimate of gamma_0 |
gamma_1 |
gives the maximum likelihood estimate of gamma_1 |
loglik |
gives the maximum loglikelihood |
df |
gives the number of estimated parameters, i.e. degrees of feedom |
conv |
gives a message on convergence of optimization; conv = 0 means convergence |
Rampal S. Etienne
Pigot, A.L. & R.S. Etienne (2015). A new dynamic null model for phylogenetic community structure. Ecology Letters 18: 153-163.
Simulates DAMOCLES
DAMOCLES_sim( phy, gamma_0, gamma_td, mu, sigma, psiBranch, psiTrait, z, phi, traitOpt, br0, br_td, nTdim, root.state, root.trait.state, plotit = FALSE, keepExtinct = FALSE )
DAMOCLES_sim( phy, gamma_0, gamma_td, mu, sigma, psiBranch, psiTrait, z, phi, traitOpt, br0, br_td, nTdim, root.state, root.trait.state, plotit = FALSE, keepExtinct = FALSE )
phy |
phylogeny in phylo format |
gamma_0 |
initial per lineage rate of immigration (gamma) |
gamma_td |
time dependency in gamma |
mu |
per lineage rate of local extinction |
sigma |
probability of local (i.e. in-situ) speciation |
psiBranch |
phylogenetic distance at which gamma is half gamma_0 |
psiTrait |
trait distance at which gamma is half gamma_0 |
z |
shape of increase in gamma with increasing trait or phylogenetic distance |
phi |
rate of decline in gamma with distance from trait optima |
traitOpt |
trait value at which gamma = gamma_0 |
br0 |
Brownian rate parameter |
br_td |
rate of temporal decline in Brownian rate parameter |
nTdim |
number of independent trait dimensions |
root.state |
geographic state of ancestor i.e. present (1) or absent(0) |
root.trait.state |
trait value of ancestor |
plotit |
whether to plot the phylogeny and timing of immigration/local extinction events |
keepExtinct |
whether to retain data for extinct lineages |
A list of two tables. The first table contains the following columns: The first column contains the vector of tip labels in the phylogeny The last column contains the presence (1) or absence (0) of the species The second table has dimensions d x N where d is the number of trait dimensions and N is the number of species. It contains the trait values.
Alex L. Pigot
Pigot, A.L. & R.S. Etienne (2015). A new dynamic null model for phylogenetic community structure. Ecology Letters 18: 153-163.
#create random phylogeny library(ape) phy = ape::rcoal(10) #run DAMOCLES out = DAMOCLES_sim( phy, gamma_0 = 1.5, gamma_td =0, mu = 0, sigma = 0, psiBranch = 0, psiTrait = 0, z = 10, phi = 0, traitOpt = 1, br0 = 0.1, br_td = -0.1, nTdim = 2, root.state = 1, root.trait.state = 0, plotit = FALSE, keepExtinct = FALSE ) #the output consists of a list patable = out[[1]] # the first element is the presence absence table traits = out[[2]] # this is a matrix of traits values #show presence/absence on the tree patable$col = rep("black",dim(patable)[1]) patable$col[which(patable$state == 1)] = "red" plot(phy,tip.col = patable$col)
#create random phylogeny library(ape) phy = ape::rcoal(10) #run DAMOCLES out = DAMOCLES_sim( phy, gamma_0 = 1.5, gamma_td =0, mu = 0, sigma = 0, psiBranch = 0, psiTrait = 0, z = 10, phi = 0, traitOpt = 1, br0 = 0.1, br_td = -0.1, nTdim = 2, root.state = 1, root.trait.state = 0, plotit = FALSE, keepExtinct = FALSE ) #the output consists of a list patable = out[[1]] # the first element is the presence absence table traits = out[[2]] # this is a matrix of traits values #show presence/absence on the tree patable$col = rep("black",dim(patable)[1]) patable$col[which(patable$state == 1)] = "red" plot(phy,tip.col = patable$col)
A list with two elements.
. phy
is a dated molecular phylogeny
for 94 species of New World Primates extracted from the maximum likelihood
tree (AUTOsoft dated) of Springer et al. (2012). 1 time unit = 100 million
years. pa
is the presence-absence matrix of NW Primates in Manu
from Solari et al. (2006). The first column indicate the species tip labels
and the second column indicates presence (1) and absence (0).
A list with two elements. The first element (phy
) is the
primate phylogeny in nexus format. The second element (pa
) is the
presence-absence matrix with 94 rows and 2 columns.
Solari, S., Pacheco, V., Luna, L., Velazco, P.M. & Patterson, B.D.
2006 Mammals of the manu biosphere reserve. Fieldiana Zoology 110, 13-22.
Springer, M.S., Meredith, R.W., Gatesy, J., Emerling, C.A., Park, J.,
Rabosky, D.L., Stadler, T., Steiner, C., Ryder, O.A., Janecka, J.E., et al.
2012 Macroevolutionary dynamics and historical biogeography of primate
diversification inferred from a species supermatrix. Plos One 7. (doi:ARTN
e49521 DOI 10.1371/journal.pone.0049521).
DAMOCLES_sim
, DAMOCLES_ML
,
DAMOCLES_loglik