| Title: | High-Performance LOESS Smoothing for R |
|---|---|
| Description: | Provides high-performance LOESS smoothing (Locally Estimated Scatterplot Smoothing) using a 'Rust' backend. Supports various weight functions, robustness iterations, streaming/online processing, cross-validation, and uncertainty quantification. Applicable to genomic data, time series, and general-purpose smoothing tasks. |
| Authors: | Amir Valizadeh [aut, cre] (ORCID: <https://orcid.org/0000-0001-5983-8527>) |
| Maintainer: | Amir Valizadeh <[email protected]> |
| License: | MIT + file LICENSE | Apache License (== 2.0) |
| Version: | 3.0.0 |
| Built: | 2026-10-22 05:23:32 UTC |
| Source: | https://github.com/thisisamirv/loess-project |
Add a single point to an online LOESS model
add_point(model, ...) ## S3 method for class 'OnlineLoess' add_point(model, x, y, weight = 1, ...)add_point(model, ...) ## S3 method for class 'OnlineLoess' add_point(model, x, y, weight = 1, ...)
model |
An |
... |
Must be empty. |
x |
A numeric coordinate vector with one value per configured dimension. For one-dimensional models, a scalar is also accepted. |
y |
A single numeric y value. |
weight |
Finite non-negative case weight for this observation; defaults to 1. |
An online result list, or NULL if fewer than
min_points have been added.
model <- OnlineLoess(fraction = 0.2, window_capacity = 20L, min_points = 2L) invisible(add_point(model, 1.0, 0.5)) add_point(model, 2.0, 0.6)model <- OnlineLoess(fraction = 0.2, window_capacity = 20L, min_points = 2L) invisible(add_point(model, 1.0, 0.5)) add_point(model, 2.0, 0.6)
Loess
Cross-validation options for Loess
cv_opts(fractions, method = "kfold", k = 5L)cv_opts(fractions, method = "kfold", k = 5L)
fractions |
Numeric vector of candidate smoothing fractions. |
method |
Cross-validation method: |
k |
Number of folds for k-fold cross-validation. Default: 5. |
A cv_opts list for Loess(cv = ...).
model <- Loess(cv = cv_opts(fractions = c(0.2, 0.3, 0.5)))model <- Loess(cv = cv_opts(fractions = c(0.2, 0.3, 0.5)))
Finalize a streaming LOESS model
finalize(model, ...)finalize(model, ...)
model |
A |
... |
Must be empty. |
A LoessResult combining all processed chunks.
x <- seq(0, 10, length.out = 100) y <- sin(x) + rnorm(100, 0, 0.1) model <- StreamingLoess(fraction = 0.2, chunk_size = 50L) invisible(process_chunk(model, x[1:50], y[1:50])) finalize(model)x <- seq(0, 10, length.out = 100) y <- sin(x) + rnorm(100, 0, 0.1) model <- StreamingLoess(fraction = 0.2, chunk_size = 50L) invisible(process_chunk(model, x[1:50], y[1:50])) finalize(model)
Fit a LOESS model to data
fit(model, ...) ## S3 method for class 'Loess' fit(model, x, y, custom_weights = NULL, ...)fit(model, ...) ## S3 method for class 'Loess' fit(model, x, y, custom_weights = NULL, ...)
model |
A |
... |
Must be empty. |
x |
Numeric vector of predictor values. |
y |
Numeric vector of response values. |
custom_weights |
Optional numeric vector of non-negative per-observation
weights. |
A LoessResult object.
x <- seq(0, 10, length.out = 100) y <- sin(x) + rnorm(100, 0, 0.1) model <- Loess(fraction = 0.2) fit(model, x, y)x <- seq(0, 10, length.out = 100) y <- sin(x) + rnorm(100, 0, 0.1) model <- Loess(fraction = 0.2) fit(model, x, y)
Interval options for fitting and prediction
intervals_opts(confidence = NULL, prediction = NULL)intervals_opts(confidence = NULL, prediction = NULL)
confidence |
Confidence coverage level in (0, 1), or |
prediction |
Prediction coverage level in (0, 1), or |
A named list for the intervals argument.
model <- Loess(intervals = intervals_opts(confidence = 0.95))model <- Loess(intervals = intervals_opts(confidence = 0.95))
Create a stateful LOESS model for batch smoothing. This is the default mode: it processes the entire dataset at once and supports every feature (confidence/prediction intervals and cross-validation).
Loess( fraction = 0.67, ..., iterations = 3L, weight_function = "tricube", robustness_method = "bisquare", scaling_method = "mad", boundary_policy = "extend", outputs = NULL, intervals = NULL, zero_weight_fallback = "use_local_mean", auto_converge = NULL, parallel = TRUE, degree = "linear", dimensions = 1L, distance_metric = "normalized", surface_mode = "interpolation", weighted_metric_weights = NULL, cell = NULL, interpolation_vertices = NULL, boundary_degree_fallback = NULL, seed = NULL, missing = "error", retain_model = FALSE, cv = NULL )Loess( fraction = 0.67, ..., iterations = 3L, weight_function = "tricube", robustness_method = "bisquare", scaling_method = "mad", boundary_policy = "extend", outputs = NULL, intervals = NULL, zero_weight_fallback = "use_local_mean", auto_converge = NULL, parallel = TRUE, degree = "linear", dimensions = 1L, distance_metric = "normalized", surface_mode = "interpolation", weighted_metric_weights = NULL, cell = NULL, interpolation_vertices = NULL, boundary_degree_fallback = NULL, seed = NULL, missing = "error", retain_model = FALSE, cv = NULL )
fraction |
Smoothing fraction, greater than 0 and up to 1. Default: 0.67. See Details for guidance on choosing a value. |
... |
Not used; forces all subsequent arguments to be named. |
iterations |
Number of robustness iterations, between 0 and 1000 (inclusive). Default: 3. |
weight_function |
Kernel weight function. One of |
robustness_method |
Outlier downweighting method: |
scaling_method |
Residual scale estimation for robustness weights:
|
boundary_policy |
Boundary handling strategy: |
outputs |
Optional character vector selecting |
intervals |
Grouped coverage levels from |
zero_weight_fallback |
Fallback policy when all robustness weights drop
to zero: |
auto_converge |
Convergence tolerance for early stopping of robustness
iterations. |
parallel |
Logical; enable parallel processing. Default: |
degree |
Local polynomial degree: |
dimensions |
Number of predictor dimensions. Default: 1. |
distance_metric |
Distance metric for neighbourhood computation:
|
surface_mode |
Surface evaluation mode: |
weighted_metric_weights |
Numeric vector of per-dimension weights.
Length must equal |
cell |
Cell size tuning parameter for the interpolation grid.
|
interpolation_vertices |
Number of vertices in the interpolation grid.
|
boundary_degree_fallback |
Logical; if |
seed |
Seed for reproducible CV folds, or |
missing |
Policy for non-finite (NaN/Inf) values in the input data:
|
retain_model |
Logical; if |
cv |
Grouped cross-validation settings from |
Best suited when the dataset fits in memory and you need intervals,
cross-validation, or diagnostics. For datasets that don't fit in memory or
arrive in chunks, see StreamingLoess; for point-by-point
real-time data, see OnlineLoess.
fraction is the most important parameter: it controls the size of the
local neighbourhood used at each point.
When outputs includes "diagnostics", Batch residual_sd is the robust
residual scale estimate 1.4826 * MAD.
| Range | Effect | Use case |
| 0.1-0.3 | Fine detail | Rapidly changing signals |
| 0.3-0.5 | Balanced | General purpose |
| 0.5-0.7 | Heavy smoothing | Noisy data |
| 0.7-1.0 | Very smooth | Trend extraction |
A Loess object.
x <- seq(0, 10, length.out = 100) y <- sin(x) + rnorm(100, 0, 0.1) model <- Loess(fraction = 0.2) result <- fit(model, x, y) plot(x, y) lines(x, result$y, col = "red")x <- seq(0, 10, length.out = 100) y <- sin(x) + rnorm(100, 0, 0.1) model <- Loess(fraction = 0.2) result <- fit(model, x, y) plot(x, y) lines(x, result$y, col = "red")
Create a stateful LOESS model for real-time online data. Maintains a
sliding window and processes each incoming point immediately via
add_point.
OnlineLoess( fraction = 0.67, window_capacity = 1000L, min_points = 2L, ..., iterations = 0L, weight_function = "tricube", robustness_method = "bisquare", scaling_method = "mad", boundary_policy = "extend", zero_weight_fallback = "use_local_mean", update_mode = "incremental", auto_converge = NULL, intervals = NULL, degree = "linear", dimensions = 1L, distance_metric = "normalized", surface_mode = "interpolation", weighted_metric_weights = NULL, cell = NULL, interpolation_vertices = NULL, boundary_degree_fallback = NULL, missing = "error", outputs = NULL )OnlineLoess( fraction = 0.67, window_capacity = 1000L, min_points = 2L, ..., iterations = 0L, weight_function = "tricube", robustness_method = "bisquare", scaling_method = "mad", boundary_policy = "extend", zero_weight_fallback = "use_local_mean", update_mode = "incremental", auto_converge = NULL, intervals = NULL, degree = "linear", dimensions = 1L, distance_metric = "normalized", surface_mode = "interpolation", weighted_metric_weights = NULL, cell = NULL, interpolation_vertices = NULL, boundary_degree_fallback = NULL, missing = "error", outputs = NULL )
fraction |
Smoothing fraction, greater than 0 and up to 1. Default: 0.67. See Details for guidance on choosing a value. |
window_capacity |
Maximum number of points kept in the sliding window, at least 3. Default: 1000. |
min_points |
Minimum number of points required before smoothing
begins, between 2 and |
... |
Not used; forces all subsequent arguments to be named. |
iterations |
Number of robustness iterations, between 0 and 1000 (inclusive). Default: 3. |
weight_function |
Kernel weight function. One of |
robustness_method |
Outlier downweighting method: |
scaling_method |
Residual scale estimation for robustness weights:
|
boundary_policy |
Boundary handling strategy: |
zero_weight_fallback |
Fallback policy when all robustness weights drop
to zero: |
update_mode |
Window update strategy: |
auto_converge |
Convergence tolerance for early stopping of robustness
iterations. |
intervals |
Grouped coverage levels from |
degree |
Local polynomial degree: |
dimensions |
Number of predictor dimensions; each |
distance_metric |
Distance metric for neighbourhood computation:
|
surface_mode |
Surface evaluation mode: |
weighted_metric_weights |
Numeric vector of per-dimension weights.
Length must equal |
cell |
Cell size tuning parameter for the interpolation grid.
|
interpolation_vertices |
Number of vertices in the interpolation grid.
|
boundary_degree_fallback |
Logical; if |
missing |
Policy for a non-finite (NaN/Inf) |
outputs |
Optional character vector selecting |
Best suited when data arrives incrementally (e.g. sensors or streams),
real-time smoothed values are needed, or memory is fixed. For datasets
that fit in memory, see Loess; for large batches processed
in chunks, see StreamingLoess.
An OnlineLoess object.
model <- OnlineLoess(fraction = 0.2, window_capacity = 20) x <- 1:50 y <- sin(x * 0.1) + rnorm(50, 0, 0.1) smoothed <- numeric(0) for (i in seq_along(x)) { result <- add_point(model, x[i], y[i]) if (!is.null(result)) smoothed <- c(smoothed, result$y) } head(smoothed, 5)model <- OnlineLoess(fraction = 0.2, window_capacity = 20) x <- 1:50 y <- sin(x * 0.1) + rnorm(50, 0, 0.1) smoothed <- numeric(0) for (i in seq_along(x)) { result <- add_point(model, x[i], y[i]) if (!is.null(result)) smoothed <- c(smoothed, result$y) } head(smoothed, 5)
Plotting supports one-dimensional results. For a multivariate fit, select a predictor dimension and create a custom plot.
## S3 method for class 'LoessResult' plot(x, main = "LOESS Fit", ...)## S3 method for class 'LoessResult' plot(x, main = "LOESS Fit", ...)
x |
A LoessResult object. |
main |
Plot title. |
... |
Additional arguments passed to plot() and lines(). |
NULL, invisibly. Called for side effects (plotting).
x <- seq(0, 10, length.out = 100) y <- sin(x) + rnorm(100, 0, 0.1) model <- Loess(fraction = 0.2) res <- fit(model, x, y) plot(res)x <- seq(0, 10, length.out = 100) y <- sin(x) + rnorm(100, 0, 0.1) model <- Loess(fraction = 0.2) res <- fit(model, x, y) plot(res)
Predict from the current Online window
predict_window(model, ...) ## S3 method for class 'OnlineLoess' predict_window( model, new_x, outputs = NULL, intervals = NULL, extrapolation = "clamp", max_extrapolation_distance = NULL, max_neighbor_distance = NULL, ... )predict_window(model, ...) ## S3 method for class 'OnlineLoess' predict_window( model, new_x, outputs = NULL, intervals = NULL, extrapolation = "clamp", max_extrapolation_distance = NULL, max_neighbor_distance = NULL, ... )
model |
An OnlineLoess object. |
... |
Must be empty. |
new_x |
Numeric query points (flattened, one coordinate per dimension). |
outputs |
Optional character vector selecting |
intervals |
Grouped coverage levels from |
extrapolation |
Behavior outside the window's predictor bounds:
|
max_extrapolation_distance |
Optional cap for linear extrapolation. |
max_neighbor_distance |
Optional cap for sparse-neighborhood predictions. |
A list containing predicted values and requested optional outputs.
model <- OnlineLoess( fraction = 1, window_capacity = 20L, surface_mode = "direct" ) for (x in 1:10) { invisible(add_point(model, x, 2 * x + 1)) } predict_window(model, c(4.5, 5.5), outputs = "gradient")model <- OnlineLoess( fraction = 1, window_capacity = 20L, surface_mode = "direct" ) for (x in 1:10) { invisible(add_point(model, x, 2 * x + 1)) } predict_window(model, c(4.5, 5.5), outputs = "gradient")
Predict from a fitted LOESS model at out-of-sample points
## S3 method for class 'Loess' predict( object, new_x, intervals = NULL, extrapolation = "clamp", max_extrapolation_distance = NULL, max_neighbor_distance = NULL, outputs = NULL, ... )## S3 method for class 'Loess' predict( object, new_x, intervals = NULL, extrapolation = "clamp", max_extrapolation_distance = NULL, max_neighbor_distance = NULL, outputs = NULL, ... )
object |
A |
new_x |
Numeric vector of out-of-sample query points (flattened,
|
intervals |
Grouped coverage levels from |
extrapolation |
Behavior for query points outside the training range:
|
max_extrapolation_distance |
Under |
max_neighbor_distance |
Maximum allowed distance to the farthest point
in a query's neighbor window before |
outputs |
Optional character vector selecting |
... |
Must be empty. |
A list with a y element (predicted values) and optional
standard_errors/confidence_lower/confidence_upper/
prediction_lower/prediction_upper/derivative elements.
x <- seq(0, 10, length.out = 100) y <- sin(x) + rnorm(100, 0, 0.1) model <- Loess(fraction = 0.2, retain_model = TRUE) fit(model, x, y) predict(model, c(2.5, 7.5))x <- seq(0, 10, length.out = 100) y <- sin(x) + rnorm(100, 0, 0.1) model <- Loess(fraction = 0.2, retain_model = TRUE) fit(model, x, y) predict(model, c(2.5, 7.5))
Print Loess Model
## S3 method for class 'Loess' print(x, ...)## S3 method for class 'Loess' print(x, ...)
x |
A Loess object. |
... |
Additional arguments (ignored). |
The input object x, invisibly.
model <- Loess(fraction = 0.3) print(model)model <- Loess(fraction = 0.3) print(model)
Print Loess Result
## S3 method for class 'LoessResult' print(x, ...)## S3 method for class 'LoessResult' print(x, ...)
x |
A LoessResult object. |
... |
Additional arguments (ignored). |
The input object x, invisibly.
x <- seq(0, 10, length.out = 50) y <- sin(x) + rnorm(50, 0, 0.1) model <- Loess(fraction = 0.3) result <- fit(model, x, y) print(result)x <- seq(0, 10, length.out = 50) y <- sin(x) + rnorm(50, 0, 0.1) model <- Loess(fraction = 0.3) result <- fit(model, x, y) print(result)
Print OnlineLoess Model
## S3 method for class 'OnlineLoess' print(x, ...)## S3 method for class 'OnlineLoess' print(x, ...)
x |
An OnlineLoess object. |
... |
Additional arguments. |
The input object x, invisibly.
model <- OnlineLoess(fraction = 0.2, window_capacity = 20L) print(model)model <- OnlineLoess(fraction = 0.2, window_capacity = 20L) print(model)
Print StreamingLoess Model
## S3 method for class 'StreamingLoess' print(x, ...)## S3 method for class 'StreamingLoess' print(x, ...)
x |
A StreamingLoess object. |
... |
Additional arguments. |
The input object x, invisibly.
model <- StreamingLoess(fraction = 0.3, chunk_size = 50L) print(model)model <- StreamingLoess(fraction = 0.3, chunk_size = 50L) print(model)
Process a data chunk through a streaming LOESS model
process_chunk(model, ...) ## S3 method for class 'StreamingLoess' process_chunk(model, x, y, custom_weights = NULL, ...)process_chunk(model, ...) ## S3 method for class 'StreamingLoess' process_chunk(model, x, y, custom_weights = NULL, ...)
model |
A |
... |
Must be empty. |
x |
Numeric vector of x values. |
y |
Numeric vector of y values. |
custom_weights |
Optional numeric case weight per observation. |
A LoessResult for this chunk.
x <- seq(0, 10, length.out = 100) y <- sin(x) + rnorm(100, 0, 0.1) model <- StreamingLoess(fraction = 0.2, chunk_size = 50L) process_chunk(model, x[1:50], y[1:50])x <- seq(0, 10, length.out = 100) y <- sin(x) + rnorm(100, 0, 0.1) model <- StreamingLoess(fraction = 0.2, chunk_size = 50L) process_chunk(model, x[1:50], y[1:50])
Create a stateful LOESS model for streaming data. Processes data in
fixed-size chunks with configurable overlap: results for each chunk are
returned by process_chunk, and finalize
flushes any remaining buffered points after the last chunk.
StreamingLoess( fraction = 0.67, chunk_size = 5000L, ..., overlap = NULL, iterations = 3L, weight_function = "tricube", robustness_method = "bisquare", scaling_method = "mad", boundary_policy = "extend", zero_weight_fallback = "use_local_mean", auto_converge = NULL, intervals = NULL, merge_strategy = "weighted_average", parallel = TRUE, degree = "linear", dimensions = 1L, distance_metric = "normalized", surface_mode = "interpolation", weighted_metric_weights = NULL, cell = NULL, interpolation_vertices = NULL, boundary_degree_fallback = NULL, missing = "error", outputs = NULL )StreamingLoess( fraction = 0.67, chunk_size = 5000L, ..., overlap = NULL, iterations = 3L, weight_function = "tricube", robustness_method = "bisquare", scaling_method = "mad", boundary_policy = "extend", zero_weight_fallback = "use_local_mean", auto_converge = NULL, intervals = NULL, merge_strategy = "weighted_average", parallel = TRUE, degree = "linear", dimensions = 1L, distance_metric = "normalized", surface_mode = "interpolation", weighted_metric_weights = NULL, cell = NULL, interpolation_vertices = NULL, boundary_degree_fallback = NULL, missing = "error", outputs = NULL )
fraction |
Smoothing fraction, greater than 0 and up to 1. Default: 0.67. See Details for guidance on choosing a value. |
chunk_size |
Number of data points per processing chunk, at least 10. Default: 5000. |
... |
Not used; forces all subsequent arguments to be named. |
overlap |
Number of overlapping points between consecutive chunks,
less than |
iterations |
Number of robustness iterations, between 0 and 1000 (inclusive). Default: 3. |
weight_function |
Kernel weight function. One of |
robustness_method |
Outlier downweighting method: |
scaling_method |
Residual scale estimation for robustness weights:
|
boundary_policy |
Boundary handling strategy: |
zero_weight_fallback |
Fallback policy when all robustness weights drop
to zero: |
auto_converge |
Convergence tolerance for early stopping of robustness
iterations. |
intervals |
Grouped coverage levels from |
merge_strategy |
Strategy for reconciling overlapping chunk regions:
|
parallel |
Logical; enable parallel processing. Default: |
degree |
Local polynomial degree: |
dimensions |
Number of predictor dimensions. Default: 1. |
distance_metric |
Distance metric for neighbourhood computation:
|
surface_mode |
Surface evaluation mode: |
weighted_metric_weights |
Numeric vector of per-dimension weights.
Length must equal |
cell |
Cell size tuning parameter for the interpolation grid.
|
interpolation_vertices |
Number of vertices in the interpolation grid.
|
boundary_degree_fallback |
Logical; if |
missing |
Policy for non-finite (NaN/Inf) values in the input data:
|
outputs |
Optional character vector selecting |
When outputs includes "diagnostics", residual_sd is the cumulative
sample standard deviation of emitted residuals. Batch residual_sd instead
uses the robust residual scale estimate 1.4826 * MAD.
Best suited for datasets over 100,000 points, memory-constrained
environments, or batch processing pipelines. For smaller datasets that fit
in memory, see Loess; for point-by-point real-time data,
see OnlineLoess.
Overlapping regions between chunks are reconciled via merge_strategy:
| Strategy | Behavior |
"average" |
Arithmetic mean of both estimates |
"weighted_average" |
Distance-weighted blend (default) |
"take_first" |
Keep left-chunk estimate |
"take_last" |
Keep right-chunk estimate |
A StreamingLoess object.
x <- seq(0, 10, length.out = 100) y <- sin(x) + rnorm(100, 0, 0.1) model <- StreamingLoess(fraction = 0.2, chunk_size = 50) res1 <- process_chunk(model, x[1:50], y[1:50]) res2 <- process_chunk(model, x[51:100], y[51:100]) finalize(model)x <- seq(0, 10, length.out = 100) y <- sin(x) + rnorm(100, 0, 0.1) model <- StreamingLoess(fraction = 0.2, chunk_size = 50) res1 <- process_chunk(model, x[1:50], y[1:50]) res2 <- process_chunk(model, x[51:100], y[51:100]) finalize(model)
Compute diagnostics for the current Online window
window_diagnostics(model, ...)window_diagnostics(model, ...)
model |
An OnlineLoess object. |
... |
Must be empty. |
A list of goodness-of-fit metrics, or NULL until the window
reaches min_points.
model <- OnlineLoess(fraction = 1, window_capacity = 20L) for (x in 1:10) { invisible(add_point(model, x, 2 * x + 1)) } window_diagnostics(model)model <- OnlineLoess(fraction = 1, window_capacity = 20L) for (x in 1:10) { invisible(add_point(model, x, 2 * x + 1)) } window_diagnostics(model)