char_thresh_global: Calculate a global threshold value for charcoal peak...

View source: R/char_thresh_global.R

char_thresh_globalR Documentation

Calculate a global threshold value for charcoal peak identification

Description

Determines a single threshold applied uniformly across the entire record. The noise component of C_peak is modelled as a zero-mean Gaussian (residuals), a one-mean Gaussian (ratios), or via a Gaussian mixture model (GMM). Mirrors CharThreshGlobal.m from the MATLAB v2.0 codebase.

Usage

char_thresh_global(
  charcoal,
  pretreatment,
  peak_analysis,
  site = NULL,
  results = NULL,
  plot_data = 0L,
  bkg_sens_in = 0L
)

Arguments

charcoal

Named list containing peak (C_peak series) and ybpI.

pretreatment

Named list with zoneDiv.

peak_analysis

Named list with cPeak, threshMethod, threshValues.

site

Character string (site name; unused in R, kept for API symmetry).

results

Named list (unused in R, kept for API symmetry).

plot_data

0/1 flag; ignored in R.

bkg_sens_in

0/1 flag; ignored in R (no sensitivity loop).

Details

## Gaussian assumption (threshMethod = 2) For residuals (cPeak = 1): noise is zero-mean; sigma is estimated from the negative half of C_peak, mirrored and pooled. For ratios (cPeak = 2): noise is one-mean; values are shifted to zero, mirrored, shifted back, and sigma estimated from the pooled set.

## GMM (threshMethod = 3) MATLAB's GaussianMixture(X, 2, 2, false) is replicated by gaussian_mixture_em(X) from utils_gaussian_mixture.R, using the same first/last-point initialisation and loose convergence criterion as the original Bowman CLUSTER EM. The noise component is identified as the Gaussian with the smaller mean (matching MATLAB's noiseIdx = find(mu == min(mu), 1)).

## Bin-lookup for threshold values Percentile thresholds are mapped to the nearest bin in possible (251 equally-spaced values spanning C_peak range). The v2.0 bug fix is preserved: both sides of the abs() comparison use the CHAR-unit threshold value thresh[i], not the raw percentile.

Value

Named list char_thresh with elements:

possible

Numeric vector of 251 candidate threshold bins.

pos

Numeric matrix [N x 4]: positive threshold for each of the four threshValues.

neg

Numeric matrix [N x 4] (method 1) or [N x 1] (methods 2-3): negative threshold.

noise_pdf

Estimated noise PDF evaluated at possible (methods 2-3), or scalar -99 (method 1).

mu_hat

Fitted noise-component mean.

sigma_hat

Fitted noise-component standard deviation.

SNI

Signal-to-noise index (scalar).

GOF

Sentinel vector (-999, length N).

See Also

[char_thresh_local()], [char_smooth()], [CharAnalysis()]


CharAnalysis documentation built on May 3, 2026, 5:06 p.m.