Search
Menu

SHAP Plots: A Deep Dive into Explainable AI

Explore how a model's prediction differs from a baseline and compare the meaning of a local contribution with a summary across observations.

Quick Answer

SHAP (SHapley Additive exPlanations) plots are powerful visualization tools that help interpret machine learning models by showing how each feature contributes to predictions, while accounting for complex feature interactions and dependencies.

A data scientist examining red and blue feature contributions

Understanding SHAP Plots: A Deep Dive into Explainable AI

SHAP (SHapley Additive exPlanations) plots are powerful visualization tools that help interpret machine learning models by showing how each feature contributes to predictions, while accounting for complex feature interactions and dependencies.

What Are SHAP Plots?

In the era of machine learning, models are becoming increasingly complex and often function as "black boxes." Understanding why a model makes certain predictions is crucial for building trust, debugging models, and ensuring fairness. This is where SHAP plots come in.

SHAP (SHapley Additive exPlanations) plots are visualization tools based on Shapley values from cooperative game theory. They provide a unified approach to explaining the output of any machine learning model by attributing prediction outcomes to each input feature in a fair and consistent manner.

The Mathematics Behind SHAP Values

SHAP values are based on the concept of Shapley values from cooperative game theory, which were introduced by Lloyd Shapley in 1953. In the context of machine learning, they assign each feature an importance value for a particular prediction.

φᵢ(f, x) = ∑S⊆N\{i} |S|!(|N|-|S|-1)! / |N|! [fx(S∪{i}) - fx(S)]

Where:

  • φᵢ is the Shapley value for feature i
  • N is the set of all features
  • S is a subset of features
  • fx(S) is the prediction for feature set S

In simpler terms, SHAP values measure how much each feature contributes to the difference between the actual prediction and the average prediction. This approach handles feature interactions and dependencies in a mathematically rigorous way.

Key Types of SHAP Plots

SHAP offers various visualization types, each serving a different purpose in model interpretation:

1. Summary Plots

Summary plots show the global importance and impact of each feature across the entire dataset. They display features ranked by their importance, with colors indicating whether higher feature values increase (red) or decrease (blue) the prediction.

Key Insight: Summary plots help you quickly identify which features have the largest overall impact on your model's predictions, making them ideal for feature selection and model debugging.

2. Dependency Plots

Dependency plots (or SHAP interaction plots) show how the SHAP value of a feature changes based on the value of that feature. They help visualize non-linear relationships and interactions between features.

These plots reveal how the impact of a feature varies across its range of values, helping data scientists understand complex patterns that might be missed in traditional partial dependence plots.

3. Force Plots

Force plots visualize the impact of each feature for an individual prediction. They show how each feature pushes the prediction higher (red) or lower (blue) from the baseline (average model output).

These plots are particularly useful for explaining specific predictions to stakeholders and for debugging unusual model behaviors at the instance level.

Interactive SHAP Visualization

Summary Plot
Dependency Plot
Force Plot
Example Model

Dataset Selection

How to interpret: Features are ranked by their global importance. Longer bars indicate more important features. The plot shows how different feature values (color-coded) affect the prediction.

Feature Selection

How to interpret: This plot shows how the impact of a feature (SHAP value) changes based on the feature's value. The x-axis shows the feature value, and the y-axis shows the SHAP value (impact on prediction).

Instance Selection

How to interpret: This plot shows how each feature pushes the prediction away from the baseline (average prediction). Red arrows push the prediction higher, while blue arrows push it lower.

Prediction Information:
Prediction: —
Baseline: —

Interactive Credit Risk Model

This interactive example allows you to adjust feature values and see how they affect the credit risk prediction and SHAP values in real-time.

Credit Risk Prediction (0-100):
50

Benefits of Using SHAP Plots

1. Model Transparency and Interpretability

SHAP plots transform complex models into understandable visualizations, making it easier to explain predictions to stakeholders and regulatory bodies. This transparency is especially critical in regulated industries like healthcare, finance, and insurance.

2. Feature Interaction Detection

Unlike simpler feature importance methods, SHAP plots incorporate feature interactions and dependencies. This means they can reveal complex relationships where the impact of one feature depends on the values of other features.

