Skip to content
Pixel
العربية

6-2Unit 6 · Analysis and Communication

Use and Evaluation of Regression Analysis

12 min readStart exercises
In this lesson
  1. The Big Idea
  2. What Is Regression Analysis?
  3. Simple Regression: A Line Through the Points
  4. Multiple Regression: More Than One Explanatory Variable
  5. Judging a Model: Evaluation Metrics
  6. Correlation Is Not Causation
  7. Cautions When Using Regression Models
  8. Try It Yourself
  9. Common Mistakes
  10. Key Points
  11. FAQ

The Big Idea

Regression analysis turns a relationship you notice in data into an equation you can calculate with: "the hotter the day, the more ice cream we sell". You build the equation from past data, then use it to explain or to predict. But the equation alone is not enough. You have to evaluate the model with more than one measure, such as R², RMSE and MAE, and you must never forget that a good fit does not prove that one variable causes the other.

What Is Regression Analysis?

Regression analysis is a way of building a mathematical model that describes the estimated relationship between a variable we want to understand or predict and one or more variables we use to help. The model can be used to explain or to predict, as long as it is appropriate and fit for the purpose it was built for.

Every regression has two kinds of variable:

  • Response variable: the variable the model tries to explain or predict, the "outcome". In the ice cream example it is sales.
  • Explanatory variable: the variable used to help explain or predict, the "input". In the example it is temperature.

The model: a simplified picture of reality

The equation we get from the data is called the model. A model is a simplified representation of a real relationship: it takes a general trend such as "higher temperature, higher sales" and puts it in a form you can compute. "Simplified" matters: reality contains many factors the model leaves out, so it will not match every actual value exactly.

To use a model in practice, getting the equation is not enough. We need to check:

  1. its fit to the data: does it pass close to the points?
  2. its prediction error: how far are its predictions from the actual values, on average?
  3. its assumptions: does the shape of the relationship suit the model we chose?
  4. its performance on suitable data: does it work on data it was not built from?
  5. the limits of the range it was built from: a model built from days between 20 and 36 °C should not be trusted the same way on a 48 °C day.

Simple Regression: A Line Through the Points

Simple regression models the response variable with one explanatory variable only. The book's example: model ice cream sales y from temperature x with a straight line called the regression line:

y = ax + b
  • y: the response variable (predicted sales).
  • x: the explanatory variable (temperature).
  • a: the coefficient, the weight given to the explanatory variable. For a straight line it tells you how much the prediction changes when x goes up by one unit.
  • b: the intercept, the constant in the equation.

Example: predicting with the line

Suppose a shop recorded sales on five days and got the regression line y = 3x + 10, where x is the temperature in °C and y is the number of cups.

  • The coefficient a = 3: each extra degree is linked to 3 more cups in the prediction.
  • If tomorrow's forecast is 30 °C: prediction = 3 × 30 + 10 = 100 cups.

Notice that we plug in a value inside the range of the data (the recorded days were between 20 and 36 °C). If we plugged in 0 °C we would get 10 cups, a number with no practical meaning here, because the model never saw a day anywhere near that temperature.

The residual: how far off was the line at each point?

The line does not pass through every point. The difference between what actually happened and what the line predicted is the residual:

residual = actual value − predicted value

On the 24 °C day, the line predicted 3 × 24 + 10 = 82 cups, but actual sales were 78. So the residual = 78 − 82 = −4. A negative sign means the line over-predicted; a positive one means it under-predicted.

The regression line and residuals Scatter plot of five days: temperature on the horizontal axis from 20 to 36 degrees, ice cream sales in cups on the vertical axis. The regression line y = 3x + 10 runs through the points. A red dashed segment from each point to the line shows the residual. Worked example: at 24 degrees actual sales were 78 cups and predicted sales 82, so the residual is 78 minus 82, which is minus 4. Footer: least squares picks the line that makes the sum of squared residuals as small as possible. 60 80 100 120 20 24 28 32 36 Temperature (°C) = explanatory variable x Sales (cups) = response variable y y = 3x + 10 At 24 °C: actual 78, predicted 82 residual = actual − predicted 78 − 82 = −4 actual value regression line residual Least squares: the line with the smallest sum of squared residuals
The solid line is the prediction; the red dashed segments are the residuals, the line's error at each point.

Least squares: choosing the best line

You could draw many lines through the points, so which one do we pick? The common method is least squares: work out the residual for each point, square it, add up the squares, and choose the line that makes this sum as small as possible. The book says the line's coefficients are often estimated this way.

Why square? Two simple reasons: squaring makes every error positive, so a positive error cannot cancel a negative one, and it makes a big error count much more than a small one. In our example the residuals were 3, −4, 2, −4 and 3, and the sum of their squares is 54. Try another line such as y = 3x + 12 and the sum of squares becomes 74, so the first line is better by the least-squares measure.

Multiple Regression: More Than One Explanatory Variable

In real life an outcome usually depends on more than one factor. A flat's price is not set by its size alone. That is where multiple regression comes in: modelling the response variable with several explanatory variables. The book's example: predicting a house price from its size, its age and its distance from the transport station.

