0% found this document useful (0 votes)
253 views12 pages

Multiple Linear Regression by Hand (Step-by-Step)

This document is a tutorial on performing multiple linear regression by hand, detailing the steps involved in calculating regression coefficients and interpreting the results. It provides a step-by-step example using specific formulas to derive the coefficients b0, b1, and b2 from a given dataset. The tutorial aims to simplify the understanding of multiple linear regression for learners in statistics and machine learning.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
253 views12 pages

Multiple Linear Regression by Hand (Step-by-Step)

This document is a tutorial on performing multiple linear regression by hand, detailing the steps involved in calculating regression coefficients and interpreting the results. It provides a step-by-step example using specific formulas to derive the coefficients b0, b1, and b2 from a given dataset. The tutorial aims to simplify the understanding of multiple linear regression for learners in statistics and machine learning.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

7/30/24, 1:04 PM Multiple Linear Regression by Hand (Step-by-Step)

About Course Basic Stats Machine Learning Software Tutorials  Tools 

Multiple Linear Regression by


Hand (Step-by-Step)
 BY ZACH BOBBITT  NOVEMBER 18, 2020

Multiple linear regression is a method we can


use to quantify the relationship between two or
more predictor variables and a response
variable.

This tutorial explains how to perform multiple


linear regression by hand.

Example: Multiple Linear


Regression by Hand
Suppose we have the following dataset with one
response variable y and two predictor variables
X1 and X2:

Use the following steps to fit a multiple linear


regression model to this dataset.

Step 1: Calculate X12, X22, X1y, X2y and X1X2.

[Link] 1/12
7/30/24, 1:04 PM Multiple Linear Regression by Hand (Step-by-Step)

Step 2: Calculate Regression Sums.

Next, make the following regression sum


calculations:

2
Σx1 = ΣX12 – (ΣX1)2 / n = 38,767 – (555)2 / 8
= 263.875
Σx2
2 = ΣX 2 – (ΣX2)2 / n = 2,823 – (145)2 / 8
2
= 194.875
Σx1y = ΣX1y – (ΣX1Σy) / n = 101,895 –
(555*1,452) / 8 = 1,162.5
Σx2y = ΣX2y – (ΣX2Σy) / n = 25,364 –
(145*1,452) / 8 = -953.5
Σx1x2 = ΣX1X2 – (ΣX1ΣX2) / n = 9,859 –
(555*145) / 8 = -200.375

Step 3: Calculate b0, b1, and b2.

The formula to calculate b1 is: [(Σx22)(Σx1y) –


(Σx1x2)(Σx2y)] / [(Σx12) (Σx22) – (Σx1x2)2]

[Link] 2/12
7/30/24, 1:04 PM Multiple Linear Regression by Hand (Step-by-Step)

Thus, b1 = [(194.875)(1162.5) – (-200.375)


(-953.5)] / [(263.875) (194.875) – (-200.375)2]
= 3.148

The formula to calculate b2 is: [(Σx12)(Σx2y) –


(Σx1x2)(Σx1y)] / [(Σx12) (Σx22) – (Σx1x2)2]

Thus, b2 = [(263.875)(-953.5) – (-200.375)


(1152.5)] / [(263.875) (194.875) – (-200.375)2]
= -1.656

The formula to calculate b0 is: y – b1X1 – b2X2

Thus, b0 = 181.5 – 3.148(69.375) – (-1.656)


(18.125) = -6.867

Step 5: Place b0, b1, and b2 in the estimated


linear regression equation.

The estimated linear regression equation is: ŷ


= b0 + b1*x1 + b2*x2

In our example, it is ŷ = -6.867 + 3.148x1 –


1.656x2

How to Interpret a Multiple Linear


Regression Equation
Here is how to interpret this estimated linear
regression equation: ŷ = -6.867 + 3.148x1 –
1.656x2

b0 = -6.867. When both predictor variables are


equal to zero, the mean value for y is -6.867.

[Link] 3/12
7/30/24, 1:04 PM Multiple Linear Regression by Hand (Step-by-Step)