For example, a loan applicant's income might have a different impact on their credit risk score depending on their debt-to-income ratio—an interaction that simpler methods might miss.

3. Model Debugging and Improvement

SHAP plots help identify unexpected model behaviors or biases. By showing how different feature values affect predictions, they can expose areas where the model might be making decisions based on problematic patterns or spurious correlations.

4. Feature Selection and Engineering

SHAP summary plots provide a reliable ranking of feature importance, helping data scientists identify which features contribute most to predictions. This information is invaluable for feature selection and engineering processes.

Applications of SHAP Plots Across Industries

Finance and Banking

  • Credit Scoring: Explaining why a loan application was approved or rejected
  • Fraud Detection: Understanding which transaction characteristics trigger fraud alerts
  • Investment Strategies: Analyzing which market indicators drive investment algorithms

Healthcare

  • Patient Readmission Risk: Identifying factors that contribute to hospital readmission
  • Disease Diagnosis: Explaining which symptoms and test results led to specific diagnoses
  • Treatment Recommendation: Understanding why an AI recommends one treatment over another

Marketing

  • Customer Churn: Determining which factors contribute most to customer attrition
  • Campaign Optimization: Understanding which customer characteristics respond best to specific marketing messages
  • Pricing Strategies: Analyzing how different factors affect optimal pricing recommendations

Best Practices for Effective SHAP Analysis

  1. Start with Summary Plots: Begin your analysis with summary plots to get a big-picture view of feature importance.
  2. Investigate Interesting Features: Use dependency plots to explore how specific features of interest affect predictions across their value ranges.
  3. Explain Individual Predictions: Use force plots to explain specific predictions, especially outliers or controversial cases.
  4. Compare Across Subgroups: Generate separate SHAP analyses for different demographic or business segments to identify potentially problematic variations.
  5. Combine with Domain Knowledge: Always interpret SHAP values in the context of domain expertise—statistical importance doesn't always equal business importance.

Limitations and Considerations

While SHAP plots are powerful interpretation tools, they have some limitations:

  • Computational Expense: Calculating exact SHAP values can be computationally intensive for large datasets or complex models.
  • Simplification of Interactions: Even though SHAP handles interactions better than many methods, the visualizations sometimes simplify highly complex interactions.
  • Feature Independence Assumption: In some implementations, SHAP can make assumptions about feature independence that might not hold in real-world data.
  • Requires Careful Interpretation: SHAP values show correlation, not causation—a high SHAP value doesn't necessarily mean changing that feature will change the outcome in the real world.

Conclusion

SHAP plots have revolutionized machine learning interpretability, providing a mathematically sound method for understanding complex models. By visualizing how each feature contributes to predictions—while accounting for interactions and dependencies—SHAP plots bridge the gap between advanced machine learning and human comprehension.

As AI systems become more embedded in critical decision-making processes, tools like SHAP plots are essential for responsible AI development. They enable data scientists, business stakeholders, and end-users alike to understand, trust, and improve machine learning models in an increasingly algorithmic world.

Whether you're building credit risk models, medical diagnosis systems, or marketing optimization algorithms, incorporating SHAP analysis into your workflow can lead to more transparent, fair, and effective machine learning solutions.

Advertisement

Reconstruct one prediction

Suppose a regression model has a baseline predicted journey time of thirty minutes. For one journey, an explanation assigns eight extra minutes to distance, minus three minutes to departure time and one extra minute to another feature. In an additive explanation on this output scale, the contributions sum to six minutes. Adding them to the baseline gives a prediction of thirty-six minutes. This accounts for the model's output on that record. It does not establish how changing one real-world condition would affect the journey.

Relationships Between Quantitative Datasets

