Intervals

Confidence and prediction intervals for uncertainty quantification.

Overview

Confidence and Prediction Intervals

Adapter support

Confidence and prediction intervals are available in Batch mode, Streaming mode (computed per chunk and merged across overlap boundaries via merge_strategy, like y/derivative), and Online mode when update_mode="full" is set (errors if combined with the default "incremental" mode).

Confidence and prediction coverage levels are independent; for example, a 90% confidence interval can be paired with a 99% prediction interval.

TypeRepresentsWidthUse
ConfidenceUncertainty in mean curveNarrowWhere is the true trend?
PredictionUncertainty for new pointsWideWhere will new data fall?

Confidence Intervals

Estimate uncertainty in the smoothed curve itself.

using FastLOWESS
using Random, Statistics

rng = MersenneTwister(42)
x = collect(range(0, 2π, length=100))
y = sin.(x) .+ randn(rng, 100) .* 0.3

model = Lowess(; fraction=0.5, intervals=(confidence=0.95,))
result = fit(model, x, y)

println("Smoothed (first 5): ", result.y[1:5])
println("CI Lower (first 5): ", result.confidence_lower[1:5])
println("CI Upper (first 5): ", result.confidence_upper[1:5])
Smoothed (first 5): [0.4003134529833126, 0.41060415969103753, 0.42251389238771603, 0.4360677268953081, 0.45121012253337694]
CI Lower (first 5): [0.351241290399097, 0.3587052764339, 0.3675001147634977, 0.37772154817984127, 0.3894057745265893]
CI Upper (first 5): [0.4493856155675282, 0.46250304294817507, 0.47752767001193436, 0.4944139056107749, 0.5130144705401646]

Prediction Intervals

Estimate where new observations might fall.

using FastLOWESS
using Random, Statistics

rng = MersenneTwister(42)
x = collect(range(0, 2π, length=100))
y = sin.(x) .+ randn(rng, 100) .* 0.3

model = Lowess(; fraction=0.5, intervals=(prediction=0.95,))
result = fit(model, x, y)

println("Prediction bounds: [$(result.prediction_lower[1]), $(result.prediction_upper[1])]")
Prediction bounds: [-0.199836681495917, 1.0004635874625423]

Both Intervals

Request both types simultaneously:

using FastLOWESS
using Random, Statistics

rng = MersenneTwister(42)
x = collect(range(0, 2π, length=100))
y = sin.(x) .+ randn(rng, 100) .* 0.3

result = fit(
    Lowess(fraction=0.5, intervals=(confidence=0.95, prediction=0.95)),
    x, y
)
println("95% CI at midpoint: [$(round(result.confidence_lower[50]; digits=3)), $(round(result.confidence_upper[50]; digits=3))]")
95% CI at midpoint: [0.031, 0.226]

Confidence Levels

Common levels and their z-values:

Levelz-valueInterpretation
0.901.64590% of intervals contain true value
0.951.96095% of intervals contain true value
0.992.57699% of intervals contain true value
using FastLOWESS
using Random, Statistics

rng = MersenneTwister(42)
x = collect(range(0, 2π, length=100))
y = sin.(x) .+ randn(rng, 100) .* 0.3

# 99% confidence interval
model = Lowess(; intervals=(confidence=0.99,))
result = fit(model, x, y)
println("99% CI at midpoint: [$(round(result.confidence_lower[50]; digits=3)), $(round(result.confidence_upper[50]; digits=3))]")
99% CI at midpoint: [-0.004, 0.256]

Standard Errors

Access standard errors directly (available when intervals are computed):

using FastLOWESS
using Random, Statistics

rng = MersenneTwister(42)
x = collect(range(0, 2π, length=100))
y = sin.(x) .+ randn(rng, 100) .* 0.3

model = Lowess(; intervals=(confidence=0.95,))
result = fit(model, x, y)

println("Standard errors (first 5): ", result.standard_errors[1:5])
Standard errors (first 5): [0.027926249777257686, 0.029263442028566525, 0.03059657274541432, 0.03192000212011192, 0.033225462074346145]

Residual Bootstrap

Set bootstrap to at least 2 to replace analytic uncertainty with residual-bootstrap refits. Batch shares its outer seed with CV; Streaming restarts the seed per combined chunk, and Online per full-update window. Online bootstrap requires update_mode="full".

using FastLOWESS

x = collect(0.0:0.1:2.9)
y = sin.(x) .+ 0.1 .* cos.(7 .* x)
intervals = (confidence=0.95, prediction=0.95, bootstrap=20)

batch = fit(Lowess(; intervals=intervals, seed=42), x, y)
println("Batch SEs: ", length(batch.standard_errors))

chunk = process_chunk(StreamingLowess(; chunk_size=length(x), intervals=intervals, seed=42), x, y)
println("Streaming CI present: ", chunk.confidence_lower !== nothing)

online = OnlineLowess(; min_points=5, update_mode="full", intervals=intervals, seed=42)
last_point = filter(!isnothing, [add_point(online, xi, yi) for (xi, yi) in zip(x[1:12], y[1:12])])[end]
println("Online PI present: ", last_point.prediction_lower !== nothing)
Batch SEs: 30
Streaming CI present: true
Online PI present: true

Availability

Supported In All Three Adapters

Confidence and prediction intervals are available in Batch, Streaming, and Online mode (update_mode="full" only).

FeatureBatchStreamingOnline
Confidence intervals✓✓✓ (update_mode="full" only)
Prediction intervals✓✓✓ (update_mode="full" only)
Standard errors✓✓✓ (update_mode="full" only)
Residual bootstrap✓✓✓ (update_mode="full" only)