Simple linear regression
Simple linear regression describes how a continuous outcome changes with a single predictor, by fitting a straight line. Where a correlation tells you how strongly two variables move together, regression tells you how much the outcome changes per unit of the predictor, and lets you make predictions.
The model
y = b₀ + b₁x + e
- b₀ (intercept): the predicted y when x = 0. Often not meaningful by itself, for example if x = 0 is impossible.
- b₁ (slope): the average change in y for each one-unit increase in x.
- e (residual): each case’s distance from the line.
“Best fit” means ordinary least squares (OLS): the line that makes the sum of squared residuals as small as possible.
Hypotheses
- H₀: the population slope is zero (β₁ = 0), so x doesn’t predict y.
- H₁: the slope is not zero.
With one predictor, the t test on the slope and the overall F test give the same p-value (F = t²).
Assumptions
- Linearity: the relationship really is a straight line.
- Independence of the residuals: no clustering, and no time trends in the ordering.
- Homoscedasticity: the residuals spread equally across all fitted values, rather than fanning out.
- Normality of the residuals, which matters most in small samples. The outcome and predictor themselves don’t need to be normal.
Also look for influential points that pull the line towards them.
Worked example: predicting fuel economy from weight
Using the 32 cars in R’s mtcars dataset (1974), we regress miles per gallon on car weight, measured in thousands of pounds.
Step 1: run the model
Model: Linear regression (OLS) Outcome: mpg N: 32 R-squared: 0.7528 Adjusted R-squared: 0.7446 F-statistic: 91.3753 F df: 1, 30 P-value: 1.294e-10 === COEFFICIENTS === const: coef=37.2851, se=1.8776, t=19.8576, p=0.0000, ci=[33.4505, 41.1198] wt: coef=-5.3445, se=0.5591, t=-9.5590, p=0.0000, ci=[-6.4863, -4.2026] === DIAGNOSTICS === Breusch-Pagan p (homoscedasticity): 0.8406 Durbin-Watson (independence): 1.2517 Residual normality p: 0.2245 Influential observations (Cook's D > 4/n): 3 Max Cook's D: 0.5319 Linearity RESET p: 0.0126
> summary(lm(mpg ~ wt, data = mtcars))
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 37.2851 1.8776 19.858 < 2e-16 ***
wt -5.3445 0.5591 -9.559 1.29e-10 ***
Residual standard error: 3.046 on 30 degrees of freedom
Multiple R-squared: 0.7528, Adjusted R-squared: 0.7446
F-statistic: 91.38 on 1 and 30 DF, p-value: 1.294e-10Identical coefficients, standard errors, R² and F. Analytika’s linear regression template is tested against R on every change.
Step 2: interpret the coefficients
- Slope: b = −5.34, 95% CI [−6.49, −4.20], p < .001. Each additional 1,000 lb is associated with 5.34 fewer miles per gallon on average.
- Intercept: 37.29. The predicted mpg for a car weighing 0 lb, which is meaningless in itself. It just positions the line.
- The equation: mpg = 37.29 − 5.34 × weight. A 3,000 lb car (weight = 3) is predicted to get 37.29 − 5.34 × 3 ≈ 21.3 mpg.
Step 3: how well does the model fit?
- R² = .75: weight explains 75% of the variation in fuel economy. With one predictor, R² is the square of the correlation (−.87² ≈ .75).
- Residual standard error = 3.05 mpg: predictions are typically off by about 3 mpg.
- F(1, 30) = 91.38, p < .001: the model explains significantly more than a flat line at the mean.
Step 4: check the diagnostics
- Homoscedasticity: Breusch-Pagan p = .84, so no sign that the residual spread changes.
- Residual normality: p = .22, no problem.
- Linearity: RESET p = .013. There’s some evidence the relationship curves, with fuel economy falling off faster among the lightest cars than a straight line allows. This is a genuine caveat. A curved term (weight²) or a log transformation might fit better.
- Influential points: three cars exceed the Cook’s distance cut-off of 4/n. Look at which ones before trusting the line completely.
- Durbin-Watson checks for correlation between consecutive residuals. It only matters when rows have a meaningful order, such as time. These cars are in an arbitrary order, so ignore it here.
Analytika lists diagnostics like these as caveats with the results. It doesn’t silently switch to a different model, because whether to add a curve is a modelling decision for you to make and justify.
Step 5: report it (APA 7)
A simple linear regression showed that car weight was associated with fuel economy, b = −5.34, 95% CI [−6.49, −4.20], t(30) = −9.56, p < .001. Weight explained 75% of the variance in miles per gallon, R² = .75, F(1, 30) = 91.38, p < .001.
Mention the curvature caveat in the text or a footnote.
Common mistakes
- Extrapolating beyond the range of the data. These cars weigh 1,500 to 5,400 lb, so the line says nothing reliable about a 10,000 lb truck.
- Interpreting a meaningless intercept.
- Causal language for observational data: “associated with”, not “reduces”.
- Checking normality of the outcome instead of the residuals.
- Skipping the residual plots. Curves and fanning are easier to see than to test.
How to run it
- SPSS: Analyze → Regression → Linear. Put the outcome under Dependent and the predictor under Independent(s), and add confidence intervals and residual plots.
- R:
summary(lm(y ~ x, data = df)), thenconfint()andplot()for the diagnostics. - Python:
statsmodels.formula.api.ols("y ~ x", data=df).fit().summary() - Analytika: ask, for example, “does weight predict mpg?”. You get the coefficients, R², diagnostics and an APA-style write-up.
With more than one predictor, see multiple regression.
More in Regression
Try it with the free tools
Run this on your own data
Upload a dataset and ask your question in plain English. Analytika checks the assumptions, picks the test, runs it, and writes the results up in APA format.