Multiple Linear Regression
Multiple Linear Regression
Rstudio
#A
library(BSDA)
#Reading data
dat=read.table("clipboard",header=T)
#B
# F-test on Pt
f.pt= anova(reg2,reg1)
f.pt
#C
#D
# square at
at2=dat[,2]^2
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
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
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
> 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.
Tr = 402.73446 – 5.15582 pt
When keep the other variable constant and When increase the price variable at 1 unit, total revenue is
decrease by 5.15582