---
title: "Quick Start"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Quick Start}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
```
Get up and running with LOWESS in minutes.
## Basic Smoothing
Smooth a noisy sine wave — the kind of signal where LOWESS shines. Each
example recovers the underlying trend from 100 points of Gaussian noise.
```{r quickstart_1}
library(rfastlowess)
# 100-point noisy sine wave
set.seed(42)
x <- seq(0, 2 * pi, length.out = 100)
y <- sin(x) + rnorm(100, sd = 0.3)
model <- Lowess(fraction = 0.3, iterations = 3)
result <- fit(model, x, y)
cat(sprintf("First smoothed value: %.4f (true: %.4f)\n",
result$y[1], sin(x[1])))
```
---
## With Confidence Intervals
```{r quickstart_2}
library(rfastlowess)
set.seed(42)
x <- seq(0, 2 * pi, length.out = 100)
y <- sin(x) + rnorm(100, sd = 0.3)
model <- Lowess(
fraction = 0.5,
iterations = 3,
outputs = "diagnostics",
intervals = intervals_opts(confidence = 0.90, prediction = 0.99)
)
result <- fit(model, x, y)
cat("Smoothed (first 5):", head(result$y, 5), "\n")
cat("CI lower (first 5):", head(result$confidence_lower, 5), "\n")
cat("CI upper (first 5):", head(result$confidence_upper, 5), "\n")
cat("R2:", result$diagnostics$r_squared, "\n")
```
---
## Handling Outliers
LOWESS can robustly handle outliers through iterative reweighting:
```{r quickstart_3}
library(rfastlowess)
x_out <- seq(1, 6, length.out = 6)
y_with_outlier <- c(2.0, 4.0, 6.0, 50.0, 10.0, 12.0)
model <- Lowess(
fraction = 0.7,
iterations = 5,
robustness_method = "bisquare",
outputs = "weights"
)
result <- fit(model, x_out, y_with_outlier)
# Outliers will have low robustness weights
for (i in seq_along(result$robustness_weights)) {
if (result$robustness_weights[i] < 0.5)
cat(sprintf("Point %d is likely an outlier (weight: %.3f)\n",
i, result$robustness_weights[i]))
}
```
---
## Streaming Mode
For datasets too large to fit in memory, stream them in fixed-size chunks with
overlap.
```{r quickstart_4}
library(rfastlowess)
set.seed(42)
x <- seq(0, 10 * pi, length.out = 5000)
y <- sin(x / pi) * exp(-x / 30) + rnorm(5000, sd = 0.15)
model <- StreamingLowess(
fraction = 0.2,
chunk_size = 1000,
overlap = 100,
merge_strategy = "weighted_average"
)
chunk_size <- 1000
for (start in seq(1, 4001, by = chunk_size)) {
end <- min(start + chunk_size - 1, length(x))
process_chunk(model, x[start:end], y[start:end])
}
result <- finalize(model)
cat(sprintf("Smoothed %d points in streaming mode\n", length(result$y)))
```
---
## Next Steps
| Topic | Link |
| --- | --- |
| How LOWESS works | [Concepts](concepts.html) |
| All parameters explained | `?Lowess` |
| Batch vs Streaming vs Online | [Execution Modes](adapter-choice.html) |
| Edge handling | [Boundary](boundary.html) |
| Outlier handling in depth | [Robustness](robustness.html) |
```{r session-info}
sessionInfo()
```