gneiss.sort.mean_niche_estimator

gneiss.sort.mean_niche_estimator(abundances, gradient)[source]

Estimates the mean niche along a gradient of an organism.

Calculates the mean niche of an organism along a gradient. This is done by calculating the mean gradient values that an organism is observed in.

Specifically, this module calculates the following

\[f(g , x) = \sum\limits_{i=1}^N g_i \frac{x_i}{\sum\limits_{j=1}^N x_j}\]

Where \(N\) is the number of samples, \(x_i\) is the proportion of species \(x\) in sample \(i\), \(g_i\) is the gradient value at sample i.

Parameters:
  • abundances (pd.Series, np.float) – Vector of fraction abundances of an organism over a list of samples.
  • gradient (pd.Series, np.float) – Vector of numerical gradient values.
Returns:

The mean gradient that the organism lives in.

Return type:

np.float

Raises:
  • ValueError: – If the length of abundances is not the same length as gradient.
  • ValueError: – If the length of gradient contains nans.