Intervals
Confidence and prediction intervals for uncertainty quantification.
Overview
Section titled “Overview”Confidence and prediction coverage levels are independent; for example, a 90% confidence interval can be paired with a 99% prediction interval.
| Type | Represents | Width | Use |
|---|---|---|---|
| Confidence | Uncertainty in mean curve | Narrow | Where is the true trend? |
| Prediction | Uncertainty for new points | Wide | Where will new data fall? |
Confidence Intervals
Section titled “Confidence Intervals”Estimate uncertainty in the smoothed curve itself.
const { Lowess } = require('fastlowess-wasm');
const n = 100;const x = Float64Array.from({ length: n }, (_, i) => i * 2 * Math.PI / (n - 1));const y = Float64Array.from(x, xi => Math.sin(xi) + 0.1);
const model = new Lowess({fraction: 0.5, intervals: {confidence: 0.95}});const result = model.fit(x, y);
result.y.slice(0, 5).forEach((y, i) => { console.log(`x=${result.x[i].toFixed(4)}: y=${y.toFixed(4)} [${result.confidence_lower[i].toFixed(4)}, ${result.confidence_upper[i].toFixed(4)}]`);});x=0.0000: y=0.3325 [0.2929, 0.3722]x=0.0635: y=0.3593 [0.3190, 0.3995]x=0.1269: y=0.3871 [0.3462, 0.4280]x=0.1904: y=0.4160 [0.3743, 0.4576]x=0.2539: y=0.4458 [0.4034, 0.4881]Prediction Intervals
Section titled “Prediction Intervals”Estimate where new observations might fall.
const { Lowess } = require('fastlowess-wasm');
const n = 100;const x = Float64Array.from({ length: n }, (_, i) => i * 2 * Math.PI / (n - 1));const y = Float64Array.from(x, xi => Math.sin(xi) + 0.1);
const model = new Lowess({fraction: 0.5, intervals: {prediction: 0.95}});const result = model.fit(x, y);console.log(`Prediction bounds: [${result.prediction_lower[0]}, ${result.prediction_upper[0]}]`);Prediction bounds: [-0.04054603685842645, 0.7056287954394038]Both Intervals
Section titled “Both Intervals”Request both types simultaneously:
const { Lowess } = require('fastlowess-wasm');
const n = 100;const x = Float64Array.from({ length: n }, (_, i) => i * 2 * Math.PI / (n - 1));const y = Float64Array.from(x, xi => Math.sin(xi) + 0.1);
const model = new Lowess({fraction: 0.5, intervals: {confidence: 0.95, prediction: 0.95}});const result = model.fit(x, y);console.log("CI lower[0]:", result.confidence_lower[0].toFixed(4));CI lower[0]: 0.2929Confidence Levels
Section titled “Confidence Levels”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 |
const { Lowess } = require('fastlowess-wasm');
const n = 100;const x = Float64Array.from({ length: n }, (_, i) => i * 2 * Math.PI / (n - 1));const y = Float64Array.from(x, xi => Math.sin(xi) + 0.1);
// 99% confidence intervalconst model = new Lowess({intervals: {confidence: 0.99}});const result = model.fit(x, y);console.log("CI lower[0]:", result.confidence_lower[0].toFixed(4));CI lower[0]: 0.3175Standard Errors
Section titled “Standard Errors”Access standard errors directly (available when intervals are computed):
const { Lowess } = require('fastlowess-wasm');
const n = 100;const x = Float64Array.from({ length: n }, (_, i) => i * 2 * Math.PI / (n - 1));const y = Float64Array.from(x, xi => Math.sin(xi) + 0.1);
const model = new Lowess({intervals: {confidence: 0.95}});const result = model.fit(x, y);
result.standard_errors.slice(0, 5).forEach((se, i) => { console.log(`Point ${i}: SE = ${se.toFixed(4)}`);});Point 0: SE = 0.0246Point 1: SE = 0.0252Point 2: SE = 0.0258Point 3: SE = 0.0265Point 4: SE = 0.0271Residual Bootstrap
Section titled “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".
const { Lowess, StreamingLowess, OnlineLowess } = require('fastlowess-wasm');
const x = Float64Array.from({ length: 30 }, (_, i) => i * 0.1);const y = Float64Array.from(x, xi => Math.sin(xi) + 0.1 * Math.cos(7 * xi));const intervals = { confidence: 0.95, prediction: 0.95, bootstrap: 20 };
const batch = new Lowess({ intervals, seed: 42 }).fit(x, y);console.log("Batch SEs:", batch.standard_errors.length);
const stream = new StreamingLowess({ intervals, seed: 42 }, { chunk_size: x.length });console.log("Streaming CI present:", stream.process_chunk(x, y).confidence_lower !== undefined);
const online = new OnlineLowess({ intervals, seed: 42 }, { min_points: 5, update_mode: "full" });let last = null;for (let i = 0; i < 12; i++) { last = online.add_point(x[i], y[i]) ?? last;}console.log("Online PI present:", last.prediction_lower !== undefined);Batch SEs: 30Streaming CI present: trueOnline PI present: trueAvailability
Section titled “Availability”| Feature | Batch | Streaming | Online |
|---|---|---|---|
| Confidence intervals | ✓ | ✓ | ✓ (update_mode: "full" only) |
| Prediction intervals | ✓ | ✓ | ✓ (update_mode: "full" only) |
| Standard errors | ✓ | ✓ | ✓ (update_mode: "full" only) |
| Residual bootstrap | ✓ | ✓ | ✓ (update_mode: "full" only) |