Before we can evaluate a relationship between two datasets, we must first decide if we feel that one might depend on the other. In our exam example, it is appropriate to say that the score on the final depends on the score on the midterm, rather than the other way around: if the midterm depended on the final, then we’d need to know the final score first, which doesn’t make sense.
Here’s another example: if we collected data on home purchases in a certain area, and noted both the sale price of the house and the annual household income of the purchaser, we might expect a relationship between those two. Which depends on the other? In this case, sale price depends on income: people who have a higher income can afford a more expensive house. If it were the other way around, people could buy a new, more expensive house and then expect a raise! (This is very bad advice.)
It's worth noting that not every pair of related datasets has clear dependence. For example, consider the percent of a country’s budget devoted to the military and the percent earmarked for public health. These datasets are generally related: as one goes up, the other goes down. However, in this case, there’s not a preferred choice for dependence, as each could be seen as depending on the other. When exploring the relationship between two datasets, if one set seems to depend on the other, we’ll say that dataset contains values of the response variable (or dependent variable). The dataset that the response variable depends on contains values of what we call the explanatory variable (or independent variable). If no dependence relationship can be identified, then we can assign either dataset to either role.

Identifying Explanatory and Response Variables

For each of the following pairs of related datasets, identify which (if any) should be assigned the role of response variable and which should be assigned to be the explanatory variable.
  1. A person’s height and weight
  2. A professional basketball player’s salary and their average points scored per game (which is a measure of how good they are at basketball)
  3. The length and width of leaves on a tree
Solution
  1. As people get taller, their weight tends to increase. But if a person goes on a diet and loses weight, we don’t expect them to also get shorter. So, weight depends on height. That means we’ll say that the response variable is weight and the explanatory variable is height.
  2. The more points a basketball player scores, the more money they should make. But if a basketball player gets a raise, we wouldn’t expect them to get better at basketball as a result. So, the response is salary and the explanatory is points per game.
  3. The way that the length and width of leaves are connected isn’t clear. It seems reasonable that as the width goes up, so would the length. But the other direction is also plausible: as the length goes up, so does the width. Without a clear dependence relationship, we’re free to declare either to be the response and the other to be the explanatory.
Once we’ve assigned roles to our two datasets, we can take the first step in visualizing the relationship between them: creating a scatter plot.

Creating Scatter Plots

A scatter plot is a visualization of the relationship between two quantitative sets of data. The scatter plot is created by turning the datasets into ordered pairs: the first coordinate contains data values from the explanatory dataset, and the second coordinate contains the corresponding data values from the response dataset. These ordered pairs are then plotted in the xy-plane. Let's return to our exam example to put this into practice.

Creating Scatter Plots Without Technology

Students are exploring the relationship between scores on the midterm exam and final exam in their math course. Here are some of the scores reported by their classmates:
Name Midterm grade Final grade
Student 1 88 84
Student 2 71 80
Student 3 75 77
Student 4 94 95
Student 5 68 73
Create a scatter plot to visualize the data.
Solution
Step 1: Since it makes more sense to think of the final exam score as being dependent on the midterm exam score, we’ll let the final grade be the response. So, let’s think of these two datasets as a set of ordered pairs, midterm first, final second:
Name (Midterm, Final)
Student 1 (88, 84)
Student 2 (71, 80)
Student 3 (75, 77)
Student 4 (94, 95)
Student 5 (68, 73)
Step 2: Next, let’s make the axes. On the horizontal axis, make sure the range of values is sufficient to cover all of the explanatory data. For our data, that’s 68 to 94. Similarly, the vertical axis should cover all of the response data (73 to 95):
A blank coordinate plane. The horizontal axis ranges from 65 to 95, in increments of 5. The vertical axis ranges from 70 to 100, in increments of 5.
Step 3: Our first point is (88, 84). So, we’ll locate 88 on the horizontal axis, 84 on the vertical axis, and identify the point that’s directly above the first location and horizontally level with the second:
A coordinate plane plots a point. The horizontal axis ranges from 65 to 95, in increments of 5. The vertical axis ranges from 70 to 100, in increments of 5. A horizontal dotted line is drawn at 84. A vertical dotted line is drawn at 88. The two dotted lines intersect at the point (88, 84).
Step 4: Repeat this process to place the other four points on the graph:
Five points are plotted on a coordinate plane. The horizontal axis ranges from 65 to 95, in increments of 5. The vertical axis ranges from 70 to 100, in increments of 5. The points are as follows: (68, 73), (72, 80), (75, 77), (88, 84), and (94, 95). Note: all values are approximate.
Step 5: Finally, label the axes:
Five points are plotted on a coordinate plane. The horizontal axis representing midterm ranges from 65 to 95, in increments of 5. The vertical axis representing final ranges from 70 to 100, in increments of 5. The points are as follows: (68, 73), (72, 80), (75, 77), (88, 84), and (94, 95). Note: all values are approximate.
For large datasets, it’s impractical to create scatter plots manually. Luckily, Google Sheets automates this process for us.