b1 = 3.148. A one unit increase in x1 is


associated with a 3.148 unit increase in y, on
average, assuming x2 is held constant.

b2 = -1.656. A one unit increase in x2 is


associated with a 1.656 unit decrease in y, on
average, assuming x1 is held constant.

Additional Resources
The following tutorials provide additional
information about linear regression:

An Introduction to Multiple Linear Regression


How to Perform Multiple Linear Regression in
Excel
How to Perform Simple Linear Regression by
Hand

POSTED IN PROGRAMMING •

Zach Bobbitt
Hey there. My name is Zach Bobbitt. I
have a Masters of Science degree in
Applied Statistics and I’ve worked on
machine learning algorithms for
professional businesses in both healthcare and retail.
I’m passionate about statistics, machine learning, and
data visualization and I created Statology to be a
resource for both students and teachers alike. My
goal with this site is to help you learn statistics through
using simple terms, plenty of real-world examples, and
helpful illustrations.

[Link] 4/12
7/30/24, 1:04 PM Multiple Linear Regression by Hand (Step-by-Step)

PREV NEXT
An Introduction to Polynomial An Introduction to Multivariate
Regression Adaptive Regression Splines

21 Replies to “Multiple Linear Regression


by Hand (Step-by-Step)”
Arko
May 10, 2021 at 5:36 pm

What about F test, T test, r, rsqure?


REPLY

Amir
June 14, 2021 at 3:59 am

Hi there, how to find the value of b1,b2


and b3 , if there is 3 independent
variables , what formula shoud I use?
Hope you can share your solution and
thanks in advanced. Have a good day.
REPLY

Shawn McMurdo
January 7, 2022 at 9:44 pm

Hi Zach,
Thanks for this tutorial!
I am unclear on how to extend this from
2 variables to 3.
Can you provide some guidance?
Thanks!
REPLY

Sarah
February 28, 2022 at 12:29 pm

Hi Zach — could you clarify where your


formulas came from? Thanks
REPLY

[Link] 5/12
7/30/24, 1:04 PM Multiple Linear Regression by Hand (Step-by-Step)

sdfsdf
March 23, 2022 at 1:57 pm

So, how to calculate 3 variable multiple


linear regression by hand
REPLY

shai
April 15, 2022 at 12:00 pm

This was really sooo helpful thank you


so much!
REPLY

Fatima
April 20, 2022 at 5:54 am

Need more examples


REPLY

Prisca mkongwa
May 30, 2022 at 2:46 am

Your formula are very useful but I advice


you to use the example which are
relevance to many people and also
which have many independent variables
rather than use simple example but we
can not refer them to our studies.
Thanks Your document are very useful.
REPLY

Duncan Jack
August 17, 2022 at 7:03 am

Thank you Zach, most helpful.


REPLY

Ralph
September 21, 2022 at 9:52 pm

[Link] 6/12
7/30/24, 1:04 PM Multiple Linear Regression by Hand (Step-by-Step)

Do you have an example how to do


Multiple Linear Regression with say 5
variables in Excel without using the
Regression Tool in Data Analysis
REPLY

Evan Smart
September 28, 2022 at 6:32 am

This resource is a total lifesaver. Thank


you and bless you!
REPLY

Barry
November 10, 2022 at 8:19 am

Thanks, this was really helpful.

I think there is a small mistake in the


working for b_2. In the calculation below,
1152.5 should be 1162.5. The answer is
correct so it looks like just a typo.

Thus, b2 = [(263.875)(-953.5) –
(-200.375)(1152.5)] / [(263.875)
(194.875) – (-200.375)2] = -1.656
REPLY

Barry
January 15, 2023 at 8:59 am

1152.5 in the line below should be


1162.5.

Thus, b2 = [(263.875)(-953.5) –
(-200.375)(1152.5)] / [(263.875)
(194.875) – (-200.375)2] = -1.656
REPLY

[Link] 7/12
7/30/24, 1:04 PM Multiple Linear Regression by Hand (Step-by-Step)