With two explanatory variables the equation becomes:

y = a1x1 + a2x2 + b

Each explanatory variable has its own coefficient (a1, a2, …), and a third variable simply adds another term of the same kind.

Reading a coefficient in multiple regression

A coefficient describes how much the prediction changes when that variable increases by one unit while the other variables are held fixed. If the coefficient for "house age" is negative, the model predicts a lower price for an older house when size and distance are the same. Note the book's warning: this describes the prediction; it is not an automatic causal explanation.

Simple versus multiple regression Two panels. Simple regression: one explanatory variable, temperature x, goes into the model y = ax + b, which outputs a prediction of ice cream sales y. Multiple regression: three explanatory variables, house size x1, age x2 and distance from the station x3, each with its own coefficient a1, a2 and a3, go into the model y = a1x1 + a2x2 + a3x3 + b, which outputs a predicted house price y. Footer warning: a coefficient describes how the prediction changes with the other variables held fixed, not a cause, and more variables do not necessarily make a better model. 1) Simple regression: one explanatory variable Temperature x Model y = ax + b Ice cream sales y 2) Multiple regression: several explanatory variables House size x1 a1 House age x2 a2 Distance to station x3 a3 Model y = a1x1 + a2x2 + a3x3 + b House price y Coefficient = change in prediction per unit, others held fixed (not a cause) More variables do not necessarily mean a better model
The key difference is the number of explanatory variables: one in simple regression, two or more in multiple regression.

Quick comparison

| Aspect | Simple regression | Multiple regression | | ------------------------------- | --------------------------------------------------- | ----------------------------------------------------- | | Number of explanatory variables | One | Two or more | | Model features | Simple and easy to interpret | Can express more complex relationships | | When to use it | To model the response with one explanatory variable | To include several explanatory variables in the model |

Judging a Model: Evaluation Metrics

Once the model is built, ask: is it useful? To answer, we use evaluation metrics. The book presents three typical ones:

| Metric | Idea | How to read it | | ------------------------------------- | ----------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ | | R² (coefficient of determination) | How much of the variation in the data the model explains, compared with a reference model | Closer to 1 means the model explains the variation better, but it is not enough on its own | | RMSE (root mean squared error) | Square the residuals, average them, then take the square root | Smaller means more accurate predictions; more affected by large errors | | MAE (mean absolute error) | The average of the residuals' absolute values (ignore the sign) | Smaller means more accurate predictions; less affected by very large errors than RMSE |

R²: how much of the variation does the model explain?

Sales change from day to day; that spread is the variation (variance). R² shows how much of it the model explains. In the simplified educational setting it is usually shown between 0 and 1: close to 1 means the model explains a large share of the variation, close to 0 means it explains little.

But the book warns that a high R² is not enough on its own to judge a model, and it tells you nothing about performance on new data. When comparing models with different numbers of variables, adjusted R² can be used.

RMSE and MAE: the size of prediction errors

Both RMSE and MAE measure how big the prediction errors are, and both are in the same units as the response variable: if we predict cups, MAE = 3 means the model is off by about 3 cups on average. They differ in how they treat large errors.

Example: two models predict sales for four days.

  • Model A residuals: 2, −2, 4, −4.
  • Model B residuals: 1, −1, 1, −9.

| | MAE | RMSE | | ------- | --- | ---------- | | Model A | 3 | about 3.16 | | Model B | 3 | about 4.58 |

The MAE is the same for both models, because it averages the errors without their signs. But Model B's RMSE is clearly larger, because squaring blew up the one big error (−9). So:

  • If a big error is very costly (for example, running badly short of a medicine), RMSE flags it.
  • If the data contain a few outliers you don't want to dominate the verdict, MAE is less affected by them.

That is why the book says the two are used according to the purpose of the analysis.

Correlation Is Not Causation

This is the most important idea in the lesson. Two variables moving together (correlation) does not mean one causes the other (causation). Regression analysis on its own cannot prove causation, however good the fit.

The book's example: a city notices that months with higher ice cream sales also have more swimming accidents, and the regression line between them shows a strong relationship. Does ice cream cause accidents? No. A hidden third cause drives both: hot weather. In the heat people buy more ice cream and also go to the beach and pools more, so accidents rise. This hidden cause is called a confounder.

Correlation is not causation: the confounder At the top a box labelled hot weather, described as a confounder, a hidden third cause. Two arrows come out of it: one to ice cream sales rise and one to swimming accidents increase. Between the two bottom boxes a dashed line labelled strong correlation, and a crossed-out arrow meaning ice cream does not cause the accidents. Footer: a regression line between them may fit well, but fit alone does not prove causation. Hot weather Confounder: a hidden third cause Ice cream sales rise Swimming accidents increase strong correlation Ice cream does not cause accidents The line may fit the data well, but fit alone does not prove causation
A confounder moves both variables together, creating a strong correlation with no causal link between them.

So what does a causal claim need?

