Adapter support: Batch and Streaming support confidence and prediction intervals; Online supports them in
update_mode = "full"only.
| Type | Represents | Width | Use |
|---|---|---|---|
| Confidence | Uncertainty in mean curve | Narrow | Where is the trend? |
| Prediction | Uncertainty for new points | Wide | Where will data fall? |
Estimate uncertainty in the smoothed curve itself.
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 with bands
plot(x, y, pch = 16, col = "gray",
main = "LOESS with 95% Confidence Intervals")
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)
cat("95% CI at midpoint: [", result$confidence_lower[50], ", ",
result$confidence_upper[50], "]\n")
#> 95% CI at midpoint: [ -0.1007995 , 0.1749161 ]Estimate where new observations might fall.
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(prediction = 0.95))
result <- fit(model, x, y)
plot(x, y, pch = 16, col = "gray",
main = "LOESS with 95% Prediction Intervals")
lines(result$x, result$y, col = "blue", lwd = 2)
lines(result$x, result$prediction_lower, col = "red", lty = 2)
lines(result$x, result$prediction_upper, col = "red", lty = 2)
cat("Prediction bounds: [", result$prediction_lower[1], ", ",
result$prediction_upper[1], "]\n")
#> Prediction bounds: [ -0.1436505 , 1.095328 ]Request both types simultaneously:
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, prediction = 0.95)
)
result <- fit(model, x, y)
plot(x, y, pch = 16, col = "gray",
main = "Confidence vs Prediction Intervals")
lines(result$x, result$y, col = "blue", lwd = 2)
# Confidence interval (narrow, blue)
lines(result$x, result$confidence_lower, col = "blue", lty = 2)
lines(result$x, result$confidence_upper, col = "blue", lty = 2)
# Prediction interval (wide, red)
lines(result$x, result$prediction_lower, col = "red", lty = 3)
lines(result$x, result$prediction_upper, col = "red", lty = 3)
legend("topright",
c("Data", "Smoothed", "95% CI", "95% PI"),
pch = c(16, NA, NA, NA), lty = c(NA, 1, 2, 3),
col = c("gray", "blue", "blue", "red"))
cat("95% CI at midpoint: [", result$confidence_lower[50], ", ",
result$confidence_upper[50], "]\n")
#> 95% CI at midpoint: [ -0.1007995 , 0.1749161 ]Common levels and their z-values:
| Level | z-value | Interpretation |
|---|---|---|
| 0.90 | 1.645 | 90% of intervals contain true value |
| 0.95 | 1.960 | 95% of intervals contain true value |
| 0.99 | 2.576 | 99% of intervals contain true value |
# 99% confidence interval
model <- Loess(fraction = 0.5, intervals = intervals_opts(confidence = 0.99))
result <- fit(model, x, y)
cat("First lower CI bound (99%):", result$confidence_lower[1], "\n")
#> First lower CI bound (99%): 0.296526Access standard errors directly (available when intervals are computed):
model <- Loess(fraction = 0.5, outputs = "se")
result <- fit(model, x, y)
cat("Standard errors (first 5):", head(result$standard_errors, 5), "\n")
#> Standard errors (first 5): 0.06960904 0.07028408 0.07095493 0.07156272 0.07204299Adapter support: Confidence and prediction intervals are available in Batch and Streaming; Online supports them in
update_mode = "full"only. intervals.
| Feature | Batch | Streaming | Online |
|---|---|---|---|
| Confidence intervals | ✓ | ✗ | ✗ |
| Prediction intervals | ✓ | ✗ | ✗ |
| Standard errors | ✓ | ✗ | ✗ |
sessionInfo()
#> R version 4.6.1 (2026-06-24)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 26.04.1 LTS
#>
#> Matrix products: default
#> BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
#> LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.32.so; LAPACK version 3.12.0
#>
#> locale:
#> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
#> [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
#> [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
#> [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
#> [9] LC_ADDRESS=C LC_TELEPHONE=C
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
#>
#> time zone: Etc/UTC
#> tzcode source: system (glibc)
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] rfastloess_3.0.0 rmarkdown_2.32
#>
#> loaded via a namespace (and not attached):
#> [1] digest_0.6.39 R6_2.6.1 fastmap_1.2.0 xfun_0.61
#> [5] maketools_1.3.2 cachem_1.1.0 knitr_1.52 htmltools_0.5.9
#> [9] buildtools_1.0.0 lifecycle_1.0.5 cli_3.6.6 sass_0.4.10
#> [13] jquerylib_0.1.4 compiler_4.6.1 sys_3.4.3 tools_4.6.1
#> [17] evaluate_1.0.5 bslib_0.12.0 yaml_2.3.12 otel_0.2.0
#> [21] jsonlite_2.0.0 rlang_1.3.0