Tamanna
February 28, 2023 at 6:47 am

Thanks a lot,for using such questions of


multiple linear regressions which are
more likely to practice for exam ,the
explanation helps a [Link]
khairun(Thank you)
REPLY

Ibrahim.h
April 30, 2023 at 9:48 am

Great work!
The only small mistake is 1152.5 which
need to be 1162.5 according to the “Reg
Sums” above.
REPLY

Ros Ugaddan
June 23, 2023 at 11:36 am

thank you, sir,


this is very useful.
REPLY

Dipesh Prabhakar Borse


October 8, 2023 at 1:04 pm

HOW TO MAKE X1,X,2,X3,X4


INDEPENDNET REGRTION WITH THE
HELP OF Y DEPENDNET PARAMETER
ANY STEP IS AVAILABLE IN
MATHEMATICALLY TO FIND THE
PREDICTABLE Y VALUES
REPLY

Dipesh Prabhakar Borse


October 8, 2023 at 1:08 pm

[Link] 8/12
7/30/24, 1:04 PM Multiple Linear Regression by Hand (Step-by-Step)

The formula to calculate b1 is: [(Σx22)


(Σx1y) – (Σx1x2)(Σx2y)] / [(Σx12) (Σx22)
– (Σx1x2)2]
WHAT IS THE FORMULA MAKING TO
FIND OUT b2,b3,b4 in multiple linear
regression module
REPLY

yash
March 10, 2024 at 4:45 am

[(Σx2^2)(Σx1y)

It’s supposed to be Sigma X1^2 for B1.


Please check for B2 as well.
REPLY

yash
March 10, 2024 at 5:10 am

Ok. Im sorry, your formula is correct.


Dont you have excel formula for the
above? It tedious task for 20 variables.
REPLY

yash
March 10, 2024 at 6:50 am

Hello again, I think using Sum of Y is


giving better b0 = Y-b1x1-b2x2-b3x3-
b4x4 value cause =Slope(), LINEST()
slope results using sum of Y is more
accurate than using Average of Y
REPLY

Leave a Reply

[Link] 9/12
7/30/24, 1:04 PM Multiple Linear Regression by Hand (Step-by-Step)

Your email address will not be published.


Required fields are marked *

Comment *

Name *

Email *

POST COMMENT

SEARCH

Search … 

ABOUT STATOLOGY

Statology makes learning statistics easy by


explaining topics in simple and straightforward
ways. Our team of writers have over 40 years of
experience in the fields of Machine Learning, AI
and Statistics. Learn more about our team
here.

[Link] 10/12
7/30/24, 1:04 PM Multiple Linear Regression by Hand (Step-by-Step)

FEATURED POSTS

How to Use the WHERE Clause to Filter Query Results


in MySQL
July 29, 2024

How to Visualize Symmetric and Skew-Symmetric


Matrices with Heatmaps in Python
July 29, 2024

How to Get the Current Date and Time in Python


July 29, 2024

How to Set Up Python for Time Series Analysis


July 29, 2024

How to Use Scikit-learn for Outlier Detection


July 26, 2024

5 Free R Courses for Stats & Analytics


July 26, 2024

STATOLOGY STUDY

Statology Study is the ultimate online statistics study guide that helps
you study and practice all of the core concepts taught in any elementary
statistics course and makes your life so much easier as a student.

INTRODUCTION TO STATISTICS COURSE

[Link] 11/12
7/30/24, 1:04 PM Multiple Linear Regression by Hand (Step-by-Step)

Introduction to Statistics is our premier online video course that


teaches you all of the topics covered in introductory statistics. Get
started with our course today.

YOU MIGHT ALSO LIKE

How to Perform Linear Regression by Hand

Excel: How to Use Multiple Linear Regression


for…

Excel: How to Interpret P-Values in Regression


Output

How to Calculate R-Squared by Hand

What is Y Hat in Statistics?

How to Use the Tilde Operator (~) in R

© 2023 Statology | Privacy Policy

[Link] 12/12

You might also like