Creating Scatter Plots in Google Sheets

The dataset “NHL19” gives the results of the 2018–2019 National Hockey League season. The columns are team, wins (W), losses (L), overtime losses (OTL), total points (PTS), goals scored by the team (GF), goals scored against the team (GA), and goal differential (the difference in GF and GA). Use Google Sheets to create a scatter plot for GF vs. GA.
Solution
Step 1: Open the dataset in Google Sheets, and click and drag to select the data we want to visualize (in this case, we want the columns for GF and GA; make sure you include those labels in the selection).
Step 2: Next, click on the “Insert” menu, then click “Chart.” Sheets will automatically choose a chart format; if the result isn’t a scatter plot, click on the drop-down menu under “Chart type” in the Chart Editor on the right side of the window and select “Scatter chart.”
Step 3: Next, check that the correct choices were made for the horizontal and vertical axes. In this case, we want to see GF on the vertical axis and GA on the horizontal axis. If Sheets made the wrong choice, we can fix it in the Chart Editor by clicking on the name of the dataset under “X-axis” to open up a dropdown menu, then selecting the variable that should go on the horizontal axis (GA in this case).
Step 4: Now, click on the variable under “Series” and select the one that should go on the vertical axis (GF). If you had to make that change, the axis labels in the graph may also need changing; those labels can be fixed using the “Customize” tab in the Chart Editor under “Chart & axis titles.” Your result should look like this:
A scatter plot titled, GF versus GA. The horizontal axis representing GA ranges from 180 to 320, in increments of 20. The vertical axis representing GF ranges from 190 to 330, in increments of 20. The points are scattered throughout and it lies from 200 to 300 on the horizontal axis and 200 to 290 on the vertical axis.
(data source: www.nhl.com)

Reading and Interpreting Scatter Plots

