---
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 = "#>")
```
## Basic Smoothing
Smooth a noisy sine wave — the kind of signal where LOESS shines. `fraction
= 0.3` and `iterations = 3` are good starting values for most signals.
```{r quickstart_1}
library(rfastloess)
# 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 <- Loess(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(rfastloess)
set.seed(42)
x <- seq(0, 2 * pi, length.out = 100)
y <- sin(x) + rnorm(100, sd = 0.3)
model <- Loess(
fraction = 0.5,
iterations = 3,
outputs = "diagnostics",
intervals = intervals_opts(confidence = 0.95, prediction = 0.95)
)
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
LOESS can robustly handle outliers through iterative reweighting:
```{r quickstart_3}
library(rfastloess)
x_out <- 1:6
y_with_outlier <- c(2.0, 4.0, 6.0, 50.0, 10.0, 12.0)
model <- Loess(
fraction = 0.7,
iterations = 5,
robustness_method = "bisquare",
outputs = "weights"
)
result <- fit(model, x_out, y_with_outlier)
# Check which points were downweighted
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(rfastloess)
set.seed(42)
x <- seq(0, 10 * pi, length.out = 5000)
y <- sin(x / pi) * exp(-x / 30) + rnorm(5000, sd = 0.15)
model <- StreamingLoess(
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("Smoothed", length(result$y), "points in streaming mode\n")
```
---
## Online Mode
For real-time / point-by-point processing.
```{r quickstart_5}
library(rfastloess)
set.seed(42)
times <- 1:100
temperatures <- 20 + 5 * sin(times / 10) + rnorm(100)
model <- OnlineLoess(
fraction = 0.3,
window_capacity = 25,
min_points = 5,
update_mode = "incremental"
)
for (i in seq_along(times)) {
result <- add_point(model, times[i], temperatures[i])
if (!is.null(result))
cat(sprintf("Time %d: %.2f\n", times[i], result$y))
if (i >= 10) break # print only the first few outputs
}
```
---
## Plotting Results
```{r quickstart_6}
library(rfastloess)
set.seed(42)
x <- seq(0, 2 * pi, length.out = 100)
y <- sin(x) + rnorm(100, sd = 0.3)
model <- Loess(fraction = 0.5, intervals = intervals_opts(confidence = 0.95))
result <- fit(model, x, y)
plot(x, y, pch = 16, col = "gray", main = "LOESS Smoothing")
lines(result$x, result$y, col = "blue", lwd = 2)
lines(result$x, result$confidence_lower, col = "blue", lty = 2)
lines(result$x, result$confidence_upper, col = "blue", lty = 2)
legend("topright", c("Data", "Smoothed", "95% CI"),
pch = c(16, NA, NA), lty = c(NA, 1, 2),
col = c("gray", "blue", "blue"))
```
---
## Next Steps
| Topic | Link |
| --- | --- |
| How LOESS works | `vignette("concepts", package = "rfastloess")` |
| Comparing with `stats::loess()` | `vignette("alternative-software", package = "rfastloess")` |
| All parameters explained | `?Loess` |
| Batch vs Streaming vs Online | `vignette("adapter-choice")` |
| Polynomial degree choices | `vignette("degree", package = "rfastloess")` |
| Multivariate smoothing | `vignette("dimensions", package = "rfastloess")` |
| Edge handling | `vignette("boundary", package = "rfastloess")` |
| Outlier handling in depth | `vignette("robustness", package = "rfastloess")` |
```{r session-info}
sessionInfo()
```