| char_lowess | R Documentation |
Pure-R implementation of the shifted-window lowess algorithm from MATLAB's
charLowess.m v2.0, which itself replicates MATLAB's
smooth(y, k, 'lowess') from the Curve Fitting Toolbox. Replaces
the previous wrapper around lowess, which used a
shrinking window at record boundaries and different tricubic weight
normalisation, causing systematic differences of ~1e-3 in charBkg.
char_lowess(y, x = NULL, span = 0.1, iter = 0L)
y |
Numeric vector of values to smooth (NaN-free; bridge NaNs before calling and restore afterward, matching the MATLAB workflow). |
x |
Numeric vector of x-positions (same length as |
span |
Smoothing span.
Converted to integer |
iter |
Number of bisquare robustness passes after the initial fit.
|
## Algorithm
For each point i, a window of exactly k points is selected:
the window is centred on i at interior points and SHIFTED (not
shrunk) at record boundaries, maintaining k neighbours throughout.
Each neighbour j receives a tricubic weight:
w_j = \left(1 - \left(\frac{|i-j|}{d_{\max}}\right)^3\right)^3
where d_{\max} is the distance to the furthest point in
the window (not the half-window radius). A weighted least-squares line
is fitted and evaluated at i. This matches
charLowess.m lines 109-147 exactly.
For iter > 0 ('rlowess'), bisquare robustness weights are
computed from the residuals after each WLS pass and multiplied into the
tricubic weights for the next pass (matching charLowess.m lines
151-157).
## Why not stats::lowess()?
stats::lowess() trims (shrinks) the window at boundaries and
normalises tricubic weights by the half-window radius hw. The two
differences compound to ~1e-3 absolute error in charBkg for the CO
dataset (500 yr / 15 yr = 33-point window, 17-point boundary zone).
Numeric vector of smoothed values, same length as y.
[char_smooth()], [char_thresh_local()]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.