| Title: | A Null Model Algorithm to Analyze Cyclical Data in Ecology |
|---|---|
| Description: | Implements a null model analysis to quantify concurrent temporal niche overlap (i.e., activity or phenology) among biological identities (e.g., individuals, populations, species) using the Rosario randomization algorithm (Castro-Arellano et al. 2010) <doi:10.1111/j.2041-210X.2010.00031.x>. |
| Authors: | Ángel L. Robles-Fernández [aut], Maria A. Hurtado-Materon [aut], Tatiana Velásquez-Roa [cre, aut], Iván Castro-Arellano [ths] |
| Maintainer: | Tatiana Velásquez-Roa <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.1.1 |
| Built: | 2026-05-22 07:54:56 UTC |
| Source: | https://github.com/alrobles/rosario |
Computes the Czekanowski index of overlap between two relative-frequency
activity profiles and :
czekanowski_index(p, q)czekanowski_index(p, q)
p |
Numeric vector of non-negative relative frequencies (typically sums to 1) describing the first biological identity data (e.g. activity, population size, etc) across ordered time bins. Standardized use of time intervals through the manual. |
q |
Numeric vector of non-negative relative frequencies (same length
as |
Inputs should be on a comparable scale; if your data are raw
counts, rescale rows to proportions first (see rescale_matrix()).
A single numeric value in [0, 1] where 0 indicates no overlap and 1 indicates identical profiles.
set.seed(1) n <- 6 p <- rmultinom(1, 20, rep(1, n))[,1]; p <- p / sum(p) q <- rmultinom(1, 20, rep(1, n))[,1]; q <- q / sum(q) czekanowski_index(p, q)set.seed(1) n <- 6 p <- rmultinom(1, 20, rep(1, n))[,1]; p <- p / sum(p) q <- rmultinom(1, 20, rep(1, n))[,1]; q <- q / sum(q) czekanowski_index(p, q)
An example dataset of 5 biological identities across 12 time intervals. Values represent counts of activity events (e.g., detections or captures) per interval. This dataset is provided for examples and vignettes.
ex1ex1
A numeric matrix with 5 rows (biological identities) and 12 columns (time intervals):
Biological identities (bioID1 … bioID5)
Time intervals (INT1 … INT12)
Counts of activity per identity × interval
ex1 rowSums(ex1) # total activity per biological identity colSums(ex1) # total activity per time intervalex1 rowSums(ex1) # total activity per biological identity colSums(ex1) # total activity per time interval
Generates a null distribution of concurrent temporal niche overlap by
repeatedly randomizing the input matrix with rosario_sample() and
recomputing the mean pairwise overlap (see temp_overlap()).
get_null_model(mat, method, nsim = 100, parallel = FALSE)get_null_model(mat, method, nsim = 100, parallel = FALSE)
mat |
Numeric matrix (rows = biological identities, columns = ordered time intervals). Time intervals are assumed to be circular (e.g., hours of the day, months of the year), so the last interval is treated as adjacent to the first. Biological identities can be individuals, populations, species or communities. |
method |
Character string naming the overlap index to use:
|
nsim |
Integer number of randomizations to run (default |
parallel |
Logical. If |
For "czekanowski", rows are rescaled to proportions internally to
satisfy the index's assumptions. Randomization preserves each row's
temporal autocorrelation by cyclically shifting (and optionally mirroring)
its profile; see rosario_sample().
When parallel = TRUE, the function calls future::plan(multisession)
internally so that randomizations are distributed across available local
sessions. This means the function overrides any previously set future plan.
If you need custom control over parallelization (e.g. cluster backends),
run the non-parallel mode (parallel = FALSE) and handle parallelism
externally.
A list with components:
Mean from all possible pairwise comparisons among biological identities for mat.
A one-sample t.test object comparing null means to the
observed value (mu = observed).
A tibble/data.frame of simulated mean overlaps (one per randomization).
temp_overlap(), rosario_sample(), temp_overlap_matrix()
get_null_model(ex1, method = "pianka", nsim = 10, parallel = FALSE)get_null_model(ex1, method = "pianka", nsim = 10, parallel = FALSE)
Computes Pianka's symmetric index of overlap between two non-negative
activity profiles and :
pianka_index(p, q)pianka_index(p, q)
p |
Numeric vector of non-negative values (counts or relative frequencies) for the first biological identity data 1 (e.g. activity, population size, etc) across ordered time bins. |
q |
Numeric vector of non-negative values (same length as |
Pianka's index does not require inputs to sum to 1, but both vectors must be non-negative and not all zero.
A single numeric value in [0, 1]; larger values indicate greater overlap.
set.seed(1) n <- 10 p <- rpois(n, 3); q <- rpois(n, 3) pianka_index(p, q)set.seed(1) n <- 10 p <- rpois(n, 3); q <- rpois(n, 3) pianka_index(p, q)
Visualizes the first 10 hypothetical time use distributions produced by
rosario() for a single biological identity. Each panel displays one
hypothetical time use distribution with its cyclic shift shown in dark gray
and its mirror image shown in dark red.
plot_rosario(numvec, normalize = TRUE, cols = 4)plot_rosario(numvec, normalize = TRUE, cols = 4)
numvec |
Numeric vector representing a single biological identity' distribution across ordered time intervals. |
normalize |
Logical; if TRUE (default) scale each half to sum to 1 (compare shapes, not totals). |
cols |
Integer; number of panels (hypothetical distributions) per row. |
Invisibly, a list with:
variants — the original list from rosario(numvec)
mat2k_plotted — matrix of the plotted variants (min(10, n) × 2k)
k — number of time bins
indices_plotted — which variant indices (1..m) were drawn
one <- c(0,5,0,7,5,13,70,0) plot_rosario(one, cols = 4)one <- c(0,5,0,7,5,13,70,0) plot_rosario(one, cols = 4)
Divides each row by its row sum so that every row sums to 1 (leaving dimnames intact).
rescale_matrix(m)rescale_matrix(m)
m |
Numeric matrix; rows are biological identities, columns are time bins (i.e., time resources). |
A numeric matrix of the same dimension with each row summing to 1.
Rows with a zero sum are left unchanged (resulting in NaN if present).
ex1_rescale <- rescale_matrix(ex1) rowSums(ex1_rescale)ex1_rescale <- rescale_matrix(ex1) rowSums(ex1_rescale)
For a numeric vector, creates the set of cyclic shifts and their mirror images (reverse order), preserving shape but changing location along the cycle. The suite of vectors and mirrors represent a complete set of possible distributions.
rosario(numvec)rosario(numvec)
numvec |
Numeric vector representing a single biological identity' distributions across ordered time intervals. Time intervals are assumed to be circular (e.g., hours of the day, months of the year), so the last interval is treated as adjacent to the first. Biological identities can be individuals, populations, species or communities. |
A list of numeric vectors with all the permutations in the time series, including the mirror patterns.
vec_permutation(), rosario_sample()
rosario(c(40, 25, 18, 10, 5, 2))rosario(c(40, 25, 18, 10, 5, 2))
Randomly permutes each row by a uniform cyclic shift of its columns and, with probability 0.5, reverses the order (mirror image). This kind of permutations preserves each biological identity's temporal autocorrelation structure and niche breadth while randomizing location within the cycle.
rosario_sample(mat)rosario_sample(mat)
mat |
Numeric matrix with biological identities in rows and ordered time intervals in columns. |
A numeric matrix of the same dimension as mat, randomized row-wise.
rosario_sample(ex1)rosario_sample(ex1)
Assemblage-wide temporal niche segregation
temp_overlap(mat, method = c("pianka", "czekanowski"))temp_overlap(mat, method = c("pianka", "czekanowski"))
mat |
A matrix with species per time columns. |
method |
A measure of temporal niche overlap between pairs of species |
The mean temporal overlaping index from a pairwise distance matrix
temp_overlap(ex1, method = "pianka") ex1_rescale <- rescale_matrix(ex1) temp_overlap(ex1_rescale, method = "czekanowski")temp_overlap(ex1, method = "pianka") ex1_rescale <- rescale_matrix(ex1) temp_overlap(ex1_rescale, method = "czekanowski")
Tidies a symmetric overlap (or distance) matrix into a three-column tibble/data frame with pairs and values.
temp_overlap_df(mat)temp_overlap_df(mat)
mat |
Square numeric matrix (typically from |
A data frame with columns item1, item2, and distance
(terminology follows stats::as.dist()).
d <- temp_overlap_matrix(ex1) temp_overlap_df(d)d <- temp_overlap_matrix(ex1) temp_overlap_df(d)
Computes all pairwise overlaps among rows (biological identities) using the chosen index.
temp_overlap_matrix(mat, method = c("pianka", "czekanowski"))temp_overlap_matrix(mat, method = c("pianka", "czekanowski"))
mat |
Numeric matrix (rows = biological identities, columns = ordered time intervals). |
method |
Overlap index to use: |
For Czekanowski, supply a row-rescaled matrix (see
rescale_matrix()) or use temp_overlap(), which handles rescaling.
A square symmetric matrix of overlap values with row/colnames copied
from mat. The first class of the object is set to the method name.
temp_overlap(), rescale_matrix()
temp_overlap_matrix(ex1, method = "pianka") ex1_rescale <- rescale_matrix(ex1) temp_overlap_matrix(ex1_rescale, method = "czekanowski")temp_overlap_matrix(ex1, method = "pianka") ex1_rescale <- rescale_matrix(ex1) temp_overlap_matrix(ex1_rescale, method = "czekanowski")
Creates a histogram of simulated mean niche overlap values from a null model
(see get_null_model()) and overlays a dashed vertical line indicating the
observed mean overlap.
temp_overlap_plot(results)temp_overlap_plot(results)
results |
A list object returned by |
A ggplot2 object displaying the null distribution of overlap values
with the observed overlap marked.
get_null_model(), temp_overlap()
mod <- get_null_model(ex1, method = "pianka", nsim = 100) temp_overlap_plot(mod)mod <- get_null_model(ex1, method = "pianka", nsim = 100) temp_overlap_plot(mod)
Returns a cyclic shift of numvec so that position x becomes the first
element and the order wraps around the end.
vec_permutation(numvec, x = 1)vec_permutation(numvec, x = 1)
numvec |
Numeric vector representing an ordered cycle. |
x |
Integer (1-based) index of the new starting position. |
A numeric vector of the same length as numvec, rotated so that
numvec[x] is first.
vec_permutation(1:6, 4) # 4 5 6 1 2 3vec_permutation(1:6, 4) # 4 5 6 1 2 3