Scatter plots give us information about the existence and strength of a relationship between two datasets. To break that information down, there are a series of questions we might ask to help us. First: Is there a curved pattern in the data? If the answer is “yes,” then we can stop; none of the linear regression techniques from here to the end of this section are appropriate. diagram and diagram show several examples of scatter plots that can help us identify these curved patterns.
A scatter plot represents a curved pattern. The x-axis ranges from 20 to 120, in increments of 20. The y-axis ranges from negative 100 to 500, in increments of 100. The scatter plot shows points scattered along a curve that passes through the following points: (20, 90), (40, 20), (50, 0), (80, 100), (100, 250), and (120, 500). Note: all values are approximate.
Curved pattern
A scatter plot represents no curved pattern. The x-axis ranges from 30 to 110, in increments of 10. The y-axis ranges from 0 to 140, in increments of 20. The points are scattered throughout and it lies from 30 to 100 on the horizontal axis and 10 to 120 on the vertical axis.
No curved pattern
A scatter plot represents a curved pattern. The x-axis ranges from 30 to 100, in increments of 10. The y-axis ranges from 40 to 120, in increments of 10. The scatter plot shows points scattered along a curve that passes through the following points: (30, 80), (40, 60), (55, 50), (70, 65), (90, 102), (100, 110), and (100, 105). Note: all values are approximate.
Curved pattern
A scatter plot represents no curved pattern. The x-axis ranges from 30 to 110, in increments of 10. The y-axis ranges from 0 to 300, in increments of 50. The points are scattered in linear decreasing order. Some of the points are as follows: (35, 250), (40, 220), (50, 200), (60, 175), (70, 150), (80, 125), (90, 75), and (100, 50). Note: all values are approximate.
No curved pattern
Once we have confirmed that there is no curved pattern in our data, we can move to the next question: Is there a linear relationship? To answer this, we must look at different values of the explanatory variable and determine whether the corresponding response values are different, on average. It's important to look at the values “on average” because, in general, our scatter plots won’t include just one corresponding response point for each value of the explanatory variable (i.e., there may be multiple response values for each explanatory value). So, we try to look for the center of those points. Let’s look again at diagram, but consider some different values for the explanatory variable. Let’s highlight the points whose x-values are around 50 and those that are around 80:
A scatter plot. The x-axis ranges from 30 to 110, in increments of 10. The y-axis ranges from 0 to 300, in increments of 50. The points are scattered in linear decreasing order. Some of the points are highlighted in red and the points are as follows: (50, 290), (48, 195), (48, 200), (49.5, 225), (50, 203), (78, 145), (79, 130), (80, 120), (81, 120), (81, 70), (82, 90), (82.5, 90), (82, 100), and (82, 120). Note: all values are approximate.
Now, we can estimate the middle of each group of points. Let's add our estimated averages to the plot as starred points:
A scatter plot. The x-axis ranges from 30 to 110, in increments of 10. The y-axis ranges from 0 to 300, in increments of 50. The points are scattered in linear decreasing order. Some of the points are highlighted in red and the points are as follows: (50, 290), (48, 195), (48, 200), (49.5, 225), (50, 203), (78, 145), (79, 130), (80, 120), (81, 120), (81, 70), (82, 90), (82.5, 90), (82, 100), and (82, 120). Asterisks are marked at (50, 200) and (80, 120). Note: all values are approximate.
Since those two starred points occur at different heights, we can conclude that there’s likely a relationship worth exploring.
Here’s another example using a different set of data:
A scatter plot. The x-axis ranges from 30 to 110, in increments of 10. The y-axis ranges from 0 to 250, in increments of 50. The points are scattered throughout and it lies from 30 to 105 on the horizontal axis and 50 to 250 on the vertical axis.
Let’s look again at the points near 50 and near 80, and estimate the middles of those clusters:
A scatter plot. The x-axis ranges from 30 to 110, in increments of 10. The y-axis ranges from 0 to 250, in increments of 50. The points are scattered throughout and it lies from 30 to 105 on the horizontal axis and 50 to 250 on the vertical axis. Some of the points are marked in red: (48, 120), (48, 140), (50, 150), (50, 155), (48, 190), (51, 195), (82, 75), (80, 125), (81, 130), (80, 160), (81, 160), (82, 140), (81, 195), (81, 200), and (78, 210). Asterisks are marked at (50, 150) and (80, 170). Note all values are approximate.
Notice that there’s not much vertical distance between our two starred points. This tells us that there’s not a strong relationship between these two datasets.

Positive and Negative Linear Relationships

