| Title: | A Null Model Algorithm to Analyze Cyclical Data in Ecology |
| Version: | 0.1.0 |
| 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>. |
| License: | GPL (≥ 3) |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| Imports: | broom, magrittr, purrr, furrr, future, rlang |
| URL: | https://alrobles.github.io/rosario/ |
| Suggests: | rmarkdown, ggplot2, spelling |
| Depends: | R (≥ 4.1.0) |
| LazyData: | true |
| Language: | en-US |
| NeedsCompilation: | no |
| Packaged: | 2025-10-14 16:57:45 UTC; maria.h.m_1995 |
| Author: | Ángel L. Robles-Fernández [aut], Maria A. Hurtado-Materon [aut], Tatiana Velásquez-Roa [aut, ths], Iván Castro-Arellano [cre] |
| Maintainer: | Iván Castro-Arellano <ic13@txstate.edu> |
| Repository: | CRAN |
| Date/Publication: | 2025-10-20 19:10:02 UTC |
Pipe operator
Description
Seemagrittr::%>% for details.
Usage
lhs %>% rhsArguments
lhs | A value or the magrittr placeholder. |
rhs | A function call using the magrittr semantics. |
Value
The result of callingrhs(lhs).
Czekanowski overlap index
Description
Computes the Czekanowski index of overlap between two relative-frequencyactivity profilesp andq:
1 - \tfrac{1}{2}\sum_i |p_i - q_i|.
Usage
czekanowski_index(p, q)Arguments
p | Numeric vector of non-negative relative frequencies (typicallysums to 1) describing the first biological identity data (e.g. activity,population size, etc) across ordered time bins. Standardized use of timeintervals through the manual. |
q | Numeric vector of non-negative relative frequencies (same lengthas |
Details
Inputs should be on acomparable scale; if your data are rawcounts, rescale rows to proportions first (seerescale_matrix()).
Value
A single numeric value in [0, 1] where 0 indicates no overlap and1 indicates identical profiles.
Examples
set.seed(1)n <- 6p <- 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)Example temporal activity dataset
Description
An example dataset of 5 biological identities across 12 time intervals. Valuesrepresent counts of activity events (e.g., detections or captures) perinterval. This dataset is provided for examples and vignettes.
Usage
ex1Format
A numeric matrix with 5 rows (biological identities) and 12 columns(time intervals):
- Rows
Biological identities (
bioID1…bioID5)- Columns
Time intervals (
INT1…INT12)- Values
Counts of activity per identity × interval
Examples
ex1rowSums(ex1) # total activity per biological identitycolSums(ex1) # total activity per time intervalNull-model test via ROSARIO algorithm randomization
Description
Generates a null distribution of concurrent temporal niche overlap byrepeatedly randomizing the input matrix withrosario_sample() andrecomputing the mean pairwise overlap (seetemp_overlap()).
Usage
get_null_model(mat, method, nsim = 1000, parallel = FALSE)Arguments
mat | Numeric matrix (rows = biological identities, columns = ordered time intervals). |
method | Character string naming the overlap index to use: |
nsim | Integer number of randomizations to run (default |
parallel | Logical. If |
Details
For"czekanowski", rows are rescaled to proportions internally tosatisfy the index's assumptions. Randomization preserves each row'stemporal autocorrelation by cyclically shifting (and optionally mirroring)its profile; seerosario_sample().
Whenparallel = TRUE, the function callsfuture::plan(multisession)internally so that randomizations are distributed across available localsessions. This means the function overrides any previously setfuture plan.If you need custom control over parallelization (e.g. cluster backends),run the non-parallel mode (parallel = FALSE) and handle parallelismexternally.
Value
A list with components:
- observed_niche_overlap
Mean from all possible pairwise comparisons among biological identities for
mat.- p_value
A one-sample
t.testobject comparing null means to theobserved value (mu = observed).- null_niche_overlap
A tibble/data.frame of simulated mean overlaps(one per randomization).
See Also
temp_overlap(),rosario_sample(),temp_overlap_matrix()
Examples
get_null_model(ex1, method = "pianka", nsim = 10, parallel = FALSE)Pianka's niche-overlap index
Description
Computes Pianka's symmetric index of overlap between two non-negativeactivity profilesp andq:
\frac{\sum_i p_i q_i}{\sqrt{\left(\sum_i p_i^2\right)\left(\sum_i q_i^2\right)}}.
Usage
pianka_index(p, q)Arguments
p | Numeric vector of non-negative values (counts or relativefrequencies) 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 |
Details
Pianka's index does not require inputs to sum to 1,but both vectors must be non-negative and not all zero.
Value
A single numeric value in [0, 1]; larger values indicate greateroverlap.
Examples
set.seed(1)n <- 10p <- rpois(n, 3); q <- rpois(n, 3)pianka_index(p, q)Diagram of ROSARIO null-model randomizations
Description
Visualizes the first 10 hypothetical time use distributions produced byrosario() for a single biological identity. Each panel displays onehypothetical time use distribution with its cyclic shift shown in dark grayand its mirror image shown in dark red.
Usage
plot_rosario(numvec, normalize = TRUE, cols = 4)Arguments
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. |
Value
Invisibly, a list with:
variants— the original list fromrosario(numvec)mat2k_plotted— matrix of the plotted variants (min(10, n) × 2k)k— number of time binsindices_plotted— which variant indices (1..m) were drawn
Examples
one <- c(0,5,0,7,5,13,70,0)plot_rosario(one, cols = 4)Row-wise rescaling of a matrix to relative frequencies
Description
Divides each row by its row sum so that every row sums to 1 (leavingdimnames intact).
Usage
rescale_matrix(m)Arguments
m | Numeric matrix; rows are biological identities, columns are timebins (i.e., time resources). |
Value
A numeric matrix of the same dimension with each row summing to 1.Rows with a zero sum are left unchanged (resulting inNaN if present).
Examples
ex1_rescale <- rescale_matrix(ex1)rowSums(ex1_rescale)Generate cyclic and mirrored permutations of a time series
Description
For a numeric vector, creates the set of cyclic shifts and theirmirror images (reverse order), preserving shape but changing location alongthe cycle. The suite of vectors and mirrors represent a complete setof possible distributions.
Usage
rosario(numvec)Arguments
numvec | Numeric vector representing a single biological identity'distributions across ordered time intervals. |
Value
A list of numeric vectors with all the permutations in the time series,including the mirror patterns.
See Also
vec_permutation(),rosario_sample()
Examples
rosario(c(40, 25, 18, 10, 5, 2))ROSARIO randomization of an assemblage matrix
Description
Randomly permutes each row by a uniform cyclic shift of its columns and,with probability 0.5, reverses the order (mirror image). This kind ofpermutations preserves each biological identity's temporal autocorrelationstructure and niche breadth while randomizing location within the cycle.
Usage
rosario_sample(mat)Arguments
mat | Numeric matrix with biological identities in rows and orderedtime intervals in columns. |
Value
A numeric matrix of the same dimension asmat, randomized row-wise.
See Also
Examples
rosario_sample(ex1)Mean concurrent temporal niche overlap
Description
Computes themean of all pairwise overlaps among rows (biologicalidentities) using the chosen index.
Usage
temp_overlap(mat, method = c("pianka", "czekanowski"))Arguments
mat | Numeric matrix (rows = biological identities, columns = ordered time intervals). |
method | Overlap index to use: |
Details
For"czekanowski", rows are automatically rescaled to proportions.
Value
A single numeric value (named by the method) equal to the mean ofthe lower triangle of the pairwise overlap matrix.
See Also
temp_overlap_matrix(),get_null_model()
Examples
temp_overlap(ex1, method = "pianka")temp_overlap(rescale_matrix(ex1), method = "czekanowski")Convert a square overlap matrix to a tidy pairwise data frame
Description
Tidies a symmetric overlap (or distance) matrix into athree-column tibble/data frame with pairs and values.
Usage
temp_overlap_df(mat)Arguments
mat | Square numeric matrix (typically from |
Value
A data frame with columnsitem1,item2, anddistance(terminology followsstats::as.dist()).
Examples
d <- temp_overlap_matrix(ex1)temp_overlap_df(d)Pairwise temporal niche-overlap matrix
Description
Computes all pairwise overlaps among rows (biological identities) using the chosen index.
Usage
temp_overlap_matrix(mat, method = c("pianka", "czekanowski"))Arguments
mat | Numeric matrix (rows = biological identities, columns = ordered time intervals). |
method | Overlap index to use: |
Details
For Czekanowski, supply arow-rescaled matrix (seerescale_matrix()) or usetemp_overlap(), which handles rescaling.
Value
A square symmetric matrix of overlap values with row/colnames copiedfrommat. The first class of the object is set to the method name.
See Also
temp_overlap(),rescale_matrix()
Examples
temp_overlap_matrix(ex1, method = "pianka")ex1_rescale <- rescale_matrix(ex1)temp_overlap_matrix(ex1_rescale, method = "czekanowski")Plot null-model results for temporal niche overlap
Description
Creates a histogram of simulated mean niche overlap values from a null model(seeget_null_model()) and overlays a dashed vertical line indicating theobserved mean overlap.
Usage
temp_overlap_plot(results)Arguments
results | A list object returned by |
Value
Aggplot2 object displaying the null distribution of overlap valueswith the observed overlap marked.
See Also
get_null_model(),temp_overlap()
Examples
mod <- get_null_model(ex1, method = "pianka", nsim = 100)temp_overlap_plot(mod)Cyclic permutation (rotate) a numeric vector
Description
Returns a cyclic shift ofnumvec so that positionx becomes the firstelement and the order wraps around the end.
Usage
vec_permutation(numvec, x = 1)Arguments
numvec | Numeric vector representing an ordered cycle. |
x | Integer (1-based) index of the new starting position. |
Value
A numeric vector of the same length asnumvec, rotated so thatnumvec[x] is first.
Examples
vec_permutation(1:6, 4) # 4 5 6 1 2 3