| Title: | Synchronicity Testing for Event Records |
| Version: | 1.0.0 |
| Description: | Evaluation of synchronous deposition across different event records using a log-ratio approach, and syncing age-depth models based on the availability of isochrons. Following the methodology of Wils & Ramisch (2026) <doi:10.1038/s41598-026-67943-7>. The synthetic example dataset used in the examples, tests and vignette is distributed separately in the companion data package 'SyncERdata'. |
| License: | GPL (≥ 3) |
| URL: | https://github.com/katleenwils/SyncER |
| BugReports: | https://github.com/katleenwils/SyncER/issues |
| Depends: | R (≥ 3.5.0) |
| Encoding: | UTF-8 |
| Imports: | dplyr, magrittr, stringr, readr, ggplot2, pracma |
| Suggests: | knitr, rmarkdown, rbacon, rplum, SyncERdata (≥ 1.0.0), testthat (≥ 3.0.0) |
| Config/testthat/edition: | 3 |
| Config/roxygen2/version: | 8.0.0 |
| VignetteBuilder: | knitr |
| NeedsCompilation: | no |
| Packaged: | 2026-09-28 22:44:03 UTC; wilska |
| Author: | Katleen Wils [aut, cre] |
| Maintainer: | Katleen Wils <katleen.wils@ugent.be> |
| Repository: | CRAN |
| Date/Publication: | 2026-10-08 17:40:11 UTC |
SyncER: Synchronicity Testing for Event Records
Description
Evaluation of synchronous deposition across different event records using a log-ratio approach, and syncing age-depth models based on the availability of isochrons. Following the methodology of Wils & Ramisch (2026) doi:10.1038/s41598-026-67943-7. The synthetic example dataset used in the examples, tests and vignette is distributed separately in the companion data package 'SyncERdata'.
Author(s)
Maintainer: Katleen Wils katleen.wils@ugent.be
Authors:
Katleen Wils katleen.wils@ugent.be
See Also
Useful links:
Add synchronized ages to age data
Description
For each horizon in adjusted_ages, overwrites the matching event row's
age / error / cc in frame with the synchronized value. Ages carry the
generation they were computed from in their record field (e.g.
"core1_synced"), while record_key may be a later generation (e.g.
"core1_synced_1"); they are matched when record_key equals, or is
a child (<record>_...) of, an age's record. Records/horizons not
found are left untouched.
Usage
add_adjusted_ages(frame, record_key, adjusted_ages)
Arguments
frame |
Data frame for a single record (rbacon/rplum-style, with an |
record_key |
Character key identifying the record generation |
adjusted_ages |
Named list of synchronized-age data frames, as returned by
|
Value
frame with matching event rows overwritten by the synchronized
ages.
Write input files for age-depth modelling and return the updated record metadata
Description
Single entry point for turning record metadata into rbacon/rplum-ready CSV input files. It
treats record_data as the initial input data: any new synchronized ages are included and
the CSV(s) are rebuilt. The updated record_data (re-keyed to the folder
generation that was written) is returned.
Usage
age_model_input(
record_data,
adjusted_ages = NULL,
update_records = FALSE,
radiocarbon_sample_names = "sample",
lead_sample_names = "210Pb_sample",
original_ages = TRUE,
base_dir = syncer_base_dir(),
verbose = TRUE
)
Arguments
record_data |
Named list of record metadata (output from |
adjusted_ages |
Optional output from |
update_records |
Logical; when |
radiocarbon_sample_names |
Character vector of the event label(s) used for your
radiocarbon samples in the input file (default: |
lead_sample_names |
Character vector of the event label(s) used for your Pb-210 (lead)
samples (default: |
original_ages |
Logical or named logical vector indicating whether the new age-depth
models should also use the original ages alongside the synchronized ages
(default: |
base_dir |
Character string specifying the output directory (default:
|
verbose |
Logical; if |
Value
Invisibly, a named list with the same structure as record_data: the record
frames with the new synchronized ages baked in, keyed by the folder generation that was
written (unchanged keys when update_records = TRUE). Assign it and pass it to the
next age_model_input() call.
Asses log-ratio value distribution for normality and centering to allow for synchronicity precision calculation
Description
Tests whether a log-ratio vector has a normal shape (via shape_ok()) and
is sufficiently centred (mean within half a standard deviation of zero). Both
conditions must hold for the precision estimate derived from the distribution to
be trustworthy.
Usage
assess_lr(ABlr)
Arguments
ABlr |
Numeric vector of log-ratio values. |
Value
Named list with elements:
-
ok: Logical;TRUEwhen both shape and centring criteria pass. -
lr_mean: Mean ofABlr(NAs removed). -
lr_sd: Standard deviation ofABlr(NAs removed).
Assign ages to non-synchronous horizons to use as older/younger than inputs
Description
Assigns a reference age to test horizons that were excluded from secondary synchronization so
they can be used as "older than"/"younger than" constraints in the age-depth
model. Each excluded horizon receives the synchronized age of the horizon
group it belongs to: e.g. an excluded "synchro-test-wrong" layer
takes the age computed for its group "synchro-test". The member-to-group
mapping comes from horizon_groups (as passed to synchronize_ages()).
Exclusions are parsed with the same logic as
synchronize_ages() (named for per-record, unnamed for global).
Usage
assign_nonsynchro_age(
adjusted_ages,
nonsynchro_horizons,
event_stats,
horizon_groups = NULL,
verbose = TRUE
)
Arguments
adjusted_ages |
Output from |
nonsynchro_horizons |
Named or unnamed character vector specifying non-synchronized horizons
(same format as in |
event_stats |
Output from |
horizon_groups |
Named list mapping each horizon group to its member labels, as
passed to |
verbose |
Logical; if |
Details
If an excluded horizon has no synchronized age for its group (it was excluded
altogether, so no group age was ever computed), it is skipped with a warning;
compute an age for it separately with synchronize_ages() using the method of
your choice ("mean", "ageofrecord", "Bayesian", ...).
Value
Named list with one element per excluded horizon, each containing a data frame
with columns: record, adjusted_age, adjusted_error.
Bayesian combination of age probabilty density functions
Description
Combines multiple posterior age distributions using Bayesian product of probability density functions. Uses kernel density estimation to construct PDFs from samples, multiplies densities in log-space to avoid underflow, normalizes using trapezoidal integration, and calculates moment-matched statistics. This is the recommended method for combining ages from multiple records with overlapping distributions.
Usage
bayesian_age_combination(
samples_list,
return_full_pdf = FALSE,
n_grid = 2000,
bw = "nrd0"
)
Arguments
samples_list |
List of numeric vectors containing posterior samples from different records. |
return_full_pdf |
Logical indicating whether to return the full combined PDF (default: FALSE). |
n_grid |
Integer specifying number of grid points for kernel density estimation (default: 2000). |
bw |
Character string or numeric value specifying bandwidth method for KDE (default: "nrd0"). |
Value
List containing:
-
mean: Numeric mean of the combined distribution -
sd: Numeric standard deviation of the combined distribution -
pdf: (ifreturn_full_pdf = TRUE) List withx(grid points) andpdf(density values)
Determine current BP datum (year - 1950)
Description
Returns the number of years elapsed since the radiocarbon BP datum (1950),
calculated from the current system date. Used as the default offset/
age_offset argument throughout SyncER to avoid negative age values.
Usage
bp_datum()
Value
Integer: current year minus 1950.
Build input data structures compatible with Bacon and Plum age-depth modelling
Description
Prepares radiocarbon and Pb210 data frames in the format required by the rbacon/rplum age-depth modelling software.
Usage
build_age_input(
record_data,
record_name,
radiocarbon_sample_names = "sample",
lead_sample_names = "210Pb_sample",
adjusted_ages = NULL,
original_ages = TRUE
)
Arguments
record_data |
A data frame containing record data with at least columns: |
record_name |
Character string used to identify the record. |
radiocarbon_sample_names |
Character vector of the event label(s) given to the
radiocarbon samples you want to include (default: |
lead_sample_names |
Character vector of the event label(s) given to the Pb-210 (lead)
samples you want to include (default: |
adjusted_ages |
Optional list output from |
original_ages |
Logical or named logical vector indicating whether to include original
radiocarbon ages when |
Value
A named list with elements:
-
c14: Data frame formatted for rbacon C14 input -
pb210: Data frame formatted for rplum containing Pb210 and C14 input, orNULLif no Pb210 data is present
Build Group Lookup from Horizon Groups
Description
Constructs a named character vector mapping each individual horizon name to
its group name, based on the horizon_groups list supplied by the user.
Usage
build_group_lookup(horizon_groups)
Arguments
horizon_groups |
Named list as passed to |
Value
Named character vector (group_of) where each element name is a
horizon name and each value is the corresponding group name, or NULL
when horizon_groups is NULL.
Compute a log-ratio values for a single pair-wise comparison
Description
Core computation for one record pair within compute_synchronicity_values().
Draws n_samples log-ratios, scores them against the age-difference bounds,
assesses distribution shape, estimates precision, and assembles the statistics and
visualization rows.
Usage
compare_pair(
col1,
col2,
rec_i,
rec_j,
var_i = NULL,
var_j = NULL,
horizon,
thresholds,
summaries,
n_samples = 10000
)
Arguments
col1 |
Numeric vector of posterior age samples for record |
col2 |
Numeric vector of posterior age samples for record |
rec_i |
Character string identifying record i. |
rec_j |
Character string identifying record j. |
var_i |
Column name used from record i. Pass |
var_j |
Column name used from record j. Same semantics as |
horizon |
Character string identifying the event/horizon being compared. |
thresholds |
Named list as returned by |
summaries |
Named list of per-record summary data frames from
|
n_samples |
Integer; number of Monte Carlo samples (default: 10000). |
Value
Named list with elements lr_name, variant_key, ABlr,
score, precision, stats_row, viz_row.
Interpolate event ages from MCMC runs of Raw Bacon/Plum output files
Description
Performs all age interpolation and computation logic from raw rbacon/rplum .out file content.
Usage
compute_event_ages(
raw_out_data,
record_data,
event_types,
max_depths,
isochrons,
test_horizons,
instantaneous_event_depths = NULL,
thick = NULL,
synced = ""
)
Arguments
raw_out_data |
Named list of character vectors (raw lines from each .out file), one element per record folder. |
record_data |
Named list of data frames representing each record's metadata
(output from |
event_types |
Character vector of all event type names present in your dataset. |
max_depths |
Named vector containing the depths to which the age models are calculated for each record. |
isochrons |
Character vector of deposit names that are known to be synchronous. |
test_horizons |
Character vector of event deposits for which synchronicity should be tested. |
instantaneous_event_depths |
Optional named list of depth intervals classified as instantaneous deposits per record that should not be considered for event-free depths. |
thick |
The rbacon/rplum section thickness; single numeric, named list per record, or NULL
(default), in which case it is derived per record from the model as
|
synced |
Character string suffix to identify synchronized folders (default: ""). |
Value
Named list of data frames, one per processed record folder, containing depth columns plus one column per event with interpolated ages.
Calculate synchronicity validation thresholds based on isochron ages and errors
Description
Calculates empirically-based validation thresholds and confidence levels from synchronized
age data for use in subsequent synchronicity testing. Calculates the coefficient of variation (CV = sigma/mu) from synchronized ages,
multiplies by user-specified sigma values to generate age difference thresholds, and
converts sigma values to confidence levels using the standard normal distribution.
The age offset is added before calculating CV to ensure consistency accross calculations.
These thresholds can be directly used in verify_synchronicity() for synchronicity testing.
Usage
compute_isochron_thresholds(
adjusted_ages,
sigma_multiplier = 2,
age_offset = bp_datum()
)
Arguments
adjusted_ages |
Output from |
sigma_multiplier |
Numeric value or named vector giving the user-defined confidence
level on the age interval, expressed as a standard-deviation multiplier (default: |
age_offset |
Numeric offset value that was added to ages to avoid negative values
(default: |
Value
Named list containing:
-
validation_thresholds: Named numeric vector of age difference thresholds (as proportions) -
confidence_levels: Named numeric vector of corresponding confidence levels (as proportions) -
sigma_values: Named numeric vector of sigma multipliers used per horizon -
empirical_cv: Named numeric vector of empirical coefficients of variation -
age_offset: The age offset value used during threshold calculation
Examples
if (requireNamespace("SyncERdata", quietly = TRUE)) {
# Set-up: synchronized ages from the example data of the companion package SyncERdata
isochrons <- paste0("isochron", 1:7)
event_stats <- process_event_ages(SyncERdata::out_data_ages_synced, isochrons)
adjusted_ages <- synchronize_ages(event_stats, horizons = isochrons, verbose = FALSE)
# Single sigma for all horizons
thresholds <- compute_isochron_thresholds(adjusted_ages, sigma_multiplier = 2)
# Different sigma per horizon
thresholds <- compute_isochron_thresholds(
adjusted_ages,
sigma_multiplier = c(horizon1 = 2, horizon2 = 1, horizon3 = 1.5)
)
# With custom age offset
thresholds <- compute_isochron_thresholds(
adjusted_ages,
sigma_multiplier = 2,
age_offset = 100
)
# Use in verify_synchronicity (its first argument is the result of
# compute_synchronicity_values(); the thresholds are passed to that function)
synchro <- compute_synchronicity_values(
event_stats,
event_names = names(thresholds$validation_thresholds),
confidence_level = thresholds$confidence_levels,
age_difference = thresholds$validation_thresholds
)
verify_synchronicity(
synchro,
event_names = names(thresholds$validation_thresholds)
)
}
Calculate minimal synchronicity precision value in log-space
Description
Returns the smallest absolute log-ratio value t such that at least
conf_level of ABlr values fall within [-t, t].
Usage
compute_minimal_precision_threshold(ABlr, conf_level)
Arguments
ABlr |
Numeric vector of log-ratio values. |
conf_level |
Numeric confidence level (e.g., 0.95). |
Value
Numeric threshold, or NA if ABlr is empty or the
desired coverage cannot be achieved.
Calculate overall synchronicity score using additive log-ratios
Description
Calculates overall synchronicity scores (i.e. the probability that all horizons are simultaneously synchronous) across multiple records using additive log-ratio (ALR) transformation. Uses the first record alphabetically as reference. The reference record's Monte Carlo resample is drawn once and shared across every non-reference column, since all comparisons are against the same single (uncertain) reference record; each non-reference record is independently resampled, reflecting that their age models are unrelated.
Usage
compute_overall_synchronicity(
samples_list,
conf_level,
age_diff_log_bounds,
n_samples = 10000,
seed = 5128
)
Arguments
samples_list |
Named list of numeric vectors containing posterior age samples, one per record. |
conf_level |
Numeric value specifying the confidence level for the test (e.g., 0.95). |
age_diff_log_bounds |
Two-element numeric vector with log-space age difference bounds. |
n_samples |
Integer number of Monte Carlo draws per record (default: 10000). |
seed |
Integer random seed for reproducibility (default: 5128). |
Value
Named list containing:
-
overall_score: Numeric value representing the proportion of joint Monte Carlo draws (rows of the (k-1)-dimensional ALR distribution) for which every non-reference record is simultaneously within bounds of the shared reference draw for that row. This is the joint probability that all considered records are synchronous. -
overall_precision: Numeric value representing the smallest age-difference tolerance (as a proportion) for whichoverall_score's joint (all-records-simultaneously) requirement would reachconf_level, or NA if the distribution is unsuitable -
n_records: Integer count of records included in the analysis -
ref_record: Character string identifying the reference record used as denominator in ALR
MC sampling of age input to calculate log-ratio values
Description
Draws n_samples values with replacement from each of two age-sample
vectors and returns the vector of log-ratios log(A / B).
Usage
compute_pairwise_lr(samples_a, samples_b, n_samples = 10000)
Arguments
samples_a |
Numeric vector of posterior age samples for record A. |
samples_b |
Numeric vector of posterior age samples for record B. |
n_samples |
Integer number of Monte Carlo draws (default: 10000). |
Value
Numeric vector of length n_samples.
Compute synchronicity score and precision for considered event deposits
Description
Performs all pairwise comparisons and overall calculations of synchronicity score and synchronicity precision.
Usage
compute_synchronicity_values(
event_stats,
event_names,
confidence_level = 0.95,
age_difference = 0.05,
horizon_groups = NULL,
n_samples = 10000,
seed = 5128
)
Arguments
event_stats |
Output from |
event_names |
Character vector of event names to test. |
confidence_level |
Numeric value or named vector giving the confidence level (a ratio)
at which synchronicity is tested (default: |
age_difference |
Numeric value or named vector giving the maximum age difference between
two records that is still considered synchronous (default:
Supply a named vector to set different values for different horizons; include one unnamed (or last) value to act as the default for any horizon not named. |
horizon_groups |
Named list mapping group names to character vectors of horizon names
that belong to each group (e.g., |
n_samples |
Integer number of Monte Carlo samples drawn per pairwise comparison (default: 10000). |
seed |
Integer random seed for reproducibility (default: 5128). |
Value
Named list with elements:
-
results: Pairwise log-ratio results -
overall_scores: Overall synchronicity scores per horizon group -
viz_data: Data frame of visualization inputs (one row per pairwise comparison) -
all_scores: Data frame of all pairwise scores -
summary: List with total, positives, negatives, min_score, max_score, positive_pct, negative_pct
Compute synchronized ages
Description
Age synchronization function that calculates age for considered isochrons using one of five possible methods.
Usage
compute_synchronized_ages(
event_stats,
method = NULL,
horizons = NULL,
nonsynchro_horizons = NULL,
excluded_records = NULL,
age_record = NULL,
age_value = NULL,
age_error = NULL,
age_cc = NULL,
offset = bp_datum(),
seed = 5128,
n_samples = 10000,
bayes_plot_opts = list(),
horizon_groups = NULL,
verbose = TRUE
)
Arguments
event_stats |
List containing processed age data and summaries (output from
|
method |
Character string or named character vector specifying the synchronization
method(s) used to assign a fixed age (and thus set the age difference between records to
zero) for each horizon. Supply a single string to apply one method to every horizon in
|
horizons |
Character vector of the horizon names to synchronize (default: |
nonsynchro_horizons |
Horizons that were tested but are considered not
synchronous, and so should not be age-matched across records (default: |
excluded_records |
Character vector or named list of records to exclude from the pooled
( |
age_record |
Character string naming the record whose age estimate is adopted when
|
age_value |
Numeric value or named vector giving the age(s) to assign when
|
age_error |
Numeric value or named vector of age errors (default: |
age_cc |
Numeric value or named vector of calibration-curve codes used with
|
offset |
Numeric offset correction value (default: |
seed |
Integer random seed for reproducibility (default: 5128). |
n_samples |
Integer number of Monte Carlo samples drawn per record by the methods that resample posterior ages (default: 10000). |
bayes_plot_opts |
Named list of Bayesian plot layout options. Supported keys:
|
horizon_groups |
Named list mapping group names to character vectors of horizon names
that belong to each group (e.g., |
verbose |
Logical; if |
Value
Named list with two elements:
-
adjusted_ages: Named list of data frames (one per horizon) with columnsrecord,adjusted_age,adjusted_error,cc -
bayesian_plot_data: Named list (one entry per Bayesian horizon) with raw plot data - pass each element toplot_bayesian_age_combination()to draw to the console or save a PDF
Retreve posterior age Samples for a horizon group across all records
Description
Builds a named list of posterior age sample vectors for the specified horizon column names, after applying per-record and global exclusions.
Usage
get_horizon_posteriors(
records_with_horizon,
relevant_horizons,
processed,
per_record_excluded,
global_excluded
)
Arguments
records_with_horizon |
Character vector of record names to search. |
relevant_horizons |
Character vector of column names belonging to the horizon group. |
processed |
Named list of per-record data frames from
|
per_record_excluded |
Named list of per-record exclusions from
|
global_excluded |
Character vector of globally excluded horizons from
|
Value
Named list of numeric vectors (posterior samples), keyed by record name. Records with no valid samples after filtering are omitted.
Retrieve confidence level, age difference, and log-ratio bounds per horizon
Description
Extracts conf_level_h and age_diff_h for a given horizon from
scalar or named-vector inputs, converts an absolute age difference (>= 1) to a
relative one using the mean age from summaries, and computes symmetric
log-space bounds.
Usage
get_horizon_thresholds(horizon, confidence_level, age_difference, summaries)
Arguments
horizon |
Character string identifying the horizon (key for named lookups). |
confidence_level |
Numeric scalar or named numeric vector. |
age_difference |
Numeric scalar or named numeric vector. |
summaries |
Named list of per-record summary data frames from
|
Value
Named list with:
-
conf_level_h: Effective confidence level. -
age_diff_h: Effective (relative) age difference. -
age_diff_log_bounds: Two-element numericc(-t, t)wheret = log(1 + age_diff_h).
Load and store event ages from Bacon/Plum output files
Description
Wrapper function that reads rbacon/rplum .out files and returns a named list of
processed event ages. Combines read_age_model_output() and
compute_event_ages() into a single call. When reload_existing
is TRUE, the previously exported CSV folder is returned instead.
Usage
load_event_ages(
folder_path = syncer_input_dir(),
record_data,
event_types,
max_depths,
isochrons,
test_horizons,
synced = "",
reload_existing = FALSE,
instantaneous_event_depths = NULL,
thick = NULL,
output_dir = syncer_output_dir(),
verbose = TRUE
)
Arguments
folder_path |
Character string giving the parent directory that contains
per-record rbacon/rplum output sub-folders (default: the directory set by |
record_data |
Named list of data frames representing each record's
metadata (output from |
event_types |
Character vector of all event type names present in your dataset. |
max_depths |
Named numeric vector of maximum depths per record. |
isochrons |
Character vector of deposit names known to be synchronous. |
test_horizons |
Character vector of event deposits for which synchronicity should be tested. |
synced |
Character string suffix identifying synchronized output folders
(default: |
reload_existing |
Logical; when |
instantaneous_event_depths |
Optional named list of depth intervals classified as instantaneous deposits per record that should not be considered for event-free depths. |
thick |
The rbacon/rplum section thickness used during age-depth modelling;
single numeric, named list per record, or |
output_dir |
Character string specifying where the previously-exported
|
verbose |
Logical; if |
Value
Named list of data frames, one per processed record, containing depth columns plus one column per event with interpolated ages.
Derive event-type variables from a defined horizon group
Description
Expands a single horizon_groups definition into the event_types,
isochrons, test_events, isochron_groups, and
test_horizon_groups values consumed by the rest of the SyncER
workflow (load_event_ages(), compute_synchronicity_values(),
synchronize_ages(), etc.). Combine with list2env() to unpack the
result into your script in a single line, e.g.
list2env(load_horizon_names(horizon_groups), environment()).
Usage
load_horizon_names(horizon_groups)
Arguments
horizon_groups |
Named list, one entry per event type present in your records. Each entry is itself a list with:
|
Value
A named list with elements event_types, isochrons,
test_events, isochron_groups, and test_horizon_groups.
Determine the next folder generation (after syncing) for a record
Description
The first synchronization of a base record appends "_synced"; every later
generation increments a trailing number on that base ("_synced_1",
"_synced_2", ...), choosing the next unused number among sibling folders
in base_dir.
Usage
next_generation_name(record_key, base_dir)
Arguments
record_key |
Character key of the record being written. |
base_dir |
Character path whose sub-folders are scanned for existing generations. |
Value
Character folder name for the next generation.
Seperate per-record excluded horizons from globally excluded horizons
Description
Normalizes the nonsynchro_horizons argument into two tidy outputs used
downstream to filter age columns. Accepts a named list (CASE 1), a named
character vector (CASE 2), or an unnamed character vector (global exclusion).
Usage
parse_excluded_horizons(nonsynchro_horizons, all_records)
Arguments
nonsynchro_horizons |
Named list, named character vector, or unnamed character
vector. Named entries are matched against |
all_records |
Character vector of all record names. |
Value
Named list with:
-
per_record_excluded: Named list of per-record horizon exclusions. -
global_excluded: Character vector of globally excluded horizons.
Plot Bayesian age combination results
Description
Automatically draws the Bayesian posterior combination figure for one horizon group from
the raw data returned by compute_synchronized_ages()$bayesian_plot_data.
Records that contributed to the combined result are drawn as solid lines;
records excluded from the combination (via excluded_records) are
drawn as dashed lines and labelled "(excluded)" in the legend. Prints to the active graphics
device (console) and, when output_dir is supplied, also saves a PDF.
Usage
plot_bayesian_age_combination(pd, output_dir = NULL, verbose = TRUE)
Arguments
pd |
Named list for a single horizon, as stored in
|
output_dir |
Character string; directory the PDF is saved to. Pass
|
verbose |
Logical; if |
Value
Invisibly returns NULL.
Create synchronicity evaluation plots per pairwise comparison of records
Description
Generates a two-panel visualization for a single event in two records: (1) histogram of log-ratio values with fitted normal distribution & statistics, confidence intervals, and age difference thresholds; (2) age probability density function (PDFs) for both records shown as histograms with frequency gradients.
Usage
plot_pairwise_synchronicity_evaluation(
Amin,
Amax,
Bmin,
Bmax,
ABlr,
sheet1_name,
sheet2_name,
column_name,
col1 = NULL,
col2 = NULL,
age_diff_log_bounds = NULL,
conf_log_bounds = NULL,
conf_level = 0.95,
variant1 = NULL,
variant2 = NULL,
plot_opts = list()
)
Arguments
Amin |
Numeric minimum age range for record A. |
Amax |
Numeric maximum age range for record A. |
Bmin |
Numeric minimum age range for record B. |
Bmax |
Numeric maximum age range for record B. |
ABlr |
Numeric vector of log-ratio values (log(A/B)). |
sheet1_name |
Character string identifying record A. |
sheet2_name |
Character string identifying record B. |
column_name |
Character string identifying the event/horizon being compared. |
col1 |
Numeric vector of posterior age samples for record 1 (default: NULL). |
col2 |
Numeric vector of posterior age samples for record 2 (default: NULL). |
age_diff_log_bounds |
Two-element numeric vector specifying log-space age difference thresholds (shown as green lines on histogram plot). |
conf_log_bounds |
Two-element numeric vector specifying confidence interval bounds in log-space (shown as blue shading on histogram plot). |
conf_level |
Numeric value specifying the confidence level used (e.g., 0.95). |
variant1 |
Optional character string specifying exact horizon name in record 1 (for generic horizon groups) (default: NULL). |
variant2 |
Optional character string specifying exact horizon name in record 2 (for generic horizon groups) (default: NULL). |
plot_opts |
Named list of plot layout options:
|
Value
No return value. Creates a composite plot with two panels displayed in the current graphics device.
Plot synchronicity evaluation plots per horizon across all records
Description
Produces per-horizon PDF files and console visualizations from a
compute_synchronicity_values() result.
Usage
plot_synchronicity_evaluation(
synchro_result,
output_dir = syncer_output_dir(),
offset = bp_datum(),
synced = "",
fig_width = 10,
fig_height = 8,
plot_opts = list(),
verbose = TRUE
)
Arguments
synchro_result |
The list returned by |
output_dir |
Character string specifying the directory the PDF files will be
saved to (default: |
offset |
Numeric offset correction value applied to ages before plotting
(default: |
synced |
Character string appended to PDF file names (default: ""). |
fig_width |
Numeric width of output PDF figures in inches (default: 10). |
fig_height |
Numeric height of output PDF figures in inches (default: 8). |
plot_opts |
Named list of plot layout options:
|
verbose |
Logical; if |
Value
Invisibly returns NULL.
Print summary of isochron-based validation thresholds
Description
Prints a formatted summary table of the thresholds returned by
compute_isochron_thresholds().
Usage
print_validation_summary(thresholds)
Arguments
thresholds |
Output list from |
Value
Invisibly returns thresholds (unchanged).
Prepare age data for log-ratio transformation and calculate basic statistics
Description
Extracts event-specific age columns from rbacon/rplum output, applies offset correction,
and calculates summary statistics. Filters columns matching event deposit patterns,
applies offset to avoid negative ages for post-1950 deposits, and ensures the record top is at age 0.
This function takes the direct output from load_event_ages() and processes it in memory.
Usage
process_event_ages(out_data, event_deposits, offset = bp_datum())
Arguments
out_data |
Named list of data frames or data.tables containing age data
(output from |
event_deposits |
Character vector of event deposit names to extract (typically
|
offset |
Numeric value added to every age so that the age reference point becomes, for
example, the year the (most recent) records were retrieved rather than 1950 AD (default:
|
Value
A named list with two elements:
-
processed: List of data frames with offset-corrected ages for each record -
summaries: List of summary data frames containing min, max, mean, and sd (sigma) for each event column
Reconstruct the synchronized age list from a frame
Description
Any dated event (non-NA C14_age) that is neither a radiocarbon sample nor
a Pb210 sample is treated as a synchronized horizon, and returned in the
adjusted_ages shape build_age_input() consumes.
Usage
read_adjusted_ages(
frame,
record_key,
radiocarbon_sample_names,
lead_sample_names
)
Arguments
frame |
Data frame for a single record, with an |
record_key |
Character key identifying the record the ages belong to. |
radiocarbon_sample_names |
Character vector of event label(s) marking radiocarbon samples. |
lead_sample_names |
Character vector of event label(s) marking Pb-210 samples. |
Value
Named list of one-row data frames (one per synchronized horizon), or an
empty list when frame has no C14_age column.
Read age results of age-depth modelling for each of the event horizons
Description
Reads a folder of CSV files containing all age information for events, one file per record,
and returns a named list of data frames. This is the inverse operation of
write_age_output_data(), and allows you to reload previously saved results without recalculating or
load age info into SyncER in case the age-depth models were not constructed using rbacon/rplum.
Usage
read_age_data(folder_path = syncer_output_dir(), synced = "", verbose = TRUE)
Arguments
folder_path |
Character string specifying the location of the folder to be read
(default: |
synced |
Character string suffix for the input folder name (default: ""); use "_synced" for synchronized data. |
verbose |
Logical; if |
Value
A named list of data frames, where each element corresponds to one record. List names match the CSV file names (without extension).
Examples
if (requireNamespace("SyncERdata", quietly = TRUE)) {
# Set-up: save the example data of the companion package SyncERdata to a
# temporary folder (stands in for "path/to/folder")
folder <- tempdir()
write_age_output_data(SyncERdata::out_data_ages, folder, verbose = FALSE)
write_age_output_data(SyncERdata::out_data_ages_synced, folder,
synced = "_synced", verbose = FALSE)
# Read non-synchronized data
out_data <- read_age_data(folder)
# Read synchronized data
out_data_synced <- read_age_data(folder, synced = "_synced")
# Use with process_event_ages
event_stats <- process_event_ages(out_data, event_deposits = c("tephra", "flood"))
}
Read Bacon/Plum age-depth modelling output files
Description
Reads raw lines from rbacon/rplum .out files for a set of records into a named list.
Call this function to obtain raw age data, then pass the result to compute_event_ages() for computation of event ages,
and finally call write_age_output_data() to save the processed ages in your folder.
Usage
read_age_model_output(
folder_path = syncer_input_dir(),
synced = "",
max_depths = NULL,
instantaneous_event_depths = NULL,
verbose = TRUE
)
Arguments
folder_path |
Character string giving the parent directory that contains
the per-record rbacon/rplum output sub-folders (default: the directory set by |
synced |
Character string suffix used to identify synchronized output folders
(default: |
max_depths |
Named numeric vector of original core depths (cm), used only for
progress reporting. Pass |
instantaneous_event_depths |
Optional named list of excluded depth intervals per record, used only for progress reporting. |
verbose |
Logical; if |
Value
Named list of character vectors (one element per folder / record), where each
element contains the raw text lines of the corresponding .out file.
Load age input data and event depths
Description
Loads age input dates (radiocarbon and/or 210Pb) and event depths of all records from a folder of
CSV files and calculates maximum depths and sedimentation rates for each record. The function reads
every .csv file in the folder, where each file represents one sediment record. For records
missing required columns ('depth' or 'C14_age'), warnings are issued and NA values are returned.
Usage
read_record_data(
folder_path = syncer_input_dir(),
file_name = "record_data_input"
)
Arguments
folder_path |
Character string specifying the path to the folder containing your input file
(default: the directory set by |
file_name |
Character string specifying the name of the subfolder (inside |
Value
A named list with three elements:
-
record_data: Named list of data frames, one per record (each CSV file becomes one element) -
max_depths: Named numeric vector containing the maximum depth value for each record -
sedrates: Named numeric vector containing an estimated sedimentation rate for each record (calculated as oldest C14 age divided by its depth)
Check log-ratio distribution shape via skewness and kurtosis z-tests
Description
Flags a numeric vector as approximately normal-shaped using the standard errors of skewness and kurtosis: z_skewness = skewness / sqrt(6 / N) z_kurtosis = excess_kurtosis / sqrt(24 / N) If either |z| exceeds the critical value, the distribution is flagged non-normal on that characteristic.
Usage
shape_ok(x, critical_z = 1.96)
Arguments
x |
Numeric vector to test. |
critical_z |
Critical z value (default 1.96, the .05 significance level; use 2.58 for the .01 level). |
Value
Logical: TRUE if both z_skewness and z_kurtosis are within bounds.
Base directory for SyncER input/output folders
Description
Returns the directory chosen with syncer_setup, or a per-session temporary
directory if none was chosen, so that SyncER never writes to the user's file space
unless asked to.
Usage
syncer_base_dir()
Value
Character string: path to the base directory.
Directory to read SyncER input folders from
Description
Returns the directory chosen with syncer_setup, or the current working
directory if none was chosen. Only used for reading.
Usage
syncer_input_dir()
Value
Character string: path to the input directory.
Set up SyncER output directory
Description
Returns the path to the SyncER_outputs folder, creating it if it does not already exist.
Every SyncER function that writes files (CSVs, PDFs) defaults its output-location argument
to this folder, so that all package output ends up in one predictable place unless the user
explicitly overrides it. If syncer_setup has been called earlier in the session, that
chosen directory is used; otherwise this defaults to a subfolder of tempdir(), so that
SyncER never writes to the user's file space without being asked to.
Usage
syncer_output_dir()
Value
Character string: path to the SyncER_outputs directory.
Set up SyncER working directory and output folder
Description
Optional first step of a SyncER script: choose the folder SyncER should work in
(holding your record_data_input folder and the age-depth model folders, and receiving all
output in a SyncER_outputs subfolder). The choice is remembered for the rest of the R session
(via options(SyncER.wd = ...)) and used as the default location by the other SyncER
functions, so you only need to set it once, at the top of your script. If the folder does not
exist yet, it is created. Your R working directory (getwd()) is never changed.
If you never call this function, input is read from the current working directory and output is
written to a per-session temporary directory (see syncer_output_dir), so
SyncER never writes to your file space without being asked to.
Usage
syncer_setup(wd = getOption("SyncER.wd"), verbose = TRUE)
Arguments
wd |
Character string giving the directory SyncER should use. If
omitted, first checks |
verbose |
Logical; if |
Value
Invisibly returns the path to the SyncER_outputs directory.
Examples
# Use a temporary directory (never write to your own file space in examples)
old <- options(SyncER.wd = getOption("SyncER.wd"))
syncer_setup(wd = tempdir())
options(old) # restore the previous setting
Computes synchronized ages and plots Bayesian age combinations if used
Description
Calls compute_synchronized_ages() and saves Bayesian combination plots to PDF if used as a matching method.
Usage
synchronize_ages(
event_stats,
output_dir = syncer_output_dir(),
method = NULL,
horizons = NULL,
nonsynchro_horizons = NULL,
excluded_records = NULL,
age_record = NULL,
age_value = NULL,
age_error = NULL,
age_cc = NULL,
offset = bp_datum(),
seed = 5128,
n_samples = 10000,
bayes_plot_opts = list(),
horizon_groups = NULL,
verbose = TRUE
)
Arguments
event_stats |
List containing processed age data and summaries (output from
|
output_dir |
Character string specifying the directory Bayesian plot PDFs will be
saved to (default: |
method |
Character string or named character vector specifying the synchronization
method(s) used to assign a fixed age (and thus set the age difference between records to
zero) for each horizon. Supply a single string to apply one method to every horizon in
|
horizons |
Character vector of the horizon names to synchronize (default: |
nonsynchro_horizons |
Horizons that were tested but are considered not
synchronous, and so should not be age-matched across records (default: |
excluded_records |
Character vector or named list of records to exclude from the pooled
( |
age_record |
Character string naming the record whose age estimate is adopted when
|
age_value |
Numeric value or named vector giving the age(s) to assign when
|
age_error |
Numeric value or named vector of age errors (default: |
age_cc |
Numeric value or named vector of calibration-curve codes used with
|
offset |
Numeric offset correction value (default: |
seed |
Integer random seed for reproducibility (default: 5128). |
n_samples |
Integer number of Monte Carlo samples drawn per record by the methods that resample posterior ages (default: 10000). |
bayes_plot_opts |
Named list of Bayesian plot layout options passed to
|
horizon_groups |
Named list mapping group names to character vectors of horizon names
that belong to each group (e.g., |
verbose |
Logical; if |
Value
Named list of synchronized ages (one element per horizon), as returned
by compute_synchronized_ages()$adjusted_ages.
Write and plot synchronicity testing results for evaluation
Description
Saves a CSV of horizon statistics, prints a summary to the console,
and produces per-horizon visualizations of the age PDFs and log-ratio distributions.
Call compute_synchronicity_values() first and pass its result here.
Usage
verify_synchronicity(
synchro_result,
event_names,
output_dir = syncer_output_dir(),
group_name = NULL,
synced = "",
isochron = FALSE,
offset = bp_datum(),
fig_width = 10,
fig_height = 8,
plot_opts = list(),
verbose = TRUE
)
Arguments
synchro_result |
The list returned by |
event_names |
Character vector of event names being tested. Falls back to
naming the CSV file when |
output_dir |
Character string specifying the directory the statistics CSV will be
saved to (default: |
group_name |
Character string used to name the CSV file (as
|
synced |
Character string appended to output filenames (default: |
isochron |
Logical; when |
offset |
Numeric offset correction value passed to |
fig_width |
Numeric width of output PDF figures in inches (default: 10). |
fig_height |
Numeric height of output PDF figures in inches (default: 8). |
plot_opts |
Named list of plot layout options:
|
verbose |
Logical; if |
Value
Invisibly returns synchro_result unchanged.
Write a build_age_input() result to a folder
Description
Writes the radiocarbon CSV (and, when present, the Pb210 CSV) of a
build_age_input() result into base_dir/out_key, creating the
folder if needed. Follows the rbacon/rplum naming convention:
<key>_C14.csv plus <key>.csv when lead data is present, otherwise
<key>.csv for the radiocarbon data.
Usage
write_age_input_data(age_input, out_key, base_dir, verbose = TRUE)
Arguments
age_input |
List with a |
out_key |
Character key naming the output folder and file stem. |
base_dir |
Character path the |
verbose |
Logical; if |
Value
Invisibly NULL; called for its side effect of writing CSV files.
Write age data (including event ages) into CSV files
Description
Each record's age information (including event ages) is written to a separate CSV file inside an output folder, with file names matching the list element names, and each row represents a single MCMC simulation.
Usage
write_age_output_data(
out_data,
folder_path = syncer_output_dir(),
synced = "",
verbose = TRUE
)
Arguments
out_data |
Named list of data frames where each element will become a separate CSV file. |
folder_path |
Character string specifying the location where the output folder should be saved
(default: |
synced |
Character string suffix for the output folder name (default: ""); use "_synced" for synchronized data. |
verbose |
Logical; if |
Value
No return value. Writes one CSV file per record and prints a success message with the folder path.