Another way to assess whether there is a relationship between two datasets in a scatter plot is to see if the points seem to be clustered around a line (specifically, a line that’s not horizontal). The stronger the clustering around that line is, the stronger the relationship.
Once we’ve established that there’s a relationship worth exploring, it’s time to start quantifying that relationship. Two datasets have a positive linear relationship if the values of the response tend to increase, on average, as the values of the explanatory variable increase. If the values of the response decrease with increasing values of the explanatory variable, then there is a negative linear relationship between the two datasets. The strength of the relationship is determined by how closely the scatter plot follows a single straight line: the closer the points are to that line, the stronger the relationship. The scatter plots in diagram to diagram depict varying strengths and directions of linear relationships.
A scatter plot. The x-axis ranges from 30 to 110, in increments of 10. The y-axis ranges from 210 to 290, in increments of 10. The points are arranged in linear decreasing order in a single row. Some of the points are as follows: (32, 288), (40, 280), (60, 260), (70, 250), (90, 230), and (100, 220). Note: all values are approximate.
Perfect negative relationship
A scatter plot. The x-axis ranges from 30 to 110, in increments of 10. The y-axis ranges from 200 to 300, in increments of 20. The points are arranged in linear decreasing order in multiple rows. Some of the points are as follows: (32, 287), (40, 281), (60, 260), (70, 245), (90, 230), and (100, 225). Note: all values are approximate.
Strong negative relationship
A scatter plot. The x-axis ranges from 30 to 110, in increments of 10. The y-axis ranges from 150 to 350, in increments of 50. The points are scattered throughout. Most points lie from 30 to 100 on the horizontal axis and 200 to 300 on the vertical axis.
Weak negative relationship
A scatter plot. The x-axis ranges from 30 to 110, in increments of 10. The y-axis ranges from 0 to 250, in increments of 50. The points are scattered throughout. Most points lie from 30 to 105 on the horizontal axis and 50 to 250 on the vertical axis.
No relationship
A scatter plot. The x-axis ranges from 20 to 110, in increments of 10. The y-axis ranges from 300 to 500, in increments of 20. The points are scattered at the center of the graph. Most points lie from 50 to 90 on the horizontal axis and 340 to 440 on the vertical axis.
Weak positive relationship
A scatter plot. The x-axis ranges from 20 to 110, in increments of 10. The y-axis ranges from 300 to 500, in increments of 20. The points are scattered in linear increasing order in a single row. Some of the points are as follows: (27, 345), (40, 360), (60, 380), (70, 390), (80, 400), and (100, 420). Note: all values are approximate.
Strong positive relationship
A scatter plot. The x-axis ranges from 20 to 110, in increments of 10. The y-axis ranges from 300 to 500, in increments of 20. The points are scattered in linear increasing order in a single row. Some of the points are as follows: (27, 345), (40, 360), (60, 380), (70, 390), (80, 400), and (100, 420). Note: all values are approximate.
Perfect positive relationship
The strength and direction (positive or negative) of a linear relationship can also be measured with a statistic called the correlation coefficient (denoted r). Positive values of r indicate a positive relationship, while negative values of r indicate a negative relationship. Values of r close to 0 indicate a weak relationship, while values close to ±1 correspond to a very strong relationship. Looking again at diagram to diagram, the correlation coefficients for each, in sequential order, are: ‒1, ‒0.97, ‒0.55, ‒0.03, 0.61, 0.97, and 1.
There’s no firm rule that establishes a cutoff value of r to divide strong relationships from weak ones, but ±0.7 is often given as the dividing line (i.e., if r>0.7 or r<-0.7 the relationship is strong, and if -0.7<r<0.7 the relationship is weak).
The formula for computing r is very complicated; it’s almost never done without technology. Google Sheets will do the computation for you using the CORREL function. The syntax works like this: if your explanatory values are in cells A2 to A50 and the corresponding response values are in B2 to B50, then you can find the correlation coefficient by entering “=CORREL(A2:A50, B2:B50)”. (Note that the order doesn’t matter for correlation coefficients; “=CORREL(B2:B50, A2:A50)” will give the same result.)
Let’s put all of this together in an example.

Interpreting Scatter Plots

Consider the four scatter plots below:
  1. A scatter plot shows points arranged in a parabolic path. The x-axis ranges from 30 to 20, in increments of 10. The y-axis ranges from negative 10 to 60, in increments of 10. The points are scattered in the form of an open upward parabola. Some of the points are as follows: (negative 20, 45), (negative 10, 10), (0, 0), (10, 10), and (15, 22). Note: all values are approximate.
  1. A scatter plot shows points arranged in increasing order. The x-axis ranges from 30 to 20, in increments of 10. The y-axis ranges from negative 100 to 150, in increments of 50. The points are scattered in increasing order. Some of the points are as follows: (negative 20, negative 50), (negative 10, 0), (0, 40), (10, 75), and (15, 100). Note: all values are approximate.
  1. A scatter plot shows points arranged in decreasing order. The x-axis ranges from 30 to 20, in increments of 10. The y-axis ranges from negative 20 to 20, in increments of 10. The points are scattered in decreasing order. Some of the points are as follows: (negative 20, 10), (negative 10, 5), (0, 0), (10, negative 5), and (15, negative 15). Note: all values are approximate.
  1. A scatter plot. The x-axis ranges from 30 to 20, in increments of 10. The y-axis ranges from 0 to 40, in increments of 5. The points are scattered throughout and the points lie from negative 20 to 15 on the horizontal axis and 0 to 30 on the vertical axis.
For each of these, answer the following questions:
  1. Is there a curved pattern in the data? If yes, stop here. If no, continue to part b.
  2. Classify the strength and direction of the relationship. Make a guess at the value of r.
