lmpy.statistics.pam_stats

Module containing base PAM statistic functionality.

Module Contents

Classes

CovarianceMatrixMetric

Constructor.

DiversityMetric

Constructor.

PamDistMatrixMetric

Constructor.

PamStats

Constructor for PAM stats computations.

PamStatsMetric

Constructor.

SiteMatrixMetric

Constructor.

SpeciesMatrixMetric

Constructor.

TreeDistanceMatrixMetric

Constructor.

TreeMetric

Constructor.

Functions

alpha(pam)

Calculate alpha diversity, the number of species in each site.

alpha_proportional(pam)

Calculate proportional alpha diversity.

c_score(pam)

Calculate the checker board score for the PAM.

lande(pam)

Calculate Lande's beta diversity metric for a PAM.

legendre(pam)

Calculate Legendre's beta diversity metric for a PAM.

mean_nearest_taxon_distance(phylo_dist_mtx)

Calculates the nearest neighbor distance.

mean_pairwise_distance(phylo_dist_mtx)

Calculates mean pairwise distance between species present at a site.

num_sites(pam)

Get the number of sites with presences.

num_species(pam)

Get the number of species with presences.

omega(pam)

Calculate the range size per species.

omega_proportional(pam)

Calculate the mean proportional range size of each species.

pearson_correlation(pam, phylo_dist_mtx)

Calculates the Pearson correlation coefficient for each site.

phi(pam)

Calculate phi, the range size per site.

phi_average_proportional(pam)

Calculate proportional range size per site.

phylogenetic_diversity(tree)

Calculate phylogenetic diversity of a tree.

psi(pam)

Calculate the range richness of each species.

psi_average_proportional(pam)

Calculate the mean proportional species diversity.

schluter_site_variance_ratio(pam)

Calculate Schluter's site variance ratio.

schluter_species_variance_ratio(pam)

Calculate Schluter's species variance ratio.

sigma_sites(pam)

Compute the site sigma metric for a PAM.

sigma_species(pam)

Compute the species sigma metric for a PAM.

sum_pairwise_distance(phylo_dist_mtx)

Calculates the sum pairwise distance for all species present at a site.

whittaker(pam)

Calculate Whittaker's beta diversity metric for a PAM.

class lmpy.statistics.pam_stats.CovarianceMatrixMetric(func)[source]

Bases: PamStatsMetric

Constructor.

Parameters

func – The function to call.

class lmpy.statistics.pam_stats.DiversityMetric(func)[source]

Bases: PamStatsMetric

Constructor.

Parameters

func – The function to call.

class lmpy.statistics.pam_stats.PamDistMatrixMetric(func)[source]

Bases: _SiteStatMetric

Constructor.

Parameters

func – The function to call.

class lmpy.statistics.pam_stats.PamStats(pam, tree=None, tree_matrix=None, node_heights_matrix=None, tip_lengths_matrix=None)[source]

Constructor for PAM stats computations.

Parameters
  • pam (Matrix) – A presence-absence matrix to use for computations.

  • tree (TreeWrapper) – A tree to use for phylogenetic distance computations.

  • tree_matrix (Matrix) – A matrix of tip / node presence absence values.

  • node_heights_matrix (Matrix) – A matrix of node height values.

  • tip_lengths_matrix (Matrix) – A matrix of tip length values.

covariance_stats = [None, None][source]
diversity_stats = [None, None, None, None, None, None][source]
site_matrix_stats = [None, None, None, None][source]
site_pam_dist_mtx_stats = [None][source]
site_tree_distance_matrix_stats = [None, None, None][source]
site_tree_stats = [None][source]
species_matrix_stats = [None, None, None, None][source]
calculate_covariance_statistics(self)[source]

Calculate covariance statistics matrices.

Returns

A list of metric name, value tuples for covariance stats.

Return type

list of tuple

calculate_diversity_statistics(self)[source]

Calculate diversity statistics.

Returns

A list of metric name, value tuples for diversity metrics.

Return type

list of tuple

calculate_site_statistics(self)[source]

