General Dynamic Model API¶
sar_gdm¶
sars.sar_gdm ¶
sar_gdm(data: DataFrame, model: str = 'loga', mod_sel: bool = False, area_col: str = 'area', species_col: str = 'species', time_col: str = 'time') -> GDMFit | GDMMultiFit
Fit the general dynamic model of oceanic island biogeography (GDM).
The GDM (Whittaker, Triantis & Ladle 2008) describes island richness as a
function of island area plus a hump-shaped function of island age: time
and time squared, with a negative coefficient on time squared when
richness rises and then falls over an island's life. model chooses how
area (and time) enter, with S richness and T island age:
"loga":S = Int + A*log(area) + Ti*T + Ti2*T^2, the "ATT²" model of Whittaker et al. (R sars's"loga"and"ATT2")"linear":S = Int + A*area + Ti*T + Ti2*T^2"power_area":S = exp(Int + A*log(area) + Ti*T + Ti2*T^2), a power law of area (area^A) times a hump in time"power_area_time":S = exp(Int + A*log(area) + Ti*log(T) + Ti2*log(T)^2), with time logged as well"all": all four, with a table comparing them
These are the forms R sars's gdm fits. The first two are fitted by
ordinary least squares. The power forms are fitted by nonlinear least
squares on richness itself (not by regressing log richness), so every form
has the same response and their AIC values are comparable.
With mod_sel=True the GDM is also compared with three simpler models
of the same form: area and time (no time squared), area only, and an
intercept only. A GDM that doesn't beat "A + T" shows no evidence of a
hump in island age.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
One row per island, with numeric columns for area, species richness and island age. |
required |
model
|
str
|
"loga" (the default), "linear", "power_area", "power_area_time" or "all". |
'loga'
|
mod_sel
|
bool
|
Also fit the three simpler candidates and rank all four by AICc, in
the fit's |
False
|
area_col
|
str
|
Names of the columns holding area, richness and island age. |
'area'
|
species_col
|
str
|
Names of the columns holding area, richness and island age. |
'area'
|
time_col
|
str
|
Names of the columns holding area, richness and island age. |
'area'
|
Returns:
| Type | Description |
|---|---|
GDMFit or GDMMultiFit
|
A |
Raises:
| Type | Description |
|---|---|
TypeError
|
If data is not a DataFrame. |
KeyError
|
If a named column is missing. |
ValueError
|
If |
Warns:
| Type | Description |
|---|---|
UserWarning
|
If the solver did not converge for a power form's GDM or, with
|
Notes
Every coefficient and the residual variance count as parameters, so the
GDM has k = 5 and AICc is finite only for 7 or more islands. In the power
forms the simpler candidates are power forms too: "A" is the power law
exp(Int + A*log(area)) and "Intercept" is exp(Int), the mean
richness, with Int on the log scale like the others.
The fit doesn't depend on the units of area or time, except through the coefficients that carry those units.
The normal likelihood grows without bound as the residuals go to zero.
So that a fit passing through every island still has finite criteria, its
residual sum of squares is not taken below the rounding error of the data
(machine epsilon times the sum of squared richness) when AIC, AICc and BIC
are computed. Exact fits then tie on the likelihood and are ranked by
their number of parameters. r_squared, rse and the standard errors
use the residuals as they are.
References
Whittaker RJ, Triantis KA, Ladle RJ (2008). A general dynamic theory of oceanic island biogeography. Journal of Biogeography 35, 977-994.
Examples:
GDMFit¶
sars.GDMFit
dataclass
¶
Result of fitting the general dynamic model with one area form.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
str
|
The form fitted: "loga", "linear", "power_area" or "power_area_time". |
terms |
str
|
Which terms the fit has: "GDM" (area, time and time squared), or one
of the simpler candidates "A + T", "A" and "Intercept" (the fits in
|
params |
dict[str, float]
|
Coefficients, named as in R sars: |
std_errors |
dict[str, float]
|
Standard error of each coefficient, from the residual variance and the model's gradient at the fit (exact for the forms that are linear in their parameters, the usual large-sample approximation for the power forms). |
p_values |
dict[str, float]
|
Two-sided p value of each coefficient's t statistic (coefficient over
standard error, on |
fitted |
ndarray
|
Fitted richness for each row of |
r_squared |
float
|
1 - RSS / total sum of squares, on richness itself for every form. |
rse |
float
|
Residual standard error: sqrt(RSS / (n - number of coefficients)). |
aic, aicc, bic |
float
|
Information criteria from the normal likelihood, counting each
coefficient and the residual variance as parameters (5 for the GDM).
AICc is infinite when |
n |
int
|
Number of islands. |
converged |
bool
|
Whether the solver converged. Always True for "loga" and "linear", which have a closed-form solution. |
data |
DataFrame
|
The data fitted (columns: area, species, time). |
comparison |
DataFrame | None
|
With |
candidates |
dict[str, GDMFit] | None
|
With |
formula
property
¶
The fitted equation, e.g. S = Int + A*log(area) + Ti*time + Ti2*time^2.
predict ¶
Predict species richness for given area and island age value(s).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
float or array - like
|
Island area(s), in the units of the fitted data. |
required |
time
|
float or array - like
|
Island age(s), in the units of the fitted data. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Predicted richness, in the broadcast shape of |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
GDMMultiFit¶
sars.GDMMultiFit
dataclass
¶
The general dynamic model fitted with every area form (model="all").
Attributes:
| Name | Type | Description |
|---|---|---|
fits |
dict[str, GDMFit]
|
The fit for each form, keyed "loga", "linear", "power_area" and "power_area_time". |
summary |
DataFrame
|
The four fits ranked by AICc: columns model, k, RSE, R2, AIC, AICc, BIC, delta_AIC, delta_AICc, weight_AIC, weight (the AICc weight) and converged. The forms share a response (richness) and a parameter count, so the ranking is the ranking by residual sum of squares. A form whose fit did not converge is listed last, with no deltas and no weight. |
data |
DataFrame
|
The data fitted (columns: area, species, time). |