Solution
    1. Yes, there is a curved pattern.
    1. No, there’s no curved pattern.
    2. Since the points tend upward as we move from left to right, this is a positive relationship. The points seem pretty closely grouped around a line, so it’s fairly strong. Comparing this scatter plot to those in diagram to diagram, we can see that the relationship is stronger than the one in diagram (r=0.61 ) but not as strong as the one in diagram (r=0.97). So, the value of the correlation coefficient is somewhere between the two. We might guess that r=0.9.
    1. No, there’s no curved pattern.
    2. Since the points tend downward as we move from left to right, this is a negative relationship. The points are not tightly grouped around a line, but the pattern is clear. It looks like it has approximately the same strength as the plot in diagram, just with the opposite sign. So, we might guess that r=-0.6.
    1. No, there’s no curved pattern.
    2. Since the points don’t really tend upward or downward as we move from left to right, there is no real relationship here. Thus, r≈0.

Finding the Correlation Coefficient

The data that were plotted in the previous example can be found in the dataset “correlationcoefficient1”. All of them share the same values for the explanatory variable x. The four responses are labeled y1 through y4 . Compute the correlation coefficients for each, if appropriate, using Google Sheets. Round to the nearest hundredth.
Solution
Step 1: There is a curved pattern in the data, so the correlation coefficient isn’t meaningful.
Step 2: Using “=CORREL(A2:A101, C2:C101)” we get r=0.89.
Step 3: Using “=CORREL(A2:A101, D2:D101)” we get r=-0.66.
Step 4: Using “=CORREL(A2:A101, E2:E101)” we get r=-0.04.

Linear Regression

The final step in our analysis of the relationship between two datasets is to find and use the equation of the regression line. For a given set of explanatory and response data, the regression line (also called the least-squares line or line of best fit) is the line that does the best job of approximating the data.
What does it mean to say that a particular line does the “best job” of approximating the data? The way that statisticians characterize this “best line” is rather technical, but we’ll include it for the sake of satisfying your curiosity (and backing up the claim of "best"). Imagine drawing a line that looks like it does a pretty good job of approximating the data. Most of the points in the scatter plot will probably not fall exactly on the line; the distance above or below the line a given point falls is called that point’s residual. We could compute the residuals for every point in the scatter plot. If you take all those residuals and square them, then add the results together, you get a statistic called the sum of squared errors for the line (the name tells you what it is: “sum” because we’re adding, “squared” because we’re squaring, and “errors” is another word for “residuals”). The line that we choose to be the “best” is the one that has the smallest possible sum of squared errors. The implied minimization (“smallest”) is where the “least” in “least squares” comes from; the “squares” comes from the fact that we’re minimizing the sum of squared errors. This is very similar to the process we outlined in the "game" that we used to introduce the mean. Both the regression line and the mean are designed to minimize a sum of squared errors. Here ends the super technical part.

Finding the Equation of the Regression Line

So, how do we find the equation of the regression line? Recall the point-slope form of the equation of a line:
The regression line has two properties that we can use to find its equation. First, it always passes through the point of means. If x¯ and y¯ are the means of the explanatory and response datasets, respectively, then the point of means is (x¯,y¯). We’ll use that as the point in the point-slope form of the equation. Second, if sx and sy are the standard deviations of the explanatory and response datasets, respectively, and if r is the correlation coefficient, then the slope is m=r×sysx. Putting all that together with the point-slope formula gives us this:
Let's walk through an example.

Finding the Equation of the Regression Line from Statistics

Suppose you have datasets x and y with the following statistics: x has mean 21 and standard deviation 4, y has mean 8 and standard deviation 2, and their correlation coefficient is −0.4. What’s the equation of the regression line?
Solution
Step 1: We’re given x¯=21, sx=4, y¯=8, sy=2, and r=-0.4. Let's start with the formula for the equation of the regression line:
y=r(sysx)(x-x¯)+y¯
Step 2: Plugging in our values gives us:
y=-0.4(24)(x-21)+8
Step 3: Our final regression line equation is:
y=-0.2x+12.2
As you can see, finding the equation of the regression line involves a lot of steps if you have to find all of the values of the needed quantities yourself. But, as usual, technology comes to our rescue. This video (which you actually watched earlier when learning how to create scatter plots) covers the regression line at around the 3:30 mark. Note that Google Sheets calls it the "trendline."
Let's put this into practice.