Calculate site-based statistics.

Returns

A matrix of site-based statistics for the selected metrics.

Return type

Matrix

calculate_species_statistics(self)[source]

Calculate species-based statistics.

Returns

A matrix of species-based statistics for the selected metrics.

Return type

Matrix

register_metric(self, name, metric_function)[source]

Register a new metric.

Parameters
  • name (str) – A name for this metric that will be used for a header.

  • metric_function (function) – A decorated metric generating function.

Raises

TypeError – Raised if the metric function type cannot be processed.

class lmpy.statistics.pam_stats.PamStatsMetric(func)[source]

Constructor.

Parameters

func – The function to call.

__call__(self, *args, **kwargs)[source]

Call the wrapped function.

Parameters
  • *args – Positional arguments passed to the function.

  • **kwargs – Keyword arguments passed to the function.

Returns

The output of the wrapped function.

Return type

object

class lmpy.statistics.pam_stats.SiteMatrixMetric(func)[source]

Bases: _SiteStatMetric

Constructor.

Parameters

func – The function to call.

class lmpy.statistics.pam_stats.SpeciesMatrixMetric(func)[source]

Bases: _SpeciesStatMetric

Constructor.

Parameters

func – The function to call.

class lmpy.statistics.pam_stats.TreeDistanceMatrixMetric(func)[source]

Bases: _SiteStatMetric

Constructor.

Parameters

func – The function to call.

class lmpy.statistics.pam_stats.TreeMetric(func)[source]

Bases: _SiteStatMetric

Constructor.

Parameters

func – The function to call.

lmpy.statistics.pam_stats.alpha(pam)[source]

Calculate alpha diversity, the number of species in each site.

Parameters

pam (Matrix) – The presence-absence matrix to use for the computation.

Returns

A column of alpha diversity values for each site in the PAM.

Return type

Matrix

lmpy.statistics.pam_stats.alpha_proportional(pam)[source]

Calculate proportional alpha diversity.

Parameters

pam (Matrix) – The presence-absence matrix to use for the computation.

Returns

A column of proportional alpha diversity values for each site in the

PAM.

Return type

Matrix

lmpy.statistics.pam_stats.c_score(pam)[source]

Calculate the checker board score for the PAM.

Parameters

pam (Matrix) – The presence-absence matrix to use for the computation.

Returns

The checkerboard score for the PAM.

Return type

float

lmpy.statistics.pam_stats.lande(pam)[source]

Calculate Lande’s beta diversity metric for a PAM.

Parameters

pam (Matrix) – The presence-absence matrix to use for the computation.

Returns

Lande’s beta diversity for the PAM.

Return type

float

lmpy.statistics.pam_stats.legendre(pam)[source]

Calculate Legendre’s beta diversity metric for a PAM.

Parameters

pam (Matrix) – The presence-absence matrix to use for the computation.

Returns

Legendre’s beta diversity for the PAM.

Return type

float

lmpy.statistics.pam_stats.mean_nearest_taxon_distance(phylo_dist_mtx)[source]

Calculates the nearest neighbor distance.

Parameters

phylo_dist_mtx (Matrix) – A matrix of distances between the species present at a site.

Returns

The average distance from each taxa to taxa nearest to it.

Return type

float

lmpy.statistics.pam_stats.mean_pairwise_distance(phylo_dist_mtx)[source]

Calculates mean pairwise distance between species present at a site.

Parameters

phylo_dist_mtx (Matrix) – A matrix of distances between the species present at a site.

Returns

The average distance from each taxa all of the other co-located taxa.

Return type

float

lmpy.statistics.pam_stats.num_sites(pam)[source]

Get the number of sites with presences.

Parameters

pam (Matrix) – The presence-absence matrix to use for the computation.

Returns

The number of sites that have present species.

Return type

int

lmpy.statistics.pam_stats.num_species(pam)[source]

Get the number of species with presences.

Parameters

pam (Matrix) – The presence-absence matrix to use for the computation.

Returns

The number of species that are present in at least one site.

Return type

int

lmpy.statistics.pam_stats.omega(pam)[source]

