liveBook · Manning

Slope

As explained in Grokking Statistics

A slope is a regression coefficient describing the change in the predicted response for a one-unit change in an input variable.

A slope describes how much a predicted response changes when an input increases by one unit. In simple linear regression, it is the m in y = mx + b, the line’s rate of change. section 7.7

Temperature and sports-drink sales

A regression of temperature against sports-drink sales produces a slope of 9.74. Interpret that as an estimated 9.74 more sales for every one-degree Fahrenheit increase. The intercept is −405.26, but predicted negative sales at zero degrees make it less useful on its own. section 7.7

Slope also appears in models with several inputs:

  • Multiple linear regression assigns one slope to each independent variable, such as house, lot, and backyard square footage. section 7.11
  • Professional output usually labels the intercept β0 and the slopes β1, β2, and β3 rather than m and b. section 7.11
import numpy as np
from scipy.stats import linregress

x = np.array([51.5, 55.1, 63.0, 71.2, 73.0, 77.1, 88.1,
    91.2, 93.0, 101.6])

y = np.array([100.98, 137.44, 237.8, 254.96, 263.45, 
    353.89, 450.32, 521.34, 503.13, 573.91])

m, b, r_value, p_value, std_err = linregress(x, y)  #1

print(f"Slope: {m:.2f} (sales increase per "
     f"degree Fahrenheit)") #2

print(f"Intercept: {b:.2f}")  #2
print(f"Pearson Correlation: {r_value:.4f}")  #2
print(f"P-value (for slope): {p_value:.10f}")  #2
print(f"Standard error of slope: {std_err:.4f}")  #2

# Slope: 9.74 (sales increase per degree Fahrenheit)
# Intercept: -405.26
# Pearson Correlation: 0.9889
# P-value (for slope): 0.0000000654
# Standard error of slope: 0.5173

Run the SciPy example to inspect the slope alongside the intercept, correlation, p-value, and standard error. section 7.7

How Grokking Statistics covers it

How deep it goes
Defines and interprets slope through fitted lines, then extends it to multiple regression and beta notation.
Examples
Uses temperature, sports-drink sales, scatterplots, and house-size variables to illustrate slope.
What it assumes
Assumes familiarity with input and output variables, while introducing slope through the familiar linear function y = mx + b.
What you can do after
Apply it via SciPy's linregress and interpret the resulting coefficient for a real input change.
How it connects
Connects slope with linear regression, intercept, correlation, p-values, standard error, and multiple linear regression.

Also explained in

Compare how 7 books explain slope →

Related concepts

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