liveBook · Manning

Trend line

As explained in Statistics Slam Dunk

A regression line is a fitted line that summarizes the predicted relationship between variables in a regression model.

A trend line, also called a regression line or line of best fit, summarizes the direction of a relationship in plotted data. It is drawn to minimize the distances between the line and the data points; a steeper line indicates a stronger correlation. section 4.5.3 section 1.2.1

Use a trend line to:

  • Add a linear summary to a scatterplot with ggplot2 by calling geom_smooth(method = lm). section 4.5.3
  • Compare relationships, such as points allowed versus wins and points scored versus wins, with matched plots. section 14.4.1
  • Show different patterns across subsets by drawing separate lines for selected ranges of the data. section 8.5.1
  • Remove the automatically added 95% confidence interval with se = FALSE when the shaded band is not wanted. section 4.5.3

NBA salaries and win shares

A scatterplot of annual salary against win shares uses geom_point() for the observations and geom_smooth(method = lm, se = FALSE) for the fitted line. The reported correlation coefficient is 0.76, indicating a positive and strong relationship; the line summarizes that pattern rather than replacing the observations. section 4.5.3

MILp1 <- ggplot(MILx, aes(x = play_length2, y = avg, group = 1)) +
 geom_line(aes(y = avg), color = "darkgreen", size = 2) +
 geom_point(color = "wheat2", size = 3) +
 labs(title = "Points Scored per Second Increment",
      subtitle = "2019-20 Milwaukee Bucks",
      caption = "regular season only",
      x = "Number of Seconds into Possession",
      y = "Average Number of Points Scored") +
 geom_smooth(method = lm, color = "blue", se = FALSE) +
 geom_smooth(method = lm, color = "gold", 
             data = MILx[MILx$play_length2 < 13,], se = FALSE) +
 geom_smooth(method = lm, color = "purple", 
             data = MILx[MILx$play_length2 > 11,], se = FALSE) +
 theme_classic() +
 theme(plot.title = element_text(face = "bold")) +
 inset_element(bucks, left = 0.80, bottom = 0.80, 
               right = 0.95, top = 0.95)

Inspect executable R code that overlays overall, before-12-second, and after-12-second regression lines on Milwaukee Bucks possession data. section 8.5.1

How Statistics Slam Dunk covers it

How deep it goes
Defines fitting and slope interpretation, demonstrates ggplot2 implementation, and notes confidence intervals without deriving regression mathematics.
Examples
Uses NBA salaries and win shares, points and wins, automobile mileage, and Milwaukee Bucks possession trends.
What it assumes
Assumes plotted numeric variables and introduces scatterplots, correlation, regression lines, and confidence intervals in plain language.
What you can do after
Apply it via ggplot2 by adding geom_smooth(method = lm) to plotted numeric data and controlling confidence bands with se.
How it connects
Connects regression lines with correlation, scatterplots, linear regression, confidence intervals, and data visualization.

Also explained in

Compare how 4 books explain trend line →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Slam Dunk. The section links point to the parts of the book it draws on.