Calculate the range size per species.

Parameters

pam (Matrix) – The presence-absence matrix to use for the computation.

Returns

A row of range sizes for each species in the PAM.

Return type

Matrix

lmpy.statistics.pam_stats.omega_proportional(pam)[source]

Calculate the mean proportional range size of each species.

Parameters

pam (Matrix) – The presence-absence matrix to use for the computation.

Returns

A row of the proportional range sizes for each species in the PAM.

Return type

Matrix

lmpy.statistics.pam_stats.pearson_correlation(pam, phylo_dist_mtx)[source]

Calculates the Pearson correlation coefficient for each site.

Parameters
  • pam (Matrix) – A presence-absence matrix to use for the computation.

  • phylo_dist_mtx (Matrix) – A matrix of distance between species.

Returns

A column of Pearson correlation values for each site in a PAM.

Return type

Matrix

lmpy.statistics.pam_stats.phi(pam)[source]

Calculate phi, the range size per site.

Parameters

pam (Matrix) – The presence-absence matrix to use for the computation.

Returns

A column of the sum of the range sizes for the species present at each

site in the PAM.

Return type

Matrix

lmpy.statistics.pam_stats.phi_average_proportional(pam)[source]

Calculate proportional range size per site.

Parameters

pam (Matrix) – The presence-absence matrix to use for the computation.

Returns

A column of the proportional value of the sum of the range sizes for

the species present at each site in the PAM.

Return type

Matrix

lmpy.statistics.pam_stats.phylogenetic_diversity(tree)[source]

Calculate phylogenetic diversity of a tree.

Parameters

tree (TreeWrapper) – A phylogenetic tree to compute phylogenetic diversity for.

Returns

The sum of the edge lengths of the nodes of the provided tree.

Return type

float

lmpy.statistics.pam_stats.psi(pam)[source]

Calculate the range richness of each species.

Parameters

pam (Matrix) – The presence-absence matrix to use for the computation.

Returns

A row of range richness for the sites that each species is present in.

Return type

Matrix

lmpy.statistics.pam_stats.psi_average_proportional(pam)[source]

Calculate the mean proportional species diversity.

Parameters

pam (Matrix) – The presence-absence matrix to use for the computation.

Returns

A row of proportional range richness for the sites that each species in

the PAM is present.

Return type

Matrix

lmpy.statistics.pam_stats.schluter_site_variance_ratio(pam)[source]

Calculate Schluter’s site variance ratio.

Parameters

pam (Matrix) – The presence-absence matrix to use for the computation.

Returns

The Schluter site variance ratio for the PAM.

Return type

float

lmpy.statistics.pam_stats.schluter_species_variance_ratio(pam)[source]

Calculate Schluter’s species variance ratio.

Parameters

pam (Matrix) – The presence-absence matrix to use for the computation.

Returns

The Schluter species variance ratio for the PAM.

Return type

float

lmpy.statistics.pam_stats.sigma_sites(pam)[source]

Compute the site sigma metric for a PAM.

Parameters

pam (Matrix) – The presence-absence matrix to use for the computation.

Returns

Matrix of covariance of composition of sites.

Return type

Matrix

lmpy.statistics.pam_stats.sigma_species(pam)[source]

Compute the species sigma metric for a PAM.

Parameters

pam (Matrix) – The presence-absence matrix to use for the computation.

Returns

Matrix of covariance of composition of species.

Return type

Matrix

lmpy.statistics.pam_stats.sum_pairwise_distance(phylo_dist_mtx)[source]

Calculates the sum pairwise distance for all species present at a site.

Parameters

phylo_dist_mtx (Matrix) – A matrix of distances between the species present at a site.

Returns

The total distance from each taxa all of the other co-located taxa.

Return type

float

lmpy.statistics.pam_stats.whittaker(pam)[source]

Calculate Whittaker’s beta diversity metric for a PAM.

Parameters

pam (Matrix) – The presence-absence matrix to use for the computation.

Returns

Whittaker’s beta diversity for the PAM.

Return type

float