Package 'ctpm'

Title: Continuous-Time Phylogenetic Modeling
Description: Functions for identifying, fitting, and applying continuous-time stochastic models to phylogenetic data. The package is based on methods introduced in Fleming et al (2014) <doi:10.1086/675504>.
Authors: Michael J. Noonan [aut, cre], Christen H. Fleming [aut]
Maintainer: Michael Noonan <[email protected]>
License: GPL-3
Version: 1.0.0
Built: 2024-11-08 03:43:45 UTC
Source: https://github.com/noonanm/ctpm

Help Index


Fit models to phylogenetic data.

Description

This function is currently a wrapper for methods implemented in the package slouch.

Usage

ctpm.fit(data, phylo, model = NULL, time.units = "Ma")

Arguments

data

A vector of continuous species trait data. This vector needs to be of the same length and same order as phylo$tip.label.

phylo

An object of class 'phylo'.

model

The model to fit. Can be one of "IID", "BM", or "OU".

time.units

A character defining the units of the edge lengths of the phylogentic tree. Defaults to "Ma"

Details

Fits evolutionary models to species trait data using the methods implemented in the package slouch and returns a model fit object (class ctmm) that is used for plotting a fitted model against an emprical variogram.

Value

Returns a model fit object (class ctmm) that is used for plotting a fitted model against an emprical variogram.

Note

Running summary on the fitted model is not currently meaningful.

Author(s)

M. J. Noonan, C. H. Fleming.

References

Noonan, M. J., Fagan, W. F., and Fleming C. H. (2021) “A semi-variance approach to visualising phylogenetic autocorrelation”. Methods in Ecology and Evolution, in press.

See Also

vignette("variograms", package = "ctpm"), plot.variogram, %#%.

Examples

#Load package and data
library(ctpm)
data("moid_traits")
data("musteloids")

#Extract the trait of interest from the full dataset
SSD <- moid_traits$SSD

#Calculate variogram
SVF <- variogram(SSD, musteloids)

#Fit the model
FIT <- ctpm.fit(SSD, musteloids, model = "BM")


#Plot the variogram and fitted model
plot(SVF, FIT)

Trait data on 57 species of extant musteloids.

Description

Morphological and life history data on mean male body mass (kg), mean male body mass (kg), sexual size dimorphism (male mass/female mass), mean male body length (mm), mean female body length (mm), mean litter size (number of offspring), social class (Solitary, Pairs, Variable Groups, Groups), and diet (Carnivorous, Piscivorous, Insectivorous, Omnivorous, Frugivorous/Herbivorous) for 57 species of extant musteloids.

Usage

data("moid_traits")

Format

An object of class "data.frame".

References

Noonan, M. J., Johnson, P. J., Kitchener, A. C., Harrington, L. A., Newman, C., and Macdonald, D. W. (2016). Sexual size dimorphism in musteloids: An anomalous allometric pattern is explained by feeding ecology. Ecology and evolution, 6(23), 8495-8501. doi:10.1002/ece3.2480. Noonan, M. J., Fagan, W. F., and Fleming C. H. (2021) “A semi-variance approach to visualising phylogenetic autocorrelation”. Methods in Ecology and Evolution, in press.

See Also

musteloids.

Examples

# Load package and data
library(ctpm)
data("moid_traits")

# Plot male mass versus female mass
plot(moid_traits$Mass.M ~ moid_traits$Mass.F)

Musteloidea phylogeny.

Description

A phylogenetic tree of Musteloidea.

Usage

data("musteloids")

Format

An object of class "phylo", from package "ape".

References

Law, Chris J. and Slater, Graham J. and Mehta, Rita S. (2017). Lineage Diversity and Size Disparity in Musteloidea: Testing Patterns of Adaptive Radiation Using Molecular and Fossil-Based Methods. Systematic Biology, 67(1), 127-144. doi:10.1093/sysbio/syx047.

See Also

moid_traits.

Examples

# Load package and tree
library(ctpm)
data("musteloids")

# Plot the phylogeny
plot(musteloids)

Plotting methods for variogram objects.

Description

Produces plots of varigram objects (semi-variance vs. time lag) and model semi-variance functions, with approximate confidence intervals around the semi-variance estimates.

Usage

## S3 method for class 'vg'
plot(x, CTPM = NULL, col="black", col.CTPM = "red", fraction = 1, ...)

Arguments

x

