Linear Regression
Linear Regression
b = 𝑦−𝑚𝑥
Where
𝑚 is the slope;
𝑛 is the sample size;
𝑛
𝑖=1 𝑥𝑖 𝑦𝑖 is the some of all products of x and y;
𝑛
𝑖=1 𝑦𝑖 is the sum of all y;
𝑛 2 2
𝑖=1 𝑥𝑖 is the sum of all X ;
𝑛 2 is the square of the sum of all x;
𝑖=1 𝑥𝑖
b is the y-intercept;
𝑦 is the mean of all y;
𝑥 is the mean of all x.
Substituting the values to the formulas:
Study the given example below and its calculation. 𝑛 𝑛 𝑛
𝑛 𝑖=1 𝑥𝑖 𝑦𝑖 − 𝑖=1 𝑥𝑖 𝑖=1 𝑦𝑖
𝑚= 2
It has been established that there is a positive correlation 𝑛 2 𝑛
𝑛 𝑖=1 𝑥𝑖 − 𝑖=1 𝑥𝑖
between scores in mathematics and English for a group of ten 𝑚=
10 298 −(48)(50)
students. The data are given below. 10 296 − (48)2
𝑚 = 0.884146
Using these data, determine the linear regression equation and If x = 10,
use this equation to predict the score of a student in Engish test, Y= .76 + (.88)(10)
who got a score of 3 in the mathematics quiz. b = 𝑦−𝑚𝑥 Y= 9.56 ~ 10
Student Math Score English Score 𝑥𝑖 𝑦𝑖 𝑥𝑖 2 b = 5 – (0.884146) (4.8)
𝑖 𝑥𝑖 𝑦𝑖 b = 0.756098
1 4 5 20 16
2 5 4 20 25 Substituting in y = mx + b and
3 9 8 72 81
rounding off to two decimal places, the linear regression
4 2 3 6 4
5 8 9 72 64 equation is
6 1 2 2 1
7 2 1 2 4 y = 𝟎. 𝟕𝟔 + 𝟎. 𝟖𝟖 𝒙
8 7 6 42 49 Thus, the student who got 3 score in mathematics quiz will
9 6 7 42 36
have also a score of 3 in English test, as shown below.
10 4 5 20 16
10 10 10 10
m -0.23649 -0.236486
ACTIVITY 8 - LINEAR REGRESSION
PROBLEM A. The table below indicates the total number of enrolees Substituting the values to the formulas:
of Ezrah Academy and the corresponding profit from 2008 to 2016. 𝑛 𝑛 𝑛
𝑛 𝑖=1 𝑥𝑖 𝑦𝑖 − 𝑖=1 𝑥𝑖 𝑖=1 𝑦𝑖
a. Compute for m and b in the linear regression equation. 𝑚=
𝑛 𝑛 2
𝑛 2
b. Give the regression equation. 𝑖=1 𝑥𝑖 − 𝑖=1 𝑥𝑖
c. Predict the school’s profit in 2017 , the y , 𝒏 −( )( )
𝒎= (𝒏) − ( )𝟐
when the total enrolment is 12,000 (the 𝒙 )
TOTAL PROFIT 𝒎 = ____________
YEAR ENROLMENT (in million
2 b = 𝑦−𝑚𝑥
𝑥𝑖 pesos) 𝑥𝑖 𝑦𝑖 𝑥𝑖
𝑦𝑖 b = ( ) – ( )( )
b = _____________
2008 16,000 250
2009 15,000 200 Rounding off to two decimal places, the linear regression
2010 10,500 150 equation is
2011 11,000 180 y = b + mx
2012 11,800 190
2013 13,400 200 y = _____ + ( )𝒙
2014 13,900 220
Thus, school’s profit in 2017 when the total enrolment is
2015 14,000 240
12,000 is P___________, as shown below.
2016 13,200 180
9 y = ______ + ( )𝒙
9 9 9
𝑖=1 𝑥𝑖 = ___ 𝑖=1 𝑦𝑖 = ___ 𝑖=1 𝑥𝑖 𝑦𝑖 = ___ 𝑥𝑖 2 = _____ y = ______ + ( )( )
𝑛 = _____ 𝑖=1
𝑥 = ___ 𝑦 = ______ y = ______ in million
LINEAR REGRESSION Substituting the values to the formulas:
PROBLEM B
𝑛 𝑛 𝑛
The table below indicates the monthly cost of electricity against 𝑛 𝑖=1 𝑥𝑖 𝑦𝑖 − 𝑖=1 𝑥𝑖 𝑖=1 𝑦𝑖
air-conditioning temperature in a household. 𝑚= 2
𝑛 2 𝑛
𝑛 𝑖=1 𝑥𝑖 − 𝑖=1 𝑥𝑖
a. Fit the data into a linear equation and compute for m and b in −( )( )
the linear regression equation. 𝒎= ( ) − ( )𝟐
b. Give the regression equation.
c. Predict the cost of electricity if the air-conditioner is set at a 𝒎 = ____________
temperature of 16 ⁰C in a month (the y).
b = 𝑦−𝑚𝑥
b = ( ) – ( )( )
b = _____________
Air-con Cost of
Month Temperature Electricity Rounding off to two decimal places, the linear regression
2
in ⁰C in pesos 𝑥𝑖 𝑦𝑖 𝑥𝑖 equation is (y = b + mx):
𝑥𝑖 𝑦𝑖
y = _____ + ( )𝒙
1 25 3000
2 23 3300 Thus, the cost of electricity if the air-conditioner is set at
3 21 3500 a temperature of 16 ⁰C in a month is ________pesos, as
4 19 3800 shown below.
y = ______ + ( )𝒙
5 17 4000
y = ______ + ( )( )
5 5 5
𝑖=1 𝑥𝑖 = __ 𝑖=1 𝑦𝑖 = __ 𝑖=1 𝑥𝑖 𝑦𝑖 = ___ 5
𝑥𝑖 2 = ___ y = ______
𝑛 =5 𝑥 = ___ 𝑦 = ___ 𝑖=1
PROBLEM C.
A real estate agent wishes to examine the relationship between the selling price of a home and its size (measured in square feet).
Predict the price for a house with 2000 square feet.
245 1400
312 1600
279 1700
308 1875
199 1100
219 1550
405 2350
324 2450
319 1425
255 1700