0% found this document useful (0 votes)
43 views

Multiple Linear Regression

This document discusses multiple linear regression analysis on data relating total revenue (tr), price (Pt), and advertising (at). Several regression models are fit and compared. The full model including Pt and at is significant, but adding the squared term at2 does not improve the model. Ultimately, only Pt is found to be a significant predictor of tr, while at and at2 are not. The final regression model shows that tr is negatively associated with Pt, when holding other variables constant.

Uploaded by

kasuweda
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Multiple Linear Regression

This document discusses multiple linear regression analysis on data relating total revenue (tr), price (Pt), and advertising (at). Several regression models are fit and compared. The full model including Pt and at is significant, but adding the squared term at2 does not improve the model. Ultimately, only Pt is found to be a significant predictor of tr, while at and at2 are not. The final regression model shows that tr is negatively associated with Pt, when holding other variables constant.

Uploaded by

kasuweda
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Multiple linear regression

Rstudio

#A

library(BSDA)

#Reading data
dat=read.table("clipboard",header=T)

#data set eke thiyana 2 idam 5 wenakam pennawa


dat[2:5,]

# fit full model i.e. unrestricted model


reg1=lm(tr~Pt+at,data=dat)
summary(reg1)

# lets do the residual analysis


par(mfrow=c(2,2))
plot(reg1)

#B

reg1=lm(tr~Pt+at,data=dat)# unrestricted model


reg2=lm(tr~at,data=dat)# restricted model

# F-test on Pt
f.pt= anova(reg2,reg1)
f.pt

#C

# H0: beta2=1; Ha:beta2 not equal to 1


library(car)
linearHypothesis(reg1, "at=1")

#D

# square at
at2=dat[,2]^2

# add this into the data set


dat2=cbind(dat,at2)

#View the data


dat2[1:3,]

reg3=lm(tr~Pt+at+at2,data=dat2)
summary(reg3)

plot(reg3)

R studio results
> library(BSDA)
> #Reading data
> dat=read.table("clipboard",header=T)
> #data set eke thiyana 2 idam 5 wenakam pennawa
> dat[2:5,]
Pt at tr
2 88.65 39.99 53.14
3 77.81 45.45 157.80
4 80.87 38.24 98.64
5 78.44 30.83 138.03
> # fit full model i.e. unrestricted model
> reg1=lm(tr~Pt+at,data=dat)
> summary(reg1)

Call:
lm(formula = tr ~ Pt + at, data = dat)

Residuals:
Min 1Q Median 3Q Max
-45.214 -12.252 -3.812 13.113 50.514

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 386.0736 34.4833 11.20 7.38e-15 ***
Pt -5.1478 0.3783 -13.61 < 2e-16 ***
at 3.6646 0.4212 8.70 2.34e-11 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 22.28 on 47 degrees of freedom


Multiple R-squared: 0.8634, Adjusted R-squared: 0.8576
F-statistic: 148.6 on 2 and 47 DF, p-value: < 2.2e-16

> # lets do the residual analysis


> par(mfrow=c(2,2))
> plot(reg1)
> reg1=lm(tr~Pt+at,data=dat)# unrestricted model
> reg2=lm(tr~at,data=dat)# restricted model
> # F-test on Pt
> f.pt= anova(reg2,reg1)
> f.pt
Analysis of Variance Table

Model 1: tr ~ at
Model 2: tr ~ Pt + at
Res.Df RSS Df Sum of Sq F Pr(>F)
1 48 115266
2 47 23337 1 91929 185.14 < 2.2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> # H0: beta2=1; Ha:beta2 not equal to 1
> library(car)
> linearHypothesis(reg1, "at=1")
Linear hypothesis test

Hypothesis:
at = 1

Model 1: restricted model


Model 2: tr ~ Pt + at

Res.Df RSS Df Sum of Sq F Pr(>F)


1 48 43209
2 47 23337 1 19872 40.021 8.619e-08 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> # square at
> at2=dat[,2]^2
> # add this into the data set
> dat2=cbind(dat,at2)
> #View the data
> dat2[1:3,]
Pt at tr at2
1 78.63 47.59 192.37 2264.808
2 88.65 39.99 53.14 1599.200
3 77.81 45.45 157.80 2065.703
> reg3=lm(tr~Pt+at+at2,data=dat2)
> summary(reg3)

Call:
lm(formula = tr ~ Pt + at + at2, data = dat2)

Residuals:
Min 1Q Median 3Q Max
-44.512 -11.488 -3.315 13.798 50.474

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 402.73446 64.06805 6.286 1.08e-07 ***
Pt -5.15582 0.38289 -13.465 < 2e-16 ***
at 2.71283 3.10166 0.875 0.386
at2 0.01347 0.04348 0.310 0.758
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 22.5 on 46 degrees of freedom


Multiple R-squared: 0.8637, Adjusted R-squared: 0.8548
F-statistic: 97.19 on 3 and 46 DF, p-value: < 2.2e-16

> plot(reg3)

>
Interpretation

According to the residual analysis, there is no reason for reject the model, so this is not broken the
underline the assumption.

> reg3=lm(tr~Pt+at+at2,data=dat2)
> summary(reg3)
Call:
lm(formula = tr ~ Pt + at + at2, data = dat2)

Residuals:
Min 1Q Median 3Q Max
-44.512 -11.488 -3.315 13.798 50.474

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 402.73446 64.06805 6.286 1.08e-07 ***
Pt -5.15582 0.38289 -13.465 < 2e-16 ***
at 2.71283 3.10166 0.875 0.386
at2 0.01347 0.04348 0.310 0.758
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 22.5 on 46 degrees of freedom
Multiple R-squared: 0.8637, Adjusted R-squared: 0.8548
F-statistic: 97.19 on 3 and 46 DF, p-value: < 2.2e-16

According to this results value of intercept and p value of pt are less than 0.05 therefore these two
variable significant. P value of at and at2 are not less than 0.05 so they are not significant.

Therefore, the regression model is as follow,

Tr = 402.73446 – 5.15582 pt

When keep the other variable are 0, total revenue is 402.73446

When keep the other variable constant and When increase the price variable at 1 unit, total revenue is
decrease by 5.15582

Adjusted R-squared is 0.8548 (85.54%). So in the model,85.54% of total


revenue variable is described by the price variable and other variables.

You might also like