Simple Linear Regression

Predict one variable from another with a straight line - temperature and strength, input and yield. The regression equation, explanatory power (R²), coefficient significance, mean response confidence interval and individual prediction interval are shown, and the residuals check the model assumptions.

1Data Table

Paste a table copied from Excel into a cell (Ctrl+V). Click a column header (A, B…) before pasting to use the first line as column names. Double-click a header to rename it, right-click to insert/delete rows and columns, and formulas such as =A1*2 work too.

2Simple Linear Regression Options

How to run a simple linear regression

  1. Copy the predictor X column and the response Y column with their headers (same subject on the same row).
  2. Choose the response Y and the predictor X. To get a prediction at a specific X, check 'Specify an X value to predict' and enter the value.
  3. Click Analyze and review the model summary, coefficients, scatter plot and automatic interpretation.

Worked example with sample data

The example data are the tensile strength (MPa) of 20 specimens made at different heat treatment temperatures (°C). The heat treatment temperature is the predictor X and the tensile strength is the response Y.

Scatter plot of heat treatment temperature and tensile strength - regression line with the 95% mean response confidence band (dark) and individual prediction band (light)
Scatter plot of heat treatment temperature and tensile strength - regression line with the 95% mean response confidence band (dark) and individual prediction band (light)

The regression equation is Tensile strength = 1.44·Heat treatment temp - 80.46: each 1 °C increase raises the tensile strength by 1.44 MPa on average. The 95% confidence interval of the slope, 1.285 ~ 1.594, excludes 0.

R²=0.9551, so temperature alone explains 95.51% of the variation in tensile strength, and the F test p-value of 1.406e-13 is highly significant.

In the scatter plot the darker band is the confidence interval of the mean strength and the lighter band is the prediction interval for a single specimen. The residuals are symmetric and the Anderson-Darling normality test (p=0.3871) shows no problem with normality. Entering 200 in 'Specify an X value to predict' adds the predicted value 207.5 (individual prediction PI 192 ~ 223).

How it is calculated

Y = b₁·X + b₀ is fitted by least squares (statsmodels OLS). R² = 1 - residual sum of squares / total sum of squares; the F test checks whether the slope is 0, and the coefficient t tests and confidence intervals use the t distribution with n - 2 residual degrees of freedom.

The mean response confidence interval is the range for the average Y at that X, and the individual prediction interval is the range for one new Y measurement. The prediction interval is always wider.

What the results show

(A prediction table when an X value is specified), the model summary, the coefficient table, a scatter plot with the regression line and confidence/prediction bands (the equation is in the side panel), residuals vs fitted, a residual QQ plot and a residual histogram.

Interpreting the simple linear regression

  • If the F P-value is below the significance level, X explains Y significantly. R² is the share of the variation in Y explained by the equation.
  • The X coefficient (slope) is the average change in Y when X increases by 1; it is significant when its confidence interval excludes 0.
  • A pattern (curve or funnel) in residuals vs fitted suggests that the straight-line model or the equal-variance assumption does not hold. For a curve, try polynomial regression.

Frequently asked questions

How is this different from correlation?

Correlation only measures how strongly two variables move together; regression also gives an equation that predicts Y from X and prediction intervals.

What is the difference between the mean response CI and the individual prediction PI?

The CI is the range for the average Y at that X, and the PI is the range for a single new measurement, so the PI is wider.

What if there are blank cells or text?

Rows where X or Y is blank or not a number are dropped entirely.

Other chart tools