Linear Regression 3D Simulator — Least Squares & Residuals Interactive

Interactive 3D linear-regression simulator with thirty observed points, a candidate regression line, vertical residual segments and residual squares, plus live charts, equations, guided experiments and a quiz.

← Statistics & Data Science Labs
About this tool — how it works & FAQOpen ▾Close ▴

About the Linear Regression 3D Simulator

This simulator scatters thirty simulated observations and lets you choose the slope and intercept of a line by hand, or switch to the ordinary least-squares solution. Every vertical residual is drawn, every residual is turned into a square, and the lab reports the sum of squared errors against the minimum attainable value.

What the simulator shows

• A real-time 3D scene with 4 inspectable parts (Observed data, Candidate regression line, Vertical residual segments and Residual squares), with home view, focus-selected-part, auto-rotate, expand, instrument-cover and hide-labels scene tools, plus a model response curve beneath the scene. • Experiment controls: Response noise SD (0.1-1); Manual slope (-1-3); Manual intercept (-2-3); use least-squares solution; Repeatable random seed (1-99); show animated explanatory markers; pause/resume, 0.1 s and 1 s single-step buttons, four playback speeds and a restart button. • A Curves & measurements tab with a parameter-comparison chart, a live-measurements chart, the model equations and snapshot readouts (Active slope; Active intercept; Residual sum of squares; Minimum attainable SSE; Active line R²). • An Experiments tab with 2 guided presets (poor manual fit and least-squares fit) and a Model verification bench that runs independent fresh models, plus a timestamped event log and a copyable trial report. • A Learn & assess tab with guided lessons, a knowledge-check quiz with reset and a written model-scope statement linking to a technical reference.

Residuals, squares and the best-fit line

A residual is the vertical gap between an observation and the line. Squaring each residual and summing gives the sum of squared errors, SSE, which least squares minimizes. The least-squares slope is the covariance-style ratio of the summed products of deviations to the summed squared x deviations, and the intercept makes the line pass through the point of means.

The lab shows the active slope and intercept, the SSE, the minimum attainable SSE and the active line's R squared, so a hand-drawn line can be compared directly with the optimum.

Reading fit quality honestly

R squared equals one minus SSE over the total sum of squares, and for a poor manually chosen line it can be negative - a line can fit worse than simply predicting the mean. The data are simulated with independent Gaussian response noise around a straight trend, and the fit is unweighted.

A high R squared describes how well the line fits the data under the model; it is not evidence of causation. The residual-square inset uses equal x and y scale within its own plane so the squares stay genuine squares rather than distorted rectangles.

Frequently asked questions

What does ordinary least squares minimize?

It minimizes the sum of squared vertical residuals - the y-direction errors between each observation and the line. The lab shows the minimum attainable SSE so you can see how close a hand-chosen line comes.

Can R squared be negative?

Yes, for a line that is not the least-squares solution. If a manually chosen line fits worse than a horizontal line at the mean, SSE exceeds the total sum of squares and R squared drops below zero. Try the poor-manual-fit experiment.

Does a high R squared prove that x causes y?

No. R squared measures how well a line describes the association in the data under the model. It says nothing by itself about causal direction or confounding.

Why are the residual errors drawn as squares?

Because the squared error for each point is the area of a square whose side is the residual. Summing those areas gives SSE, which makes it visible why large residuals dominate the total.

Related tools & guides