Finding the Equation of the Regression Line Using Google Sheets

In source illustration or discussion, we considered the relationship between goals scored (GF) and goals against (GA) using the dataset “NHL19”. Recreate the scatter plot in Google Sheets, and use it to find the equation of the regression line.
Solution
Once we have recreated the scatter plot, we find the equation of the regression line by clicking the three dots at the top right of the plot, selecting “Edit chart,” then clicking on “Customize” and “Series.” We add the regression line by checking the box next to “Trendline,” and then we show the equation by selecting “Use Equation” in the drop-down menu under “Label.” The equation of the tangent line is y=-0.0554x+261.

Using the Equation of the Regression Line

Once we’ve found the equation of the regression line, what do we do with it? We’ll look at two possible applications: making predictions and interpreting the slope.
We can use the equation of the regression line to predict the response value y for a given explanatory value x. All we have to do is plug that explanatory value into the formula and see what response value results. This is useful in two ways: first, it can be used to make a guess about an unknown data value (like one that hasn’t been observed yet). Second, it can be used to evaluate performance (meaning, we can predict an outcome given a particular event). In source illustration or discussion, we created a scatter plot of final exam scores vs. midterm exam scores using this data:
Name Midterm Grade Final Grade
Allison 88 84
Benjamin 71 80
Carly 75 77
Daniel 94 95
Elmo 68 73
The equation of the regression line is y=0.687x+27.4, where y is the final exam score and x is the midterm exam score. If Frank scored 85 on the midterm, then our prediction for his final exam score is 0.687×85+27.4=85.795. To use the regression line to evaluate performance, we use a data value we’ve already observed. For example, Allison scored 88 on the midterm. The regression line predicts that someone who scores an 88 on the midterm will get 0.687×88+27.4=87.856 on the final. Allison actually scored 84 on the final, meaning she underperformed expectations by almost 4 points (87.856-84).
The second application of the equation of the regression line is interpreting the slope of the line to describe the relationship between the explanatory and response datasets. For the exam data in the previous paragraph, the slope of the regression line is 0.687. Recall that the slope of a line can be computed by finding two points on the line and dividing the difference in the y-values of those points by the difference in the x-values. Keeping that in mind, we can interpret our slope as 0.687=difference in final scoresdifference in midterm scores . Multiplying both sides of that equation by the denominator of the fraction, we get 0.687×difference in midterm scores=difference in final scores. Thus, a one-point increase in the midterm score would result in a predicted increase in the final score of 0.687 points. A ten-point drop in the midterm score would give us a decrease in the predicted final score of 6.87 points. In general, the slope gives us the predicted change in the response that corresponds to a one unit increase in the explanatory variable.

Applying the Equation of the Regression Line

The data in “MLB2019Off” gives offensive team stats for the 2019 Major League Baseball season. Use that dataset to answer the following questions:
  1. What is the equation of the regression line for runs (R) vs. hits (H)?
  2. How many runs would we expect a team to score if the team got 1500 hits in a season?
  3. Did the Kansas City Royals (KCR) overperform or underperform in terms of runs scored, based on their hit total? By how much?
  4. Write a sentence to interpret the slope of the regression line.
Solution
  1. Using Google Sheets, we find that the regression line equation is y=0.884x–456, where y is the number of runs scored and x is the number of hits.
  2. Plugging 1500 into the equation of the regression line, we get 0.884×1500-456=870. We would predict that a team with 1500 hits would score 870 runs.
  3. The Royals had 1356 hits, so we would predict their run total to be 0.884×1356-456≈743. They actually scored 691 runs, so they underperformed expectations by 52 runs (743–691).
  4. The slope gives us the predicted change in the response that corresponds to a one unit increase in the explanatory variable. So, we expect one additional hit to result in 0.884 more runs. Since 0.884 runs doesn’t really make sense, we can get a better interpretation by multiplying through by ten or one hundred: Ten additional hits will result in almost nine additional runs, or a hundred additional hits will yield on average just over 88 additional runs.