Skip to content

Regression Analysis

Add trend lines with statistical confidence bands to scatter plots and line charts.

Basic Trend Line

Add a regression mark to show the linear relationship in your data:

yaml
type: scatter
x: temperature
y: ice_cream_sales
marks:
  - type: dot
  - type: regression
title: Temperature vs Ice Cream Sales

The regression line fits through your data points using ordinary least squares (OLS).

Configuration

ParameterTypeDefaultDescription
typestring-'regression'
xstringinheritedX-axis field
ystringinheritedY-axis field
strokestring'#4f46e5'Line color
strokeWidthnumber2Line thickness
strokeOpacitynumber1Line opacity
showConfidencebooleantrueDisplay confidence bands
confidenceLevelnumber0.95Confidence interval (0-1)
showEquationbooleanfalseDisplay equation and R²
extendDomainnumber0Extend line beyond data range

Confidence Bands

Confidence bands show the uncertainty around the trend line. The default 95% band means: if we repeated this analysis, 95% of regression lines would fall within this region.

yaml
marks:
  - type: dot
  - type: regression
    showConfidence: true
    confidenceLevel: 0.95

Widen bands for more conservative estimates:

yaml
marks:
  - type: regression
    confidenceLevel: 0.99

Disable bands for a cleaner look:

yaml
marks:
  - type: regression
    showConfidence: false

Display Equation

Show the regression equation and R² coefficient:

yaml
marks:
  - type: regression
    showEquation: true

Displays: y = 2.34x + 15.7 (R² = 0.87)

The R² value indicates fit quality:

  • 0.9+ Strong relationship
  • 0.7-0.9 Moderate relationship
  • Below 0.7 Weak relationship

Grouped Regression

Add separate trend lines for each category:

yaml
type: scatter
x: study_hours
y: test_score
color: subject
marks:
  - type: dot
  - type: regression

Each color group gets its own regression line, revealing whether the relationship varies by category.

Styling

Custom Colors

yaml
marks:
  - type: regression
    stroke: "#ef4444"
    strokeWidth: 3

Dashed Line

yaml
marks:
  - type: regression
    strokeDasharray: "5,5"

Semi-transparent Band

yaml
marks:
  - type: regression
    showConfidence: true
    fillOpacity: 0.1

Outlier Handling

Remove outliers before fitting to prevent skewed results:

yaml
marks:
  - type: regression
    removeOutliers: true
    outlierThreshold: 2.5

Points beyond 2.5 standard deviations from the mean are excluded from the fit (but still displayed).

Extend Beyond Data

Project the trend line beyond your data range:

yaml
marks:
  - type: regression
    extendDomain: 0.1

Extends the line 10% beyond the data range on each side.

Examples

Sales Forecast

yaml
type: scatter
x: month
y: revenue
marks:
  - type: dot
    fill: "#6366f1"
  - type: regression
    stroke: "#dc2626"
    showEquation: true
    extendDomain: 0.2
title: Revenue Trend with Forecast

A/B Test Analysis

yaml
type: scatter
x: time_on_page
y: conversion_rate
color: variant
marks:
  - type: dot
    r: 4
  - type: regression
    strokeWidth: 2
    showConfidence: true
title: Conversion by Time on Page
subtitle: Comparing variants A and B

Scientific Data

yaml
type: scatter
x: concentration
y: absorption
marks:
  - type: dot
    symbol: cross
  - type: regression
    showEquation: true
    showConfidence: true
    confidenceLevel: 0.99
    removeOutliers: true
title: Beer-Lambert Calibration Curve

Limitations

  • Only linear regression is supported (no polynomial, logarithmic, etc.)
  • Requires numeric x and y fields
  • Confidence bands assume normal distribution of residuals
  • Very small datasets (< 5 points) produce unreliable estimates

Released under the MIT License. Built by Boundary Lab.