| Title: | High-Performance LOWESS Smoothing for R |
|---|---|
| Description: | Provides high-performance LOWESS smoothing (Locally Weighted 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>), Aleksei Chirkunov [rev] (Reviewed the package for rOpenSci (GitHub: @alexzerg), see <https://github.com/ropensci/software-review/issues/769>), Josiah Parry [rev] (ORCID: <https://orcid.org/0000-0001-9910-865X>, Reviewed the package for rOpenSci (GitHub: @JosiahParry), see <https://github.com/ropensci/software-review/issues/769>), Etienne Bacher [edt] (Edited the package for rOpenSci (GitHub: @etiennebacher), see <https://github.com/ropensci/software-review/issues/769>) |
| Maintainer: | Amir Valizadeh <[email protected]> |
| License: | MIT + file LICENSE | Apache License (== 2.0) |
| Version: | 5.0.0 |
| Built: | 2026-10-12 23:11:36 UTC |
| Source: | https://github.com/thisisamirv/lowess-project |
Add a single point to an online LOWESS model
add_point(model, ...) ## S3 method for class 'OnlineLowess' add_point(model, x, y, ...)add_point(model, ...) ## S3 method for class 'OnlineLowess' add_point(model, x, y, ...)
model |
An |
... |
Must be empty. |
x |
A single numeric x value. |
y |
A single numeric y value. |
An online result list, or NULL if fewer than
min_points have been added.
model <- OnlineLowess(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 <- OnlineLowess(fraction = 0.2, window_capacity = 20L, min_points = 2L) invisible(add_point(model, 1.0, 0.5)) add_point(model, 2.0, 0.6)
Lowess
Build a cross-validation options list to pass to
Lowess(cv = ...). Cross-validation is disabled by default
(cv = NULL); supplying cv_opts() enables it and lets the
model pick the best smoothing fraction from the candidates.
cv_opts(method = "kfold", k = 5L, fractions)cv_opts(method = "kfold", k = 5L, fractions)
method |
Cross-validation method: |
k |
Number of folds for k-fold cross-validation. Default: 5. |
fractions |
Numeric vector of candidate smoothing fractions, each
greater than 0 and up to 1 (e.g. |
A cv_opts list for Lowess(cv = ...).
Use Lowess(seed = ...) for reproducible fold assignment.
model <- Lowess( cv = cv_opts(method = "kfold", k = 5, fractions = c(0.2, 0.3, 0.5)), seed = 42 )model <- Lowess( cv = cv_opts(method = "kfold", k = 5, fractions = c(0.2, 0.3, 0.5)), seed = 42 )
Finalize a streaming LOWESS model
finalize(model, ...)finalize(model, ...)
model |
A |
... |
Must be empty. |
A LowessResult combining all processed chunks.
x <- seq(0, 10, length.out = 100) y <- sin(x) + rnorm(100, 0, 0.1) model <- StreamingLowess(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 <- StreamingLowess(fraction = 0.2, chunk_size = 50L) invisible(process_chunk(model, x[1:50], y[1:50])) finalize(model)
Fit a LOWESS model to data
fit(model, ...) ## S3 method for class 'Lowess' fit(model, x, y, custom_weights = NULL, ...)fit(model, ...) ## S3 method for class 'Lowess' 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 LowessResult object.
x <- seq(0, 10, length.out = 100) y <- sin(x) + rnorm(100, 0, 0.1) model <- Lowess(fraction = 0.2) fit(model, x, y)x <- seq(0, 10, length.out = 100) y <- sin(x) + rnorm(100, 0, 0.1) model <- Lowess(fraction = 0.2) fit(model, x, y)
Returns whether the currently loaded rfastlowess shared library was built with the GPU backend enabled.
gpu_available()gpu_available()
Logical; TRUE if the GPU backend is active.
install_gpu to download and install it.
gpu_available()gpu_available()
Downloads a prebuilt GPU-enabled rfastlowess shared library for the current platform from the matching GitHub Release. On Windows, installs a versioned sidecar alongside the CPU library and activates its native routines when the package is loaded after restarting R. Other platforms atomically replace the CPU library. GPU support is opt-in and not included in CRAN/Bioconductor releases.
A running R session cannot swap an already-loaded shared library, so restart R after installing for the change to take effect.
Downloads are checked against GitHub's published SHA-256 digest before execution. Native probes have a 30-second timeout and require matching package-version/ABI contracts and registered argument counts. Older GPU artifacts without this contract must be rebuilt. On Windows, invalid sidecars are skipped and activated DLLs remain mapped until R exits to protect live model finalizers. Probing is not a security sandbox; local native libraries must be trusted.
install_gpu(yes = FALSE, local_path = NULL)install_gpu(yes = FALSE, local_path = NULL)
yes |
Logical; skip the interactive |
local_path |
Character; path to a GPU-enabled shared library already
built locally (e.g. via |
Invisibly, TRUE if a GPU-enabled library is available at
the printed path (already active, or freshly installed); FALSE
if the user aborted.
gpu_available to check the current status.
# Check whether the GPU backend is already active before installing it gpu_available() if (interactive()) { install_gpu() }# Check whether the GPU backend is already active before installing it gpu_available() if (interactive()) { install_gpu() }
Build an interval options list to pass to intervals = ... in
Lowess, StreamingLowess,
OnlineLowess, or predict.Lowess.
intervals_opts(confidence = NULL, prediction = NULL, bootstrap = 0L)intervals_opts(confidence = NULL, prediction = NULL, bootstrap = 0L)
confidence |
Coverage for confidence intervals, greater than 0 and
less than 1 (e.g. 0.90). |
prediction |
Coverage for prediction intervals, greater than 0 and
less than 1 (e.g. 0.99). |
bootstrap |
Number of bootstrap resamples used to compute the
intervals. |
An intervals_opts list.
model <- Lowess( intervals = intervals_opts( confidence = 0.90, prediction = 0.99, bootstrap = 200 ), seed = 42 )model <- Lowess( intervals = intervals_opts( confidence = 0.90, prediction = 0.99, bootstrap = 200 ), seed = 42 )
Create a stateful LOWESS model for batch smoothing. This is the default mode: it processes the entire dataset at once and supports every feature (confidence/prediction intervals, cross-validation, GPU backend).
Lowess( fraction = 0.67, ..., iterations = 3L, weight_function = "tricube", robustness_method = "bisquare", delta = NULL, zero_weight_fallback = "use_local_mean", boundary_policy = "extend", scaling_method = "mad", auto_converge = NULL, missing = "error", parallel = TRUE, backend = "cpu", outputs = NULL, intervals = NULL, cv = NULL, seed = NULL, retain_model = FALSE )Lowess( fraction = 0.67, ..., iterations = 3L, weight_function = "tricube", robustness_method = "bisquare", delta = NULL, zero_weight_fallback = "use_local_mean", boundary_policy = "extend", scaling_method = "mad", auto_converge = NULL, missing = "error", parallel = TRUE, backend = "cpu", outputs = NULL, intervals = NULL, cv = NULL, seed = NULL, retain_model = FALSE )
fraction |
Smoothing fraction, greater than 0 and up to 1. Default: 0.67. |
... |
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: |
delta |
Interpolation distance threshold, as a non-negative fraction
of the x range; points within |
zero_weight_fallback |
Fallback policy when all robustness weights drop
to zero: |
boundary_policy |
Boundary handling strategy: |
scaling_method |
Residual scale estimation for robustness weights:
|
auto_converge |
Convergence tolerance for early stopping of robustness
iterations. |
missing |
Policy for non-finite (NaN/Infinity) values in input data:
|
parallel |
Logical; enable parallel processing. Default: |
backend |
Execution backend: |
outputs |
Character vector selecting optional output components:
|
intervals |
Interval options, created with
|
cv |
Cross-validation options, created with |
seed |
Non-negative whole-number seed shared by cross-validation and
bootstrap resampling for reproducible results. When cross-validation is
unavailable, it controls bootstrap resampling only.
|
retain_model |
Logical; if |
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 StreamingLowess; for point-by-point
real-time data, see OnlineLowess.
When "diagnostics" is selected, residual_sd is the robust
residual scale estimate (1.4826 * MAD).
fraction is the most important parameter: it controls the size of the
local neighbourhood used at each point.
| 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 Lowess object.
x <- seq(0, 10, length.out = 100) y <- sin(x) + rnorm(100, 0, 0.1) model <- Lowess(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 <- Lowess(fraction = 0.2) result <- fit(model, x, y) plot(x, y) lines(x, result$y, col = "red")
Create a stateful LOWESS model for real-time online data. Maintains a
sliding window and processes each incoming point immediately via
add_point.
OnlineLowess( fraction = 0.67, ..., iterations = 0L, weight_function = "tricube", robustness_method = "bisquare", delta = NULL, zero_weight_fallback = "use_local_mean", boundary_policy = "extend", scaling_method = "mad", auto_converge = NULL, missing = "error", window_capacity = 1000L, min_points = 2L, update_mode = "incremental", outputs = NULL, intervals = NULL, seed = NULL )OnlineLowess( fraction = 0.67, ..., iterations = 0L, weight_function = "tricube", robustness_method = "bisquare", delta = NULL, zero_weight_fallback = "use_local_mean", boundary_policy = "extend", scaling_method = "mad", auto_converge = NULL, missing = "error", window_capacity = 1000L, min_points = 2L, update_mode = "incremental", outputs = NULL, intervals = NULL, seed = NULL )
fraction |
Smoothing fraction, greater than 0 and up to 1. Default: 0.67. |
... |
Not used; forces all subsequent arguments to be named. |
iterations |
Number of robustness iterations. Requires
|
weight_function |
Kernel weight function. One of |
robustness_method |
Outlier downweighting method: |
delta |
Interpolation distance as a non-negative fraction of the x
range. In Online mode, |
zero_weight_fallback |
Fallback policy when all robustness weights drop
to zero: |
boundary_policy |
Boundary handling strategy: |
scaling_method |
Residual scale estimation for robustness weights:
|
auto_converge |
Convergence tolerance for early stopping. Requires
|
missing |
Policy for non-finite (NaN/Infinity) values in input data:
|
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 |
update_mode |
Window update strategy: |
outputs |
Character vector selecting optional Online output components:
|
intervals |
Interval options, created with
|
seed |
Non-negative whole-number seed shared by cross-validation and
bootstrap resampling for reproducible results. When cross-validation is
unavailable, it controls bootstrap resampling only.
|
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 Lowess; for large batches processed
in chunks, see StreamingLowess.
Confidence and prediction interval coverage levels are independent; both
interval types require update_mode = "full".
Positive delta values also require update_mode = "full".
A non-NULL auto_converge requires full mode and at least one
robustness iteration; unsupported combinations are rejected.
An OnlineLowess object.
model <- OnlineLowess(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 <- OnlineLowess(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)
Plot Lowess Result
## S3 method for class 'LowessResult' plot(x, main = "LOWESS Fit", ...)## S3 method for class 'LowessResult' plot(x, main = "LOWESS Fit", ...)
x |
A LowessResult 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 <- Lowess(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 <- Lowess(fraction = 0.2) res <- fit(model, x, y) plot(res)
Predict from a fitted LOWESS model at out-of-sample points
## S3 method for class 'Lowess' predict( object, new_x, outputs = NULL, intervals = NULL, seed = NULL, extrapolation = "clamp", max_extrapolation_distance = NULL, max_neighbor_distance = NULL, ... )## S3 method for class 'Lowess' predict( object, new_x, outputs = NULL, intervals = NULL, seed = NULL, extrapolation = "clamp", max_extrapolation_distance = NULL, max_neighbor_distance = NULL, ... )
object |
A |
new_x |
Numeric vector of out-of-sample query points. |
outputs |
Character vector selecting optional prediction components:
|
intervals |
Interval options, created with
|
seed |
Non-negative whole-number seed for bootstrap resampling.
|
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 local window before |
... |
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 <- Lowess(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 <- Lowess(fraction = 0.2, retain_model = TRUE) fit(model, x, y) predict(model, c(2.5, 7.5))
Print Lowess Model
## S3 method for class 'Lowess' print(x, ...)## S3 method for class 'Lowess' print(x, ...)
x |
A Lowess object. |
... |
Additional arguments (ignored). |
The input object x, invisibly.
model <- Lowess(fraction = 0.3) print(model)model <- Lowess(fraction = 0.3) print(model)
Print Lowess Result
## S3 method for class 'LowessResult' print(x, ...)## S3 method for class 'LowessResult' print(x, ...)
x |
A LowessResult 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 <- Lowess(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 <- Lowess(fraction = 0.3) result <- fit(model, x, y) print(result)
Print OnlineLowess Model
## S3 method for class 'OnlineLowess' print(x, ...)## S3 method for class 'OnlineLowess' print(x, ...)
x |
An OnlineLowess object. |
... |
Additional arguments. |
The input object x, invisibly.
model <- OnlineLowess(fraction = 0.2, window_capacity = 20L) print(model)model <- OnlineLowess(fraction = 0.2, window_capacity = 20L) print(model)
Print StreamingLowess Model
## S3 method for class 'StreamingLowess' print(x, ...)## S3 method for class 'StreamingLowess' print(x, ...)
x |
A StreamingLowess object. |
... |
Additional arguments. |
The input object x, invisibly.
model <- StreamingLowess(fraction = 0.3, chunk_size = 50L) print(model)model <- StreamingLowess(fraction = 0.3, chunk_size = 50L) print(model)
Process a data chunk through a streaming LOWESS model
process_chunk(model, ...) ## S3 method for class 'StreamingLowess' process_chunk(model, x, y, ...)process_chunk(model, ...) ## S3 method for class 'StreamingLowess' process_chunk(model, x, y, ...)
model |
A |
... |
Must be empty. |
x |
Numeric vector of x values. |
y |
Numeric vector of y values. |
A LowessResult for this chunk.
x <- seq(0, 10, length.out = 100) y <- sin(x) + rnorm(100, 0, 0.1) model <- StreamingLowess(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 <- StreamingLowess(fraction = 0.2, chunk_size = 50L) process_chunk(model, x[1:50], y[1:50])
Create a stateful LOWESS 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.
StreamingLowess( fraction = 0.67, ..., iterations = 3L, weight_function = "tricube", robustness_method = "bisquare", delta = NULL, zero_weight_fallback = "use_local_mean", boundary_policy = "extend", scaling_method = "mad", auto_converge = NULL, missing = "error", chunk_size = 5000L, overlap = NULL, merge_strategy = "weighted_average", parallel = TRUE, outputs = NULL, intervals = NULL, seed = NULL )StreamingLowess( fraction = 0.67, ..., iterations = 3L, weight_function = "tricube", robustness_method = "bisquare", delta = NULL, zero_weight_fallback = "use_local_mean", boundary_policy = "extend", scaling_method = "mad", auto_converge = NULL, missing = "error", chunk_size = 5000L, overlap = NULL, merge_strategy = "weighted_average", parallel = TRUE, outputs = NULL, intervals = NULL, seed = NULL )
fraction |
Smoothing fraction, greater than 0 and up to 1. Default: 0.67. |
... |
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: |
delta |
Interpolation distance threshold, as a non-negative fraction
of the x range; points within |
zero_weight_fallback |
Fallback policy when all robustness weights drop
to zero: |
boundary_policy |
Boundary handling strategy: |
scaling_method |
Residual scale estimation for robustness weights:
|
auto_converge |
Convergence tolerance for early stopping of robustness
iterations. |
missing |
Policy for non-finite (NaN/Infinity) values in input data:
|
chunk_size |
Number of data points per processing chunk, at least 10. Default: 5000. |
overlap |
Number of overlapping points between consecutive chunks,
less than |
merge_strategy |
Strategy for reconciling overlapping chunk regions:
|
parallel |
Logical; enable parallel processing. Default: |
outputs |
Streaming output choices:
|
intervals |
Interval options, created with
|
seed |
Non-negative whole-number seed shared by cross-validation and
bootstrap resampling for reproducible results. When cross-validation is
unavailable, it controls bootstrap resampling only.
|
Best suited for datasets over 100,000 points, memory-constrained
environments, or batch processing pipelines. For smaller datasets that fit
in memory, see Lowess; for point-by-point real-time data,
see OnlineLowess.
When "diagnostics" is selected, residual_sd is the cumulative
sample standard deviation of emitted residuals.
Confidence and prediction interval coverage levels are independent.
Overlapping regions between chunks are reconciled via merge_strategy:
| Strategy | Alias | Behavior |
| "weighted_average" (default) | "weighted" | Distance-weighted blend |
| "average" | "mean" | Average overlapping values |
| "take_first" | "first" | Keep left chunk values |
| "take_last" | "last" | Keep right chunk values |
A StreamingLowess object.
x <- seq(0, 10, length.out = 100) y <- sin(x) + rnorm(100, 0, 0.1) model <- StreamingLowess(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 <- StreamingLowess(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)