Skip to content

linearPrediction

Builds the prediction band for a new observation under a simple linear regression of points: ŷ ± t·s·√(1 + 1/n + (x − x̄)²/Sxx). Wider than the confidence band of linearConfidence, since it covers the scatter of individual values as well as the uncertainty of the fitted line, which makes it the band to draw around a forecast. Returns a function mapping an x value to its [lower, upper] bounds, or null when there are fewer than three usable points or the x values do not vary.

Parameters

import {linearPrediction} from "@d3plus/math";
pointsrequiredArray.<[number, number]>

An array of [x, y] pairs.

levelnumberDefault 0.95

The confidence level, between 0 and 1. Defaults to 0.95.