›Linear Regression Simulator Back
Statistics

Linear Regression Simulator

Click on the chart to add data points and watch the least-squares regression line and statistics update in real time.

Controls

Click on the chart to add data points, or use the buttons below.

Results
—
R² (0–1)
—
r (−1–+1)
—
Slope b
—
Intercept a
0
Points n
—
RMSE
Add 2 or more points to see the regression line.
Click on the chart to add data points
Theory & Key Formulas

Least-squares fit: $$\hat{y} = a + b\,x$$

$$b = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2}, \qquad a = \bar{y} - b\,\bar{x}$$

$R^2$ is the fraction of variance explained by the model; $r$ is Pearson's correlation; RMSE is the root-mean-square residual.

FAQ

What is the method of least squares?
It finds the line that minimizes the sum of squared residuals (differences between observed values and the line). This gives the best linear fit.
How do you interpret the correlation coefficient r?
r=+1 is perfect positive correlation; r=0 is no correlation; r=-1 is perfect negative. |r|>0.7 is generally considered strong correlation.
What are important caveats in regression analysis?
Correlation does not imply causation. Outliers can strongly distort results. Always check residual plots to verify that a linear model is appropriate.
How does multiple regression differ?
Simple regression uses one predictor variable; multiple regression uses several. Coefficients are estimated as beta = (XtX)^-1 Xt y using matrix algebra.
🙋
I can see the simulation updating, but what exactly is being calculated here?
🎓
Great question! The simulator solves the governing equations in real time as you move the sliders. Each parameter you control directly affects the physical outcome you see in the graph. The key is to build an intuitive feel for how each variable influences the result — that's how engineers develop physical judgment.
🙋
So when I increase this parameter, the curve shifts significantly. Is that a linear relationship?
🎓
It depends on the model. Some relationships are linear, but many engineering phenomena are nonlinear. Try moving the sliders to extreme values and see if the output changes proportionally — if the graph shape changes, that's a sign of nonlinearity. This hands-on exploration is exactly what simulations are best for.
🙋
Where is this kind of analysis actually used in practice?
🎓
Constantly! Engineers run these calculations during the design phase to quickly screen parameters before investing in expensive physical tests or detailed finite element simulations. Getting comfortable with these simplified models is a real engineering skill.

How to Use

  1. Click on the graph to add data points; each click generates a coordinate pair (x, y) visible in the scatter plot.
  2. Enable "show-residuals" to display vertical distance lines from each point to the fitted regression line—critical for assessing model fit quality.
  3. Toggle "show-mean-lines" to overlay horizontal and vertical reference lines at mean-x and mean-y; this helps identify leverage points and influential outliers.
  4. Check "show-confidence" to shade the 95% confidence interval band around the regression line, representing prediction uncertainty at each x-value.
  5. Monitor the output statistics panel: R² quantifies variance explained (0.85+ indicates strong fit), slope b shows the rate of change per unit x, and RMSE reports prediction error in original y-units.

Worked Example

A quality engineer collects 12 measurements of tensile strength (y, MPa) versus carbon content (x, wt%). After plotting: points cluster around y = 320 + 45x. The simulator calculates slope b = 45.2 MPa/wt%, intercept a = 318 MPa, R² = 0.91, and RMSE = 8.7 MPa. Residuals reveal one outlier at 2.1 wt% with 15 MPa deviation, suggesting measurement error or material batch variation warranting investigation.

Practical Notes

  1. Minimum 3 points required for regression; n < 5 yields unreliable R² and wide confidence bands—collect adequate samples before trusting predictions.
  2. Outliers disproportionately shift slope and intercept; "show-residuals" exposes high-leverage points that may warrant removal if data entry errors are confirmed.
  3. R² = 0.5–0.7 in industrial processes (e.g., process yield vs. temperature) is often acceptable; demand R² > 0.8 only when prediction criticality is high (safety, cost).
  4. Confidence interval widens beyond the data range; extrapolation beyond x-max is unreliable and common source of engineering forecast failures.