A variogram object calculated using variogram.

CTPM

A ctpm evolutionary model object in the same format as the output of ctpm.fit.

col

Color for the empirical variogram. Can be an array.

col.CTPM

Color for the model. Can be an array.

fraction

The proportion of the variogram object, variogram, that will be plotted.

...

Additional plot.variogram function parameters.

Details

For highly irregularly phylogenetic distances with few species, it may be useful to set complete = FALSE to coarsen the variogram. When this is the cases, species are binned across lags, with the number of lags estimated using either kmeans or Gaussian Mixture Modelling GMM clustering with n classes = (N)\sqrt(N).

Value

Returns a plot of semi-variance vs. time lag, with the empirical variogram in black and the ctpm semi-variance function in red if specified.

Note

The errors of the empirical variogram are correlated. Smooth trends are not necessarily significant.

Author(s)

M. J. Noonan, C. H. Fleming.

References

Noonan, M. J., Fagan, W. F., and Fleming C. H. (2021) “A semi-variance approach to visualising phylogenetic autocorrelation”. Methods in Ecology and Evolution, in press.

See Also

vignette("variograms", package = "ctpm"), variogram, ctpm.fit.

Examples

#Load package and data
library(ctpm)
data("moid_traits")
data("musteloids")

#Extract the trait of interest from the full dataset
SSD <- moid_traits$SSD

#Calculate variogram
SVF <- variogram(SSD, musteloids)

#Plot the variogram
plot(SVF)

Calculate an empirical variogram from phylogenetic data.

Description

This function calculates the empirical variogram of phylogenetic data for visualizing stationary (time-averaged) autocorrelation structure. One of two weighting algorithms can be used.

Usage

variogram(data, phylo, weights = "IID", complete = FALSE, time.units = "Ma", 
          trait.units = NULL,  progress = TRUE, algorithm = "GMM")

Arguments

data

A vector of continuous species trait data. This vector needs to be of the same length and same order as phylo$tip.label.

phylo

An object of class 'phylo'.

weights

The weights to apply when calculating the semi-variances. Can be one of "IID", or "BM". Defaults to "IID".

time.units

A character string defining the units of the branch lengths. Defaults to "Ma".

trait.units

A character string defining the units of the trait being analysed. Defaults to uniteless.

complete

A logical value indicating whether the semi-variance is to be calculated across all possible lags. Defalts to FALSE.

algorithm

A character string defining the algorithm to apply when calculating the time-lag bins. Can be one of "kmeans", or "GMM".

progress

A logical value indicating whether to include a progress bar.

Details

weights

The weights for the semi-variance are calculated based on an assumption about the form of the the correlation matrix. If the phylogenetic process is Independent and Identically Distributed (IID), then it is sufficient to consider a correlation matrix, where the diagonal is 1 and the off-diagonal is 1/41/4 if species pair (i,j)(i,j) and (k,l)(k,l) share one species in common and 0 otherwise.

If the phylogenetic process is BM, then it is sufficient to consider a correlation matrix where the diagonal is 1 and the off-diagonal is the squared proportion of time lag τ\tau during which the backward-in-time-forward-in-time tip-branch-tip trajectories correspond to the same species.

complete

If calculating all pairwaise phylogenetic distances results in highly irregular time series (which is usually the case), it is more useful to coarsen the variogram. This is the case when complete = FALSE. Species are binned across lags, with the number of lags estimated using either kmeans or Gaussian Mixture Modelling GMM clustering with n classes = (N)\sqrt(N).

Value

Returns a variogram object (class variogram) which is a dataframe containing the time-lag, lag, the semi-variance estimate at that lag, SVF, and the degrees of freedom on the estimated semi-variance DOF.

Note

Can be slow on very large phylogenies.

Author(s)

M. J. Noonan, C. H. Fleming.

References

Noonan, M. J., Fagan, W. F., and Fleming C. H. (2021) “A semi-variance approach to visualising phylogenetic autocorrelation”. Methods in Ecology and Evolution, in press.

See Also

vignette("variograms", package = "ctpm"), plot.variogram, %#%, KMeans_rcpp, GMM.

Examples

#Load package and data
library(ctpm)
data("moid_traits")
data("musteloids")

#Extract the trait of interest from the full dataset
SSD <- moid_traits$SSD

#Calculate variogram
SVF <- variogram(SSD, musteloids)

#Plot the variogram
plot(SVF)