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.DataFrame or 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 feature is observed in. If abundances is a pd.DataFrame containing the mean gradient values for each feature. Otherwise a float is returned.

Return type:

pd.Series or np.float

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