Skip to course content
Free R statistics course

Statistical Data Analytics with R

Unit 08.02: A slope is an association within the observed range

lm() fits a line. What the slope means is a question the arithmetic cannot answer.

A slope is an association within the observed range

lm(y ~ x) estimates an intercept and a slope. The slope says how much y changes, on average, per one-unit change in x — an association, not an effect, unless x was randomised.

Two limits are built in. The relationship is estimated only over the range of x you observed, so extrapolating beyond it assumes the line continues when nothing in the data says so. And the intercept is the fitted value at x = 0, which is frequently outside the data and meaningless as a prediction.

broom::tidy() gives the coefficients as a table and glance() gives the model-level summary.

This block fits revenue against spend and reads the output.

suppressPackageStartupMessages(library(broom))
set.seed(503)

spend <- runif(80, 100, 900)
revenue <- 250 + 1.8 * spend + rnorm(80, 0, 180)

model <- lm(revenue ~ spend)
print(tidy(model))
cat("\n")
print(glance(model)[, c("r.squared", "sigma", "statistic", "p.value", "nobs")])

co <- coef(model)
cat("\nFitted line: revenue =", round(co[1], 1), "+", round(co[2], 3), "* spend\n")
cat("Slope meaning: each extra 1 of spend is associated with",
    round(co[2], 3), "more revenue,\n")
cat("               on average, within the observed spend range of",
    round(min(spend)), "to", round(max(spend)), ".\n\n")
cat("'Associated with', not 'causes'. Nothing here was randomised.\n")
cat("The intercept of", round(co[1], 1), "is spend = 0, which is outside the\n")
cat("data -- it is a mathematical anchor, not a prediction.\n")

The fitted line is revenue = 269.4 + 1.742 × spend, with an R-squared of 0.817 and a residual SD of 184 over 80 observations. Each extra unit of spend is associated with 1.742 more revenue, on average, within the observed spend range of 109 to 896 — not below it, and not above. The intercept of 269.4 sits at spend = 0, outside the data entirely, and is an anchor for the line rather than a prediction.

The mistake this prevents

The mistake is describing a regression slope from observational data as an effect. Nothing was randomised, so the slope reflects whatever else differs between high-spend and low-spend cases.

Takeaway

Report the slope with its interval and say 'associated with' unless the predictor was randomised. State the observed range of x, and do not interpret the intercept when zero lies outside it.