Random Placement API¶
coleman¶
sars.coleman ¶
Compare site richness with Coleman's random placement model.
Under random placement every individual lands on a site with probability
equal to the site's share of the total area, independently of the others.
A species with n individuals is then absent from a site of relative
area alpha with probability (1 - alpha)^n, which gives the expected
richness S(alpha) = sum_i [1 - (1 - alpha)^n_i] and the variance
sum_i (1 - alpha)^n_i - sum_i (1 - alpha)^(2 n_i) (Coleman 1981). The
model has no parameters to estimate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
abundance
|
pd.DataFrame or 2-D array-like
|
Species-by-site abundance table: one row per species, one column per
site, each value the number of individuals of that species counted at
that site. This is the orientation R |
required |
area
|
array - like
|
Area of each site; all must be positive. A list or array is matched
to |
required |
Returns:
| Type | Description |
|---|---|
ColemanFit
|
The per-site table ( |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Warns:
| Type | Description |
|---|---|
UserWarning
|
If no value in |
Notes
Species absent from every site are dropped. They add nothing to the
expected richness or to its variance ((1 - alpha)^0 = 1), so the
result is the same with or without them; ColemanFit.n_species counts
only the species that were seen.
A site counts as within one standard deviation when
|observed - expected| <= sd.
The one-third rule is a convention, not a test with a known error rate.
One standard deviation either side holds roughly two thirds of the spread,
so about a third of the sites are expected outside it under random
placement itself, and with few sites the rule often rejects data that
were placed at random. Read rejected alongside the plot
(plot_coleman) and the pattern of the sites that fall outside.
References
Coleman BD (1981). On random placement and species-area relations. Mathematical Biosciences 54, 191-215.
Coleman BD, Mares MA, Willig MR, Hsieh Y-H (1982). Randomness, area, and species richness. Ecology 63, 1121-1133.
Examples:
>>> import numpy as np
>>> import sars
>>> rng = np.random.default_rng(1)
>>> area = np.array([1.0, 2.0, 5.0, 10.0, 20.0, 50.0])
>>> totals = np.array([1, 2, 3, 5, 8, 13, 21, 34, 55, 89])
>>> counts = np.array([rng.multinomial(n, area / area.sum()) for n in totals])
>>> fit = sars.coleman(counts, area)
>>> fit.n_sites
6
ColemanFit¶
sars.ColemanFit
dataclass
¶
Coleman's random placement model compared with observed richness.
Attributes:
| Name | Type | Description |
|---|---|---|
sites |
DataFrame
|
One row per site, in the order given, indexed by site label (the
abundance table's column labels, or 0, 1, ... for an array). Columns:
|
abundance |
Series
|
Total abundance of each species over all sites, indexed by species label (the abundance table's row labels, or row positions for an array). Species absent from every site are left out. |
total_area |
float
|
Sum of the site areas. |
Notes
Two fits are equal only if they are the same object: the tables they hold have no single true-or-false comparison.
fraction_outside
property
¶
Share of the sites whose observed richness lies more than one standard deviation from the expected value.
rejected
property
¶
Whether random placement is rejected: True when more than a third of the sites lie more than one standard deviation from the expected curve.
This is the conventional rule, and a rough one: about a third of the sites are expected outside one standard deviation when placement is random, so with few sites it often rejects data that are.
predict ¶
Expected species richness of a site of the given area(s).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
float or array - like
|
Area value(s), in the units of the site areas, between 0 and
|
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Expected richness under random placement, with the shape of |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an area is negative, not finite, or larger than |
predict_sd ¶
Standard deviation of the richness of a site of the given area(s).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
float or array - like
|
Area value(s), in the units of the site areas, between 0 and
|
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Standard deviation of richness under random placement, with the
shape of |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an area is negative, not finite, or larger than |
placement_test ¶
A calibrated test of random placement, by simulation.
The one-third rule (rejected) has no stated error rate, and with
few sites it often rejects data placed at random. This test simulates
random placement itself: each species' individuals, as many as were
counted, are scattered over the sites in proportion to their areas,
n_sim times. The statistic is the sum over sites of the squared
distance of observed from expected richness, in standard deviations,
and the p value is the share of simulations at least as far from the
curve as the data, counting the data as one of them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_sim
|
int
|
Number of simulated placements. The smallest p value possible is
|
999
|
rng
|
Generator or int
|
Random number generator, or a seed for one, for a reproducible result. |
None
|
Returns:
| Type | Description |
|---|---|
ColemanTest
|
The statistic, its p value, and how often the one-third rule rejected the simulated random placements: that rule's false rejection rate for these species totals and site areas. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ColemanTest¶
sars.ColemanTest
dataclass
¶
A simulation test of Coleman's random placement model
(ColemanFit.placement_test).
Attributes:
| Name | Type | Description |
|---|---|---|
statistic |
float
|
Sum over sites of the squared distance of observed from expected richness, in standard deviations. |
p_value |
float
|
Share of the simulated random placements, the data counted among them, whose statistic is at least the data's. A small value is evidence against random placement. |
n_sim |
int
|
Number of simulated placements. |
rule_rejection_rate |
float
|
Share of the simulated random placements that the one-third rule rejects: how often that rule would reject random placement for these species totals and site areas when it holds. |