| Title: | Calculating Density-Independent Niche Breadth Indices from Abundance Data |
|---|---|
| Description: | Deriving density-independent and density-dependent niche breadth indices from abundance data of two or more habitats, including both the pairwise and n-dimensional methods to calculate isodar-adjusted inequality. Methods are described in Granot, Dubiner & Belmaker (in revision), "Why abundance-based indices of niche breadth are biased, and what can be done to improve them", Ecology Letters. |
| Authors: | Shahar Dubiner [aut, cre] (ORCID: <https://orcid.org/0000-0003-1771-0087>), Itai Granot [aut], Jonathan Belmaker [aut] |
| Maintainer: | Shahar Dubiner <[email protected]> |
| License: | GPL-3 |
| Version: | 1.0.0 |
| Built: | 2026-10-13 11:31:11 UTC |
| Source: | https://github.com/cran/isoniche |
Fits isodar relationships using total least squares (TLS), which minimizes orthogonal distances between observations and the fitted relationship.
fit_isodars( data, hab_cols = NULL, n_habitats = ncol(data), flip_intercept = TRUE, dim = "pairwise" )fit_isodars( data, hab_cols = NULL, n_habitats = ncol(data), flip_intercept = TRUE, dim = "pairwise" )
data |
A data frame containing abundance columns for the habitats. |
hab_cols |
Character vector giving the habitat abundance columns.
If |
n_habitats |
Number of habitats to use when |
flip_intercept |
Logical. If TRUE, pairwise relationships with a negative intercept are reversed so that the reported intercept is positive. |
dim |
Either |
With dim = "pairwise" (default), TLS relationships are fitted between
every pair of habitats.
With dim = "ndim", a single multidimensional TLS hyperplane is fitted
using all habitats simultaneously.
For dim = "pairwise", a tibble with one row for every
habitat pair, containing the coefficients of the TLS regression.
For dim = "ndim", a tibble containing the coefficients
of the n-dimensional TLS hyperplane.
set.seed(1) populations1 <- simulate_isodars(1, 1.1, 1, 0, noise = 2, n = 10) fit_isodars(populations1, hab_cols=c("hab1","hab2","hab3")) populations2 <- simulate_isodars(1.5, 2, 5, 2, noise = 2, n = 10) fit_isodars(populations2, hab_cols=c("hab1","hab2","hab3"))set.seed(1) populations1 <- simulate_isodars(1, 1.1, 1, 0, noise = 2, n = 10) fit_isodars(populations1, hab_cols=c("hab1","hab2","hab3")) populations2 <- simulate_isodars(1.5, 2, 5, 2, noise = 2, n = 10) fit_isodars(populations2, hab_cols=c("hab1","hab2","hab3"))
Reconstructs habitat abundances for one or more requested total abundances using either pairwise or n-dimensional isodars.
iai( isodars, abundances = NULL, weights = NULL, method = "gini", plot = FALSE, scaled = TRUE, max_search = 10000, dim = "pairwise" )iai( isodars, abundances = NULL, weights = NULL, method = "gini", plot = FALSE, scaled = TRUE, max_search = 10000, dim = "pairwise" )
isodars |
A data frame returned by fit_isodars(). |
abundances |
Numeric vector of total abundances. If NULL, the minimum total abundance yielding positive abundance in all habitats is searched. |
weights |
Weighting scheme for pairwise reconstruction. Either NULL, a numeric vector, or "1/var". Not used for dim = "ndim" (1 isodar - no variance). |
method |
Currently only "gini". |
plot |
Logical. If TRUE, plots niche breadth against chosen total abundances. |
scaled |
Logical. If TRUE, coerces minimum possible IAI to be zero rather than 1/n. |
max_search |
Maximum abundance searched when abundances = NULL. |
dim |
Either "pairwise" or "ndim". Should match the dim used in fit_isodars(). |
With dim = "pairwise", the pairwise relationships are simultaneously fitted using (optionally weighted) total least squares (TLS).
With dim = "ndim", the n-dimensional TLS hyperplane is used directly. For a given total abundance, the reconstructed abundance vector is the point on the TLS hyperplane and total-abundance plane that is closest to equal allocation among habitats. Non-negative abundances are enforced using an active-set procedure.
Niche breadth is defined as 1 - Gini(x).
A tibble containing total abundance, niche breadth, and the reconstructed abundance of each habitat.
set.seed(1) populations1 <- simulate_isodars(1, 1.1, 1, 0, noise = 2, n = 10) isodars1 <- fit_isodars(populations1, hab_cols=c("hab1","hab2","hab3")) iai(isodars1) iai(isodars1,abundances=c(6,10,16,20,40,60,130,260),weights="1/var",plot=TRUE) populations2 <- simulate_isodars(1.5, 2, 5, 2, noise = 2, n = 10) isodars2 <- fit_isodars(populations2, hab_cols=c("hab1","hab2","hab3"), dim="ndim") iai(isodars2, dim="ndim", scaled = "FALSE") iai(isodars2, dim="ndim") iai(isodars2, dim="ndim",abundances=c(26,46,60,106,160,260),plot=TRUE)set.seed(1) populations1 <- simulate_isodars(1, 1.1, 1, 0, noise = 2, n = 10) isodars1 <- fit_isodars(populations1, hab_cols=c("hab1","hab2","hab3")) iai(isodars1) iai(isodars1,abundances=c(6,10,16,20,40,60,130,260),weights="1/var",plot=TRUE) populations2 <- simulate_isodars(1.5, 2, 5, 2, noise = 2, n = 10) isodars2 <- fit_isodars(populations2, hab_cols=c("hab1","hab2","hab3"), dim="ndim") iai(isodars2, dim="ndim", scaled = "FALSE") iai(isodars2, dim="ndim") iai(isodars2, dim="ndim",abundances=c(26,46,60,106,160,260),plot=TRUE)
Resamples the original abundance data with replacement, refits the isodars for each bootstrap replicate, and calculates the resulting isodar-adjusted niche breadth.
isoderr( data, hab_cols = NULL, n_habitats = ncol(data), dim = "pairwise", abundances = NULL, n_boot = 1000, output = "SD", conf_level = 0.95, weights = NULL, flip_intercept = TRUE, max_search = 10000, seed = NULL )isoderr( data, hab_cols = NULL, n_habitats = ncol(data), dim = "pairwise", abundances = NULL, n_boot = 1000, output = "SD", conf_level = 0.95, weights = NULL, flip_intercept = TRUE, max_search = 10000, seed = NULL )
data |
A data frame containing abundance columns for the habitats. |
hab_cols |
Character vector giving the habitat abundance columns. If NULL, the first n_habitats columns are used. |
n_habitats |
Number of habitats to use when hab_cols = NULL. |
dim |
Either "pairwise" (default) or "ndim". |
abundances |
Numeric vector of total abundances. If NULL, the abundance selected by iai() from the original data is used. |
n_boot |
Number of bootstrap replicates. |
output |
Either "SD", "SE", or "CI". |
conf_level |
Confidence level for CI. Default is 0.95. |
weights |
Weighting scheme passed to iai(). Only applicable to dim = "pairwise". |
flip_intercept |
Passed to fit_isodars(). |
max_search |
Maximum abundance searched when abundances = NULL. |
seed |
Optional random-number seed. |
With dim = "pairwise", pairwise TLS isodars are refitted for every bootstrap replicate.
With dim = "ndim", an n-dimensional TLS hyperplane is refitted for every bootstrap replicate.
The requested total abundances are determined once from the original dataset and then held constant across bootstrap replicates.
A tibble containing the total abundance, bootstrap estimate, and requested measure of uncertainty.
set.seed(1) populations1 <- simulate_isodars(1.5, 2, 5, 2, noise = 2, n = 10) isoderr(populations1, n_boot=100, weights=NULL,hab_cols=c("hab1","hab2","hab3")) isoderr(populations1, n_boot=100,output="CI",hab_cols=c("hab1","hab2","hab3"))set.seed(1) populations1 <- simulate_isodars(1.5, 2, 5, 2, noise = 2, n = 10) isoderr(populations1, n_boot=100, weights=NULL,hab_cols=c("hab1","hab2","hab3")) isoderr(populations1, n_boot=100,output="CI",hab_cols=c("hab1","hab2","hab3"))
Simulates abundance data for three habitats across n sites using
sequential linear relationships (isodars) with Gaussian noise:
hab2 is generated from hab1 using slope1 and int1
hab3 is generated from hab2 using slope2 and int2
simulate_isodars( slope1, slope2, int1, int2, noise = 1, n = 30, hab1_max = 100/(slope1^1.2) - int1 )simulate_isodars( slope1, slope2, int1, int2, noise = 1, n = 30, hab1_max = 100/(slope1^1.2) - int1 )
slope1 |
Numeric. Isodar slope for |
slope2 |
Numeric. Isodar slope for |
int1 |
Numeric. Isodar intercept for |
int2 |
Numeric. Isodar intercept for |
noise |
Numeric (>= 0). Standard deviation of Gaussian noise. |
n |
Integer (> 0). Number of simulated sites. |
hab1_max |
Integer. maximum abundance value in habitat 1 (other maxima calculated from hab1_max). Default is derived to generally suit the isodar parameters, but is arbitrary. |
The output includes simple per-site niche metrics (CV and Gini) computed from the three habitat abundances.
A tibble with one row per simulated site containing:
hab1, hab2, hab3: simulated abundances (nonnegative integers)
total_abundance: hab1 + hab2 + hab3
mean_abundance: total_abundance divided by 3
sd: scaled standard deviation of habitat abundances
cv: coefficient of variation (NA if mean_abundance == 0)
gini: Gini coefficient of habitat abundances
set.seed(1) simulate_isodars(1, 1.1, 1, 0, noise = 2, n = 10) simulate_isodars(1.5, 2, 5, 2, noise = 2, n = 10)set.seed(1) simulate_isodars(1, 1.1, 1, 0, noise = 2, n = 10) simulate_isodars(1.5, 2, 5, 2, noise = 2, n = 10)