Estimate the Rate of Change (RoC) in community composition along a temporal sequence. RoC is defined as the dissimilarity between consecutive Working Units (WUs), standardised by the age difference between them.
Usage
estimate_roc(
data_source_community,
data_source_age,
age_uncertainty = NULL,
smooth_method = c("none", "m.avg", "grim", "age.w", "shep"),
smooth_n_points = 5,
smooth_age_range = 500,
smooth_n_max = 9,
working_units = c("levels", "bins", "MW"),
bin_size = 500,
number_of_shifts = 5,
bin_selection = c("random", "first"),
standardise = FALSE,
n_individuals = 150,
dissimilarity_coefficient = c("euc", "euc.sd", "chord", "chisq", "gower", "bray"),
tranform_to_proportions = TRUE,
rand = NULL,
use_parallel = FALSE,
seed = NULL,
interest_threshold = NULL,
time_standardisation = NULL,
verbose = FALSE,
silent = FALSE
)Arguments
- data_source_community
data.frame. Community data with taxa as columns and samples as rows. The first column must be namedsample_id(character).- data_source_age
data.framewith two columns:sample_id- unique identifier of each level (character)age- age of the level (numeric)
- age_uncertainty
Optional age-uncertainty matrix from an age-depth model. Either:
A
matrixwith one column per sample and one row per age sequence drawn from a posterior age-depth model. One row is randomly selected at the start of each randomisation run. Used only whenrandis set; withrand = NULL, the single run uses the point ages.NULL(default) - age uncertainties are not used.
- smooth_method
character. Smoothing method applied to each taxon before RoC is computed."none"- no smoothing (default)"shep"- Shepard's 5-term filter (Davis, 1986; Wilkinson, 2005)"m.avg"- moving average"age.w"- age-weighted average"grim"- Grimm's smoothing (Grimm & Jacobson, 1992). The window of each sample starts with thesmooth_n_pointssamples centred on it, except that the windows of the first(smooth_n_max - 1) / 2samples start at the first sample (with the defaults, the window of sample 4 starts with samples 1 to 6). It widens by one sample on each side at a time, in at mostsmooth_n_max - smooth_n_pointssteps, while it spans less thansmooth_age_rangeyears and has at mostsmooth_n_maxsamples. Windows near the ends of the sequence can therefore stay smaller thansmooth_n_max. The window is not always centred on its sample, and neighbouring samples can end up with the same window. Their smoothed values are then identical, and the RoC between them is zero.
- smooth_n_points
numeric. Number of samples in the window of moving average and age-weighted smoothing, and in the starting window of Grimm smoothing: the sample and(smooth_n_points - 1) / 2samples on each side (for Grimm, see the exception at the start of the sequence undersmooth_method). Near the ends of the sequence, the window is cut at the first or last sample and holds fewer samples. Must be a positive, odd whole number. Shepard's filter always uses the sample and two samples on each side; for it,smooth_n_points(a whole number greater than 2) only sets how many samples at each end of the sequence are left unsmoothed:smooth_n_points / 2, rounded to the nearest whole number with halves rounded to the even number (2 for 3 to 5, 4 for 7 to 9).- smooth_age_range
numeric. Maximum age range (in years) for Grimm and age-weighted smoothing windows.- smooth_n_max
numeric. Maximum number of samples included in a Grimm smoothing window. Must be an odd whole number larger thansmooth_n_points.- working_units
character. Strategy used to define Working Units between which dissimilarity is calculated."levels"- each stratigraphical level is its own WU."bins"- one representative level is selected from each time bin of widthbin_size."MW"- moving-window binning: selective binning is repeatednumber_of_shiftstimes, shifting the window bybin_size / number_of_shiftsyears each time. All results are retained and summarised together.
- bin_size
numeric. Width of each time bin in years. Used whenworking_unitsis"bins"or"MW".- number_of_shifts
numeric. Number of window shifts in moving-window binning (working_units = "MW").- bin_selection
character. Rule for selecting one level from each bin."random"(default) - a level is selected at random."first"- the level closest to the start of the bin is selected.
- standardise
logical. IfTRUE, assemblage counts in each WU are rarefied ton_individualsbefore dissimilarity is computed.- n_individuals
numeric. Number of individuals to rarefy to whenstandardise = TRUE. Automatically reduced to the smallest count in the sequence if any WU has fewer individuals.- dissimilarity_coefficient
character. Dissimilarity coefficient used to compare consecutive WUs. Seevegan::vegdist()for details."euc"- Euclidean distance"euc.sd"- standardised Euclidean distance"chord"- Chord distance"chisq"- Chi-squared coefficient"gower"- Gower's distance"bray"- Bray-Curtis dissimilarity
- tranform_to_proportions
logical. IfTRUE(default), community data are converted to proportions before dissimilarity is computed.- rand
numeric. Number of randomisation runs. Set toNULL(default) for a single run. The single run uses the point ages (age_uncertaintyis not used), and it is deterministic unless samples are selected at random (bin_selection = "random"withworking_units = "bins"or"MW") or counts are rarefied (standardise = TRUE). With these settings or withage_uncertainty, fewer than 100 runs (includingNULL) give a warning unlesssilent = TRUE. With 100 runs or more, a warning gives the recommended number of runs when the Monte Carlo error is too large (see Details andcheck_rand()).- use_parallel
Controls parallel computation of randomisation runs.
FALSE(default) - single core only.TRUE- all cores available to the R session, as reported byparallelly::availableCores(). This respects the cores allocated to a job by an HPC scheduler (for example SLURM), container limits, and the optionmc.cores. If only one core is available, runs on a single core.A positive
numeric- use that many cores.1is the same asFALSE.
When the runs draw random numbers (random bin selection or
standardise = TRUE), each run has its own random-number stream, created before the runs start. Seeded results (see Details ofestimate_roc()) are therefore identical for any value ofuse_parallelandsilent.- seed
Seed of the random draws of the call: the age sequences drawn from
age_uncertainty, random bin selection, and rarefaction.NULL(default) - the random-number generator of the R session is used, so the results depend on its state. Callset.seed()right beforeestimate_roc()for reproducible results.A single whole
numericbetween-.Machine$integer.maxand.Machine$integer.max- all random draws of the call come from a generator seeded withseed, and the generator of the R session is left unchanged. The sameseedand settings give identical results in any R session, whatever random draws came before the call.
See Details.
- interest_threshold
numeric. Optional. Samples older than this age are excluded from the output.- time_standardisation
numeric. Time unit for RoC values. RoC is reported as dissimilarity pertime_standardisationyears. Defaults tobin_sizewhenNULL.- verbose
logical. IfTRUE, print progress messages during computation.- silent
logical. IfTRUE, suppress all console output (overridesverbose).
Value
A tibble with one row per Working Unit (WU) pair, sorted by age, with
columns:
Working_Unit- label of the WU pairAge- median age of the WU pair across randomisation runsROC- median RoC score across randomisation runsROC_up- 97.5 % quantile of RoC across randomisation runs, the upper bound of the 95 % intervalROC_dw- 2.5 % quantile of RoC across randomisation runs, the lower bound of the 95 % intervaln_runs- number of randomisation runs with a RoC value for the WU pairROC_mc_error,ROC_up_mc_error,ROC_dw_mc_error- Monte Carlo standard errors ofROC,ROC_up, andROC_dw: how much these values vary between calls with different seeds.NAwhen there are too few runs to estimate them, for example withrand = NULL. Estimates from fewer than 100 runs are unreliable (seecheck_rand()).
Details
RoC between two consecutive WUs is computed as dissimilarity divided
by the age difference between the WUs, scaled by
time_standardisation. When rand > 1, the full computation is
repeated rand times; in each run, one age sequence is drawn at
random from age_uncertainty (if supplied) and, when
standardise = TRUE, assemblage counts are independently rarefied.
The final RoC value for each WU pair is the median across all runs;
the 2.5 % and 97.5 % quantiles are returned as the bounds of a 95 %
interval.
With a finite number of runs, these summaries have Monte Carlo error,
which falls with the square root of the number of runs. It is
estimated for each WU pair as the exact bootstrap standard error of the
order statistic nearest to each summary (Maritz and Jarrett, 1978),
which is computed without resampling and draws no random numbers. With
100 runs or more and silent = FALSE, a warning gives the recommended
number of runs when the error exceeds 10 % of the width of the 95 %
interval in at least 10 % of the assessed WU pairs. Use check_rand()
for details and other tolerances.
Results are reproducible in two ways. With seed, a call gives the same
results whatever random draws came before it in the R session, and it
leaves the generator of the session unchanged. It draws with R's default
generator ("Mersenne-Twister" with the "Inversion" normal kind and
the "Rejection" sample kind), whatever kind the session uses, so
seed = x gives the same results as set.seed(x) followed by a call
with seed = NULL in a session with the default generator. With
seed = NULL, set.seed() right before the call also gives
reproducible results, but any random draw in between, for example an
earlier call of estimate_roc() in a loop over records, changes them,
and the call advances the generator of the session when it draws random
numbers.
Progress bar
With silent = FALSE, the randomisation runs show the progress bar set
by pbapply::pboptions(): by default a timer bar in interactive
sessions and no bar otherwise (for example with Rscript, in
R CMD check, or when rendering documents). A type chosen with
pbapply::pboptions(type = ...) is used as it is. verbose does not
affect the bar. With silent = TRUE, no bar is shown, and the
progress-bar setting of the session is restored after the call.
References
Birks, H.J.B., Gordon, A.D., 1985. Numerical Methods in Quaternary Pollen Analysis. Academic Press, London.
Davis, J.C., 1986. Statistics and Data Analysis in Geology, 2nd edn. J. Wiley & Sons, New York.
Grimm, E.C., Jacobson, G.L., 1992. Fossil-pollen evidence for abrupt climate changes during the past 18000 years in eastern North America. Clim. Dyn. 6, 179-184.
Maritz, J. S., Jarrett, R. G., 1978. A note on estimating the variance of the sample median. Journal of the American Statistical Association 73, 194-196. doi:10.1080/01621459.1978.10480027
Wilkinson, L., 2005. The Grammar of Graphics. Springer-Verlag, New York.
Examples
# \donttest{
data("example_data", package = "RRatepol")
# Pollen counts, level ages, and age uncertainties of the first sequence
data_pollen <-
purrr::chuck(example_data, "pollen_data", 1)
data_age <-
purrr::chuck(example_data, "sample_age", 1)
mat_age_uncertainty <-
purrr::chuck(example_data, "age_uncertainty", 1)
# Basic use -----
# Each level is a Working Unit (WU), no smoothing, and a single run.
# The result has one row per pair of neighbouring WUs.
data_roc_levels <-
estimate_roc(
data_source_community = data_pollen,
data_source_age = data_age,
dissimilarity_coefficient = "chisq"
)
#>
#> ── RRatepol started 2026-12-04 19:03:18 ────────────────────────────────────────
#> ℹ Working Units: individual levels.
#> ℹ Time standardisation: RoC is reported as dissimilarity per 500 years.
#> ✔ RRatepol finished 2026-12-04 19:03:18 [0.28 secs]
data_roc_levels
#> # A tibble: 62 × 9
#> Working_Unit Age ROC ROC_up ROC_dw n_runs ROC_mc_error ROC_up_mc_error
#> <chr> <dbl> <dbl> <dbl> <dbl> <int> <dbl> <dbl>
#> 1 392671-392672 -21 1.22 1.22 1.22 1 NA NA
#> 2 392672-392673 129 0.857 0.857 0.857 1 NA NA
#> 3 392673-392674 258. 1.41 1.41 1.41 1 NA NA
#> 4 392674-392675 378 1.13 1.13 1.13 1 NA NA
#> 5 392675-392676 506. 1.83 1.83 1.83 1 NA NA
#> 6 392676-392677 630. 1.95 1.95 1.95 1 NA NA
#> 7 392677-392678 753 1.42 1.42 1.42 1 NA NA
#> 8 392678-392679 877 1.66 1.66 1.66 1 NA NA
#> 9 392679-392680 1008 1.52 1.52 1.52 1 NA NA
#> 10 392680-392681 1136. 1.06 1.06 1.06 1 NA NA
#> # ℹ 52 more rows
#> # ℹ 1 more variable: ROC_dw_mc_error <dbl>
plot_roc(data_source = data_roc_levels)
# Detailed progress messages (`verbose`) or none at all (`silent`)
data_roc_verbose <-
estimate_roc(
data_source_community = data_pollen,
data_source_age = data_age,
verbose = TRUE
)
#>
#> ── RRatepol started 2026-12-04 19:03:18 ────────────────────────────────────────
#> ℹ Working Units: individual levels.
#> ℹ Time standardisation: RoC is reported as dissimilarity per 500 years.
#>
#> ── Data extraction ──
#>
#> ℹ Community data: 63 samples and 47 taxa.
#> ℹ Age data: 63 samples.
#> ℹ Age uncertainty: not provided.
#> ℹ Missing values: 0 in the community data and 0 in the age data.
#> ℹ Sample totals in the community data: minimum 362, maximum 691, mean 506, and
#> median 505.
#> ℹ Ages: minimum -21, maximum 8402, mean 4426, and median 4628.
#> ✔ Data extraction finished.
#> ℹ Community data: 63 samples and 47 taxa.
#> ℹ Age data: 63 samples.
#> ℹ Age uncertainty: not provided.
#> ℹ Missing values: 0 in the community data and 0 in the age data.
#> ℹ Sample totals in the community data: minimum 362, maximum 691, mean 506, and
#> median 505.
#> ℹ Ages: minimum -21, maximum 8402, mean 4426, and median 4628.
#>
#> ── Estimation ──
#>
#> ℹ Number of estimations (runs times window shifts): 1.
#> ℹ Converting the community data to proportions.
#> ℹ Dissimilarity coefficient: Euclidean distance.
#> ✔ RRatepol finished 2026-12-04 19:03:19 [0.38 secs]
data_roc_silent <-
estimate_roc(
data_source_community = data_pollen,
data_source_age = data_age,
silent = TRUE
)
# Smoothing -----
# Shepard's 5-term filter
data_roc_smooth_shep <-
estimate_roc(
data_source_community = data_pollen,
data_source_age = data_age,
smooth_method = "shep",
silent = TRUE
)
# Moving average of 3 levels
data_roc_smooth_m_avg <-
estimate_roc(
data_source_community = data_pollen,
data_source_age = data_age,
smooth_method = "m.avg",
smooth_n_points = 3,
silent = TRUE
)
# Age-weighted average of 5 levels within 500 years
data_roc_smooth_age_w <-
estimate_roc(
data_source_community = data_pollen,
data_source_age = data_age,
smooth_method = "age.w",
smooth_n_points = 5,
smooth_age_range = 500,
silent = TRUE
)
# Grimm's smoothing: windows of 3 to 9 levels spanning up to 500 years
data_roc_smooth_grim <-
estimate_roc(
data_source_community = data_pollen,
data_source_age = data_age,
smooth_method = "grim",
smooth_n_points = 3,
smooth_n_max = 9,
smooth_age_range = 500,
silent = TRUE
)
# Dissimilarity coefficients -----
# All coefficients, each on proportions (the default)
list_roc_coefficients <-
c("euc", "euc.sd", "chord", "chisq", "gower", "bray") %>%
purrr::set_names() %>%
purrr::map(
.f = ~ estimate_roc(
data_source_community = data_pollen,
data_source_age = data_age,
dissimilarity_coefficient = .x,
silent = TRUE
)
)
# Euclidean distance on the raw counts
data_roc_counts <-
estimate_roc(
data_source_community = data_pollen,
data_source_age = data_age,
dissimilarity_coefficient = "euc",
tranform_to_proportions = FALSE,
silent = TRUE
)
# Binning -----
# One level per 500-year bin, the level closest to the start of the bin
data_roc_bins <-
estimate_roc(
data_source_community = data_pollen,
data_source_age = data_age,
working_units = "bins",
bin_size = 500,
bin_selection = "first",
silent = TRUE
)
# Moving-window binning: 500-year bins shifted 5 times by 100 years.
# Selecting the first level in each bin keeps a single run
# deterministic.
data_roc_moving_window <-
estimate_roc(
data_source_community = data_pollen,
data_source_age = data_age,
working_units = "MW",
bin_size = 500,
number_of_shifts = 5,
bin_selection = "first",
silent = TRUE
)
# Output settings -----
# RoC per 1000 years, and only WUs younger than 8000 cal yr BP
data_roc_output <-
estimate_roc(
data_source_community = data_pollen,
data_source_age = data_age,
interest_threshold = 8000,
time_standardisation = 1000,
silent = TRUE
)
# Randomisation -----
# Age uncertainty, smoothing, one level selected at random in each
# 500-year bin, and rarefaction to 150 pollen grains. Each of the 100
# runs draws a new age sequence, selection of levels, and rarefied
# sample, here on 2 cores.
# `seed` makes the results reproducible in any R session; calling
# `set.seed(900723)` right before a call without `seed` works too.
# 100 runs are only a pilot, so a warning recommends more runs;
# `check_rand()` gives the number of runs for a real analysis.
data_roc_randomised <-
estimate_roc(
data_source_community = data_pollen,
data_source_age = data_age,
age_uncertainty = mat_age_uncertainty,
smooth_method = "shep",
working_units = "bins",
bin_size = 500,
bin_selection = "random",
standardise = TRUE,
n_individuals = 150,
dissimilarity_coefficient = "chisq",
rand = 100,
use_parallel = 2,
seed = 900723
)
#>
#> ── RRatepol started 2026-12-04 19:03:23 ────────────────────────────────────────
#> ℹ Age uncertainty: each run uses one age sequence drawn from `age_uncertainty`.
#> ℹ Working Units: selective binning with 500-year bins.
#> ℹ Bin selection: one sample at random in each bin.
#> ℹ Time standardisation: RoC is reported as dissimilarity per 500 years.
#> ℹ Standardisation: each Working Unit is rarefied to 150 individuals, or to the
#> smallest count in the data if that is lower.
#> Warning: ! The Monte Carlo error of the RoC estimates exceeds 10 % of the 95 % interval
#> width in at least 10 % of the assessed Working Units.
#> ℹ About 200 randomisation runs (`rand`) are recommended; see `check_rand()`.
#> ✔ RRatepol finished 2026-12-04 19:03:26 [2.46 secs]
# `ROC_up` and `ROC_dw` give the 95 % interval across runs
plot_roc(
data_source = data_roc_randomised,
age_threshold = 8000
)
# }
