char_smooth: Smooth charcoal record to estimate low-frequency C_background

View source: R/char_smooth.R

char_smoothR Documentation

Smooth charcoal record to estimate low-frequency C_background

Description

Applies one of five smoothing methods to the interpolated charcoal accumulation rate series (charcoal$accI) and stores the result in charcoal$accIS. Mirrors CharSmooth.m from the MATLAB v2.0 codebase.

Usage

char_smooth(charcoal, pretreatment, smoothing, results = NULL, plot_data = 0L)

Arguments

charcoal

Named list with elements accI (resampled CHAR, length N), ybpI (resampled ages), and ybp (raw ages).

pretreatment

Named list with element yrInterp.

smoothing

Named list with elements:

method

Integer 1-5 selecting the smoothing method.

yr

Window width in years.

results

Named list (not used in R; kept for API symmetry).

plot_data

0/1 flag; ignored in R (no diagnostic plots).

Details

## Smoothing methods | Index | Name | Implementation | |——-|——|—————-| | 1 | Lowess | [char_lowess()] with iter = 0 | | 2 | Robust Lowess | [char_lowess()] with iter = 4 | | 3 | Moving average | zoo::rollapply(..., mean, partial=TRUE) | | 4 | Running median + Lowess | Shifted-window median loop, then [char_lowess()] | | 5 | Running mode + Lowess | Shifted-window 100-bin mode loop, then [char_lowess()] |

## Span convention The smoothing window width in data-point units is s = smoothing$yr / pretreatment$yrInterp. This is passed to [char_lowess()] as span = s (number of points), which converts it to the fraction required by stats::lowess() via f = round(s) / N.

## NaN bridging NaN values in accI (from record gaps) cannot be passed to [char_lowess()] directly. They are bridged by linear interpolation before smoothing and restored afterward, matching the MATLAB fallback path in CharSmooth.m (used when the Curve Fitting Toolbox is absent). Methods 4 and 5 always use the bridged series.

## Window selection for methods 4 and 5 The boundary window is SHIFTED (not shrunk) to maintain exactly round(s) samples, matching MATLAB's loop logic. Note that MATLAB's round() rounds 0.5 away from zero while R uses banker's rounding (round half to even); this can cause single-sample differences in window boundaries for odd half-integers.

Value

The input charcoal list with an additional element accIS: the smoothed C_background series (length N).

See Also

[char_lowess()], [CharAnalysis()]


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