arrow

Research Skills

Regression Equation: How to Find, Understand and Use a Regression Equation with a Simple Example

A regression equation is a mathematical method for predicting unknown values from known data. Using a simple example of study time and exam scores, this article walks step by step through calculating the slope and intercept and building a regression equation, and also explains how to compute them with Excel and Python. You will also learn what a regression equation means, how it differs from a correlation coefficient, the different regression types, and how to avoid common problems such as

Regression Equation: How to Find, Understand and Use a Regression Equation with a Simple Example

A regression equation lets you predict one value from another. If you know how many hours a student studied, you can use a regression equation to estimate their exam score. The most common type is a straight line drawn through the data points, often called the line of best fit. Let's find that line, work out what it says, and see which mistakes people often make.

What is a regression equation?

A regression equation is a formula that predicts one value from another. Here is the simplest form:

ŷ = b0 + b1x

The little hat over ŷ means "predicted value". x is the value you already know. b0 is the intercept and b1 is the slope. You don't pick them by guessing. A method called least squares finds the line that comes closest to all the data points.

Two more terms come up often. The dependent variable is what you want to predict, such as an exam score. The independent variable is what you use to make the prediction, such as study time. The b values are your regression coefficients.

Part

Name

Meaning

Our example

ŷ

Predicted value

The score the line expects

85.6 for 6 hours of study

x

Independent variable

What you already know

Study time

b0

Intercept

Predicted score for 0 hours of study

48.4

b1

Slope

Points gained per extra hour

6.2

How to find the regression equation step by step

We'll use data from five students. They studied 1, 2, 3, 4 and 5 hours. Their scores were 55, 60, 68, 72 and 80.

  1. Draw a scatter plot. Study time goes along the bottom axis and scores go up the side. If the points roughly follow a straight line, you can continue.

  2. Do some addition. There are 5 students. Study time adds up to 15. Scores add up to 335. Multiply each student's study time by their score and add the products to get 1,067. Square each study time and add them to get 55.

  3. Calculate the slope. Multiply 5 by 1,067 to get 5,335. Multiply 15 by 335 to get 5,025. Subtract and you get 310. Now multiply 5 by 55 to get 275, then subtract 15 squared (225) to get 50. Divide 310 by 50 to get a slope of 6.2.

  4. Calculate the intercept. Multiply the slope by 15 to get 93. Subtract 93 from 335 to get 242. Divide by 5 to get 48.4.

  5. Put it together. Your equation is ŷ = 48.4 + 6.2x.

Let's test it. For 6 hours of study, 6.2 times 6 is 37.2, plus 48.4 gives 85.6. So the line predicts a score of about 86.

Working it out by hand once is a good way to see how it works. After that, let software do the heavy lifting. In Excel, put study time in column A and scores in column B. Then type =SLOPE(B2, A2) in one cell and =INTERCEPT(B2, A2) in another. In Python, np.polyfit(x, y, 1) gives you both values at once. Either way, you should get 6.2 and 48.4.

It also helps to see how real researchers present their models.A summarization tool can condense a paper into its methods and main findings, making it easier to spot the equations they used.

How to understand your regression equation

Getting the numbers is only half the job. The other half is understanding what they say.

The slope is 6.2. That means that on average, each extra hour of study is associated with about 6.2 more points. The intercept is 48.4, the predicted score for someone who studied zero hours. Be careful with this. Sometimes the intercept is just a mathematical starting point and doesn't represent anything real.

The R-squared value shows how much of the variation in scores the line explains. In our small example it is about 0.99, which means a very good fit. Real data is never this tidy, so don't be surprised if you get a smaller value.

Then there are the residuals, the gap between the actual and predicted values. For the student who studied 3 hours, the line predicts 67. But his actual score was 68. The residual is 1. Small, evenly spread residuals are a good sign.

Regression equation vs. correlation coefficient

These two are often confused. The correlation coefficient, called r, is a single number between minus 1 and plus 1. It tells you how strong the link is and whether the two move in the same direction. For our students, r is about 0.995.

A regression equation goes further. It gives you a rule you can use. A correlation says "study time and scores move together". A regression equation says "after 6 hours of study, expect a score of about 85.6".

Which regression type should you use?

Let the data decide. A quick scatter plot usually points you in the right direction.

Type

When to use it

Example

Simple linear regression

One predictor with a straight-line trend

Study time and scores

Multiple regression

Two or more predictors

Predicting house price from size and age

Polynomial regression

Data points follow a curve

Growth that speeds up over time

Logistic regression

The outcome is yes or no

Pass or fail

Common mistakes to avoid

Predicting outside your data range. This is called extrapolation, and many people trip up here. Our data only covers 1 to 5 hours. Try predicting 20 hours and the line gives 172.4, which isn't even a possible score. Stay within the range you measured.

Ignoring outliers. One unusual data point can pull the whole line off course. If a point sits far from the others, find out why.

Assuming causation. A strong link doesn't prove that one thing causes another. Ice cream sales and sunburns both rise in summer, but ice cream doesn't give anyone a sunburn.

Using a straight line on curved data. If your points follow a curve, a straight line will mislead you. Polynomial regression may fit better.

Swapping x and y. Predicting scores from study time gives a different line from predicting study time from scores. Decide which is which before you start.

If you're studying papers that use regression analysis, Canyam also has an analysis tool you can try.

Frequently asked questions

What is the formula for linear regression?

It is ŷ = b0 + b1x. b0 is the intercept and b1 is the slope.

How do I find the regression equation in Excel?

Use the SLOPE and INTERCEPT functions, entering the y values first and then the x values. You can also add a trendline to a chart and tick the option to display the equation.

What is the difference between slope and intercept?

The slope shows how much y changes when x increases by 1. The intercept is the predicted y value when x is zero.

Can I trust predictions outside my data range?

Not really. The line only describes the range of data you measured, so predictions outside that range can be badly off.

What is Canyam?

Canyam is an academic discovery platform that helps you explore academic papers. It offers summarization and analysis tools, and you can save the content you like.

Final thoughts

A regression equation is really just a straight line written as a formula. Plot your data, find the slope and intercept, and explain what each number means in plain language. Then watch out for outliers and keep your predictions within the range of data you actually measured.