Session 11-12-Linear and Multiple Regression
Session 11-12-Linear and Multiple Regression
Regression is a predictive model used to predict the value of one variable which is referred as
dependent variable or outcome variable from the value(s) of one or more other variables referred as
input variable(s) or independent variable(s).
Linear regression has single independent variable. The general form of the regression model is:
which is estimated by
where the b1 represent the partial regression coefficients, (i.e., b1 represents the expected change in Y
when X1 is changed by one unit).
Multiple regression has more than one independent variable. The general form of the multiple
regression model is:
which is estimated by
where the bi’s represent the partial regression coefficients (i.e., b1 represents the expected change in Y
when X1 is changed by one unit and the X2 through Xk are held constant).
Student_Sales_Data.xlsx
Student
Student_Sales_Data.xlsx
Sales
DayType Price($) Advertising ($100s) Sales($)
Weekdays 5.5 3.3 350
Weekdays 7.5 3.3 460
Weekdays 8 3 350
Weekdays 8 4.5 430
Weekdays 6.8 3 350
Weekdays 7.5 4 380
Weekdays 4.5 3 430
Weekdays 6.4 3.7 470
Weekend 7 3.5 450
Weekend 5 4 490
Weekend 7.2 3.5 340
Weekend 7.9 3.2 300
Weekend 5.9 4 440
Weekend 5 3.5 450
Weekend 7 2.7 300
Regression in R
library(readxl)
df<-read_excel('Student_Sales_Data.xlsx', sheet = 'Sales')
#Print Data Frame
#df
#Call lm() function for regression
model<-lm(Sales~Price+Advertising, data=df)
#print results OUTPUT:
summary(model) Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 306.53 114.25 2.683 0.0199 *
Regression Model df$Price -24.98 10.83 -2.306 0.0398 *
df$Advertising 74.13 25.97 2.855 0.0145 *
Sales= 306.53 -24.98 *Price+74.13 *Advertising
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Using The Equation to Make Predictions
Regression Model
Sales= 306.53 -24.98 *Price+74.13 *Advertising
where
Sales is in number of pies per week
Price is in $
Advertising is in $100’s.
Let:
Y = pie sales Ŷ b0 b1 X1 b 2 X 2
X1 = price
X2 = holiday (X2 = 1 if a holiday occurred during the week)
X4 = Quarter (Q1-Dummy, 3 0 0 1
4 0 0 0
Q2-Dummy,
Total number of dummy variables
Q3-Dummy) = 4 (Total quarters)-1=3
Dummy-Variable Example-Predicting Auto Sales
Regression Equation