The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.
EcoNiche is an R package for quantifying niche position and niche breadth under continuous, multidimensional environmental gradients.
Traditional niche breadth indices often treat sampling units as discrete states. However, real ecological gradients are continuous, multidimensional, and frequently confounded by covariates (e.g., climate, spatial structure, background environmental effects). EcoNiche provides a standardized workflow to estimate niche parameters within a constrained ordination framework while explicitly controlling for covariates.
The package is built around one central idea:
Estimate niche position and conditional niche breadth in a continuous environmental space, rather than across arbitrary discrete states.
To achieve this, EcoNiche implements three analytical modules with distinct roles:
This is the primary method of EcoNiche.
This workflow is based on canonical correspondence analysis (CCA) and partial CCA (pCCA) following Okie et al. (2015) and Feng et al. (2020).
It allows users to:
Conceptually:
This framework is specifically designed for:
The GAM module serves both as a validation tool and as a biologically interpretable response modeling framework.
It fits species-specific response curves along the composite environmental axis (typically CCA1), allowing:
This module serves three complementary purposes:
Cross-validation of ordination-based niche
position
GAM-derived optima can be compared directly with CCA-based
abundance-weighted means to evaluate positional consistency.
Quantification of one-dimensional tolerance along the
dominant composite gradient
Breadth50 provides a practical measure of effective response range along
the main constrained axis.
Visualization of individual species response
curves
GAM explicitly models the abundance–environment relationship, allowing
users to:
Importantly, the GAM analysis is conducted within the same gradient coordinate system defined by CCA, ensuring conceptual consistency between ordination-based and response-curve-based niche estimation.
Levins’ index is implemented for comparison, not as the primary estimator.
EcoNiche provides two Levins implementations:
These serve as sensitivity benchmarks to evaluate:
In continuous-gradient contexts, Levins’ breadth may reflect occupancy or prevalence more than environmental tolerance. Therefore, it is included primarily for methodological comparison.
EcoNiche is designed as a modular analytical framework rather than a fixed analytical pipeline.
At its core, the framework is built on constrained ordination:
CCA / partial-CCA define the composite environmental gradient and estimate niche parameters in continuous multivariate space.
From this core framework, users may choose different complementary modules depending on their research question:
Used to estimate:
This module is recommended when: - Environmental predictors are multidimensional - Covariate control is required - Continuous-gradient niche estimation is the primary objective
Used when users wish to:
GAM operates along the composite gradient defined by CCA, ensuring consistency in coordinate space.
Used when users wish to:
Levins’ index is included primarily as a comparative benchmark rather than the primary estimator under continuous gradients.
In practice, users typically:
This flexible structure allows researchers to tailor analyses to their ecological question while maintaining a coherent gradient-based coordinate system.
Package version: 0.9.0
# install.packages("remotes")
remotes::install_github("zhoushuotao/EcoNiche")EcoNiche imports:
Suggested:
Most functions assume the following:
otu:
taxon-by-sample abundance tableotu[1:3, 1:3]
# S1 S2 S3
# OTU1 10 0 2
# OTU2 3 1 0
# OTU3 0 0 5env:
sample-by-environment tablerownames(env) should match colnames(otu)
(EcoNiche will align by intersection when relevant)env[1:3, ]
# Temp pH SOC
# S1 15.2 6.7 2.31
# S2 18.1 6.3 1.90
# S3 12.4 6.8 3.05group (only for
group workflow)names(group) must be sample IDslibrary(EcoNiche)
set.seed(1)
# OTU table: 50 taxa x 30 samples
otu <- matrix(rpois(50 * 30, lambda = 10), nrow = 50, ncol = 30)
rownames(otu) <- paste0("OTU", 1:50)
colnames(otu) <- paste0("S", 1:30)
# Environment table: 30 samples x 3 variables
env <- data.frame(
Temp = rnorm(30, 15, 3),
pH = rnorm(30, 6.5, 0.4),
SOC = rlnorm(30, 2, 0.3)
)
rownames(env) <- colnames(otu)EcoNiche provides a controller function cca_workflow()
and two explicit workflows:
cca_workflow_gradient()cca_workflow_group()Use when you want:
res <- cca_workflow(
mode = "gradient",
otu = otu,
env = env,
sel = "Temp", # constrained variable(s) for the width axis (partial-CCA)
covariates = c("pH", "SOC") # variables for position axis (CCA) and as covariates in partial-CCA
)
# Species-level niche traits (position/width)
head(res$species$species)
# Plot: niche width vs niche position
res$species$plot
# Site niche position vs a gradient variable
res$gradient$plotsel and covariates in CCA/pCCAEcoNiche separates environmental predictors into:
sel — focal environmental variable(s) defining the
primary constrained axiscovariates — conditioning variables used to control
background structureThe appropriate choice depends on study design and ecological hypothesis.
If samples were collected explicitly along a known environmental gradient (e.g., temperature, pH, elevation), that gradient should typically be treated as the focal predictor.
Example:
Recommended setup:
sel = "Temperature"
covariates = c("pH", "NDVI")Interpretation:
CCA constructs the dominant composite axis associated with the focal gradient.
pCCA controls for background covariates.
Niche position reflects species location along the focal gradient.
Conditional niche breadth reflects dispersion after removing background effects.
This setup is appropriate when the research question is:
How do species’ niches vary along temperature after accounting for other environmental structure?
If the dominant environmental structure is unclear, or multiple predictors are strongly correlated, a data-driven approach is recommended.
In this case:
Perform PCA on environmental variables.
Inspect loadings of PC1 and PC2.
Identify the dominant composite environmental structure.
Use this information to guide CCA/pCCA specification.
Example:
PC1 loads strongly on precipitation and moisture.
PC2 reflects soil chemistry.
You may then:
Use predictors associated with PC1 as sel
Use remaining structure as covariates
Or reduce dimensionality first via cca_prep_env()
This approach avoids arbitrarily selecting a single variable when gradients are inherently multivariate.
Use when samples belong to groups (e.g., habitat types, treatments, regions) and you want group summaries.
group <- rep(c("A", "B", "C"), length.out = ncol(otu))
names(group) <- colnames(otu)
res_g <- cca_workflow(
mode = "group",
otu = otu,
env = env,
sel = "Temp",
covariates = c("pH", "SOC"),
group = group,
plot_type = "both" # "sample" / "group" / "both"
)
head(res_g$group$group_summary)
res_g$plotUse when your main question is:
For each taxon, what is the optimum along gradient X, and how wide is its response?
EcoNiche fits one GAM per taxon and reports (among others):
optimum_env (peak along the gradient)env50_min, env50_max,
breadth50 (50% peak breadth)gam_df <- gam_fit_model(
otu = otu,
env = env,
env_var = "Temp",
data_type = "count", # "auto" / "count" / "relative"
count_family = "nb", # "nb" / "poisson"
use_offset = TRUE, # offset = log(library size) for count mode
min_prev = 0.10,
min_total = 100,
k_spline = 5,
n_grid = 200,
verbose = TRUE
)
head(gam_df)p <- gam_plot_species(
otu = otu,
env = env,
env_var = "Temp",
otu_id = "OTU1",
data_type = "count",
count_family = "nb",
add_ci = TRUE
)
p$plot
p$optimum_env
p$breadth50site_bw <- gam_calc_sitewidth(
otu = otu,
niche_df = gam_df,
width_col = "breadth50",
weight_mode = "auto"
)
head(site_bw)Levins breadth treats environments as discrete states and measures how evenly a taxon occupies these states.
EcoNiche supports:
lev_samples <- niche_width_calc(
otu = otu,
env = env, # optional; used for aligning samples
method = "levins", # "levins" / "shannon" / "both"
standardize = TRUE,
min_occ = 3,
min_abund = 5
)
head(lev_samples)Discretize a continuous gradient into bins, aggregate abundances within bins, then compute Levins breadth across bins.
lev_binned <- levins_calc_binned(
otu = otu,
env = env,
axis_var = "Temp",
nbin = 8,
bin_method = "equal_freq", # "equal_freq" (quantiles) or "equal_width"
agg_fun = "mean", # "mean" recommended; or "sum"
otu_mode = "auto",
min_occ = 3,
min_abund = 5
)
head(lev_binned)lev_comm <- levins_calc_group(
otu = otu,
env = env,
levins_df = lev_binned,
grad = "Temp",
width_col = "levins_Bstd",
method = "loess",
make_plot = TRUE
)
head(lev_comm$data)
lev_comm$plotpos_df <- res$species$species
pos_df$OTU <- rownames(pos_df)
pos_width <- levins_plot_pos_width(
pos_df = pos_df,
levins_df = lev_binned,
id_col = "OTU",
pos_col = "NichePosition",
width_col = "levins_Bstd",
method = "lm",
make_plot = TRUE
)
pos_width$plotlevins_calc_binned() (binned states)Sample alignment
colnames(otu) and rownames(env)
refer to the same sample IDs.Rare taxa
min_prev, min_total, and/or
min_mean.Counts vs relative abundance
use_offset=TRUE) to
account for library size.Numeric column indices
A vignette exists under vignettes/ (currently titled
“CoNiche workflow” due to legacy naming).
To build vignettes locally:
install.packages(c("knitr", "rmarkdown"))
devtools::build_vignettes()CCA / partial-CCA
cca_workflow(), cca_workflow_gradient(),
cca_workflow_group()cca_prep_env(), cca_fit_ordination()cca_calc_species(),
cca_calc_gradient()cca_calc_group(),
cca_plot_group_env()GAM
gam_fit_model(), gam_plot_species(),
gam_calc_sitewidth()Levins
niche_width_calc()levins_calc_binned(), levins_calc_group(),
levins_plot_pos_width()If you use EcoNiche in a publication, please cite the software (and include the version):
Zhou S, Feng K, Deng Y. EcoNiche: Community Niche Position and Width Estimation Tools (R package), v1.0.1. GitHub: https://github.com/yedeng-lab/EcoNiche
(Replace with a formal paper citation if/when a methods manuscript is published.)
Issues and pull requests are welcome.
When reporting bugs, please include:
sessionInfo(),otu and env,MIT License (see LICENSE / LICENSE.md).
::contentReference[oaicite:0]{index=0}
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.