The Arabic edition says a causal claim needs a study design and additional evidence that allow causal inference, and that a good fit or coming first in time is not enough on its own. Things we usually need include: the cause coming before the effect, ruling out other factors such as confounders, and a sensible theoretical explanation. None of them is enough alone.

Cautions When Using Regression Models

Regression is widely used, but misusing it leads to wrong conclusions. The book sums up four cautions:

  1. Don't confuse correlation with causation: regression alone does not prove that an explanatory variable is a cause.
  2. A model isn't finished just because it exists: check its accuracy with evaluation metrics and confirm it is fit for the purpose.
  3. Don't rely on R² alone: check prediction errors (RMSE and MAE), assumptions and performance on data not used for fitting.
  4. More explanatory variables don't necessarily improve the model: choose variables that suit the purpose.

In the end, regression results are not absolute truth but one perspective offered by the data, to be interpreted carefully and combined with real-world judgement.

Try It Yourself

Try
Move a and b and watch the residuals
20242832366080100120x (°C)
Temperature x (°C)Sales y (cups)
y = ax + b
y = 2x + 30
Sum of squared residuals
549
Sum of squared residuals: 549
The red dashed lines are the residuals (actual − predicted). Try to make the sum of their squares as small as you can.

Change a (the slope) and b (the intercept) until the line passes close to most of the points. Watch how the residuals grow when the line drifts away from the trend, and try to make the sum of their squares as small as possible: that is the least-squares idea.

Try
Simple or multiple?
Sort each situation by how many explanatory variables the model uses.
Items (8)
Tap an item to select it, then tap the category it belongs to.
Nothing here yet
Nothing here yet
Try
Phones and marks
The situation
A school collected data on 300 students and found that students who spend more time on their phones get lower marks, and the regression line between the two fits the data well. The head teacher wants to write in a report: 'It is proven that phone use causes lower marks.' What do you advise?
What would you do? You can try more than one choice.

Common Mistakes

"If the regression line fits well, the explanatory variable causes the outcome"

A good fit means the two variables move together, and a hidden confounder such as hot weather may be moving both.

Regression alone does not prove causation; a causal claim needs a study design and additional evidence.

"R² is close to 1, so the model is excellent and nothing else needs checking"

R² only describes how much variation is explained. It says nothing about the size of the errors or about performance on new data.

Use R² together with RMSE and MAE, and test the model on data not used for fitting.

"The more explanatory variables I add, the better the model"

Variables unrelated to the purpose make the model more complex for no gain, and can make it chase noise.

Choose variables that suit the purpose; when comparing models with different numbers of variables, adjusted R² can be used.

"RMSE and MAE are the same measure with different names"

Both measure error size, but RMSE squares the errors and so gives large ones more weight, while MAE is less affected by outliers.

Two models can have the same MAE and different RMSEs because of a single big error.

"A residual is the predicted value minus the actual value"

The order matters, because the sign tells you which way the model was wrong.

Residual = actual − predicted; a negative residual means the model predicted more than happened.

Key Points

  • Regression analysis builds a mathematical model of the estimated relationship between a response variable (the outcome) and one or more explanatory variables (the inputs), for explanation or prediction.
  • A model is a simplified picture of reality and isn't finished when it is built: check its fit, errors, assumptions, performance and range.
  • Simple regression uses one explanatory variable with the line y = ax + b; multiple regression uses several, e.g. y = a1x1 + a2x2 + b.
  • Residual = actual − predicted, and least squares picks the line with the smallest sum of squared residuals.
  • In multiple regression a coefficient describes the change in prediction per unit with the other variables held fixed, with no automatic causal meaning.
  • R² shows explained variation and is usually shown between 0 and 1 in the simplified setting, but it is not enough on its own.
  • RMSE and MAE measure prediction error in the response's units; RMSE is more affected by large errors, MAE less affected by outliers.
  • Correlation is not causation: a confounder may lie behind the relationship, and a good fit alone does not prove a cause.

FAQ

What's an easy way to tell the response variable from the explanatory variable?

The response variable is what you want to predict or explain: the outcome, such as sales or a house price. The explanatory variable is what you use to help predict it: the input, such as temperature or house size. Ask yourself: what do I want to find out? That is the response variable.

Do I have to calculate R² or RMSE in the exam?

The book explains what each metric means and gives no worked calculations for them. What matters is knowing what each one measures, how to read it, how RMSE differs from MAE, and why R² is not enough alone. It also helps to be able to plug numbers into an equation like y = ax + b and work out a residual.

Why is RMSE sometimes bigger than MAE when both measure error?

Because RMSE squares the errors before averaging, so a big error becomes much bigger after squaring and pushes the result up. If a model has one large error, its RMSE rises clearly while its MAE changes less.

If regression can't prove causation, what is it good for?

A lot: prediction and planning. A school canteen can estimate how many drinks to order from the temperature without claiming that temperature alone is the cause. The point is not to turn a correlation into a causal claim without a study design and additional evidence.

Done reading? Test yourself