0% found this document useful (0 votes)
4 views10 pages

Multiple Regression Analysis in R

The document presents a practical report on regression analysis conducted by Sakshi Sanjeev Mishra, focusing on two datasets. The first dataset analyzes the selling price of houses using multiple regression, while the second dataset examines life expectancy in relation to television and doctor availability. The results indicate significant relationships in both analyses, with specific coefficients and p-values provided for interpretation.

Uploaded by

ayushkharat422
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)
4 views10 pages

Multiple Regression Analysis in R

The document presents a practical report on regression analysis conducted by Sakshi Sanjeev Mishra, focusing on two datasets. The first dataset analyzes the selling price of houses using multiple regression, while the second dataset examines life expectancy in relation to television and doctor availability. The results indicate significant relationships in both analyses, with specific coefficients and p-values provided for interpretation.

Uploaded by

ayushkharat422
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

R Console Page 1

> #Name:-Sakshi Sanjeev Mishra


> #Roll no:-2532022
> #Class:-[Link]
> #Course name:Lab course on Regression Analysis
>
> #######################Practical:-6########################
>
> ##Q.1##
> data1=[Link]([Link]());data1
y x1 x2 x3 x4 x5 x6 x7 x8 x9
1 25.9 4.9176 1.0 3.4720 0.998 1.0 7 4 42 0
2 29.5 5.0208 1.0 3.5310 1.500 2.0 7 4 62 0
3 27.9 4.5429 1.0 2.2750 1.175 1.0 6 3 40 0
4 25.9 4.5573 1.0 4.0500 1.232 1.0 6 3 54 0
5 29.9 5.0597 1.0 4.4550 1.121 1.0 6 3 42 0
6 29.9 3.8910 1.0 4.4550 0.988 1.0 6 3 56 0
7 30.9 5.8980 1.0 5.8500 1.240 1.0 7 3 51 0
8 28.9 5.6039 1.0 9.5200 1.501 0.0 6 3 32 0
9 35.9 5.8282 1.0 6.4350 1.225 2.0 6 3 32 0
10 31.5 5.3003 1.0 4.9883 1.552 1.0 6 3 30 0
11 31.0 6.2712 1.0 5.5200 0.975 1.0 5 2 30 0
12 30.9 5.9592 1.0 6.6660 1.121 2.0 6 3 32 0
13 30.0 5.0500 1.0 5.0000 1.020 1.0 5 2 46 0
14 36.9 8.2464 1.5 5.1500 1.664 2.0 8 4 50 0
15 41.9 6.6969 1.5 6.9020 1.488 1.5 7 3 22 0
16 40.5 7.7841 1.5 7.1020 1.376 1.0 6 3 17 0
17 43.9 9.0384 1.0 7.8000 1.500 1.5 7 3 23 0
18 37.5 5.9894 1.0 5.5200 1.256 2.0 6 3 40 0
19 37.9 7.5422 1.5 5.0000 1.690 1.0 6 3 22 0
20 44.5 8.7951 1.5 9.8900 1.820 2.0 8 4 50 0
21 37.9 6.0831 1.5 6.7265 1.652 1.0 6 3 44 0
22 38.9 8.3607 1.5 9.1500 1.777 2.0 8 4 48 0
23 36.9 8.1400 1.0 8.0000 1.504 2.0 7 3 30 0
24 45.8 9.1416 1.5 7.3262 1.831 1.5 8 4 31 0
>
> ##a)Multiple regression model
> Model1=lm(y~x1+x2+x3+x4+x5+x6+x7+x8+x9,data1);Model1

Call:
lm(formula = y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9,
data = data1)

Coefficients:
(Intercept) x1 x2 x3 x4 x5
12.8737 1.1363 7.8154 0.3126 2.9045 2.7020
x6 x7 x8 x9
1.2037 -2.6776 -0.0924 NA

> cat("The multiple regression model is,\nY(Selling price of a house)=12.8737+1.1363x1+7.8154x2+0


.3126x3+2.9045x4+2.7020x5+1.2037x6-2.6776x7-0.0924x8,\n")
The multiple regression model is,
Y(Selling price of a house)=12.8737+1.1363x1+7.8154x2+0.3126x3+2.9045x4+2.7020x5+1.2037x6-2.6776x
7-0.0924x8,
>
> ##b)To check significance of regression model
> #H0:B1=B2=B3=B4=B5=B6=B7=B8=0
> #H1:Bi!=0
> s=summary(Model1)
> p_value=0.0000
> if(p_value<0.05){
+ cat("We reject [Link] is a statistically significant relationship between response variable(Y
) and regressor(x)")
+ }else{
+ cat("We accept [Link] is no statistically significant relationship between response variable(
Y) and regressor(x)")
+ }
We reject [Link] is a statistically significant relationship between response variable(Y) and r
egressor(x)>
> ##c)
> s=summary(Model1);s
R Console Page 2

Call:
lm(formula = y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9,
data = data1)

Residuals:
Min 1Q Median 3Q Max
-3.537 -1.716 -0.169 1.453 3.825

Coefficients: (1 not defined because of singularities)


Estimate Std. Error t value Pr(>|t|)
(Intercept) 12.87373 4.94525 2.603 0.0200 *
x1 1.13628 1.00505 1.131 0.2760
x2 7.81538 3.77858 2.068 0.0563 .
x3 0.31257 0.43598 0.717 0.4844
x4 2.90449 4.11907 0.705 0.4915
x5 2.70203 1.39545 1.936 0.0719 .
x6 1.20366 2.06771 0.582 0.5691
x7 -2.67758 2.66103 -1.006 0.3303
x8 -0.09240 0.07144 -1.293 0.2155
x9 NA NA NA NA
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 2.792 on 15 degrees of freedom


Multiple R-squared: 0.859, Adjusted R-squared: 0.7838
F-statistic: 11.42 on 8 and 15 DF, p-value: 3.949e-05

> p_value=s$coefficients[,4];p_value
(Intercept) x1 x2 x3 x4 x5 x6
0.01996932 0.27599225 0.05630377 0.48442951 0.49153331 0.07190251 0.56912967
x7 x8
0.33026572 0.21547965
> for(i in 2:length(p_value)){
+ var_name=rownames(s$coefficients)[i]
+ p_val=p_value[i]
+ if(p_val<0.05){
+ cat(var_name,"is statistically significant(p_value=",round(p_val,4),")\n")
+ }else{
+ cat(var_name,"is NOT statistically significant(p_value=",round(p_val,4),")\n")
+ }
+ }
x1 is NOT statistically significant(p_value= 0.276 )
x2 is NOT statistically significant(p_value= 0.0563 )
x3 is NOT statistically significant(p_value= 0.4844 )
x4 is NOT statistically significant(p_value= 0.4915 )
x5 is NOT statistically significant(p_value= 0.0719 )
x6 is NOT statistically significant(p_value= 0.5691 )
x7 is NOT statistically significant(p_value= 0.3303 )
x8 is NOT statistically significant(p_value= 0.2155 )
>
>
> ##Q.2##
> data2=[Link]([Link]());data2
Country LifeExp [Link] [Link] LifeExpMale LifeExpFemale
1 Argentina 70.5 4.0 370 74 67
2 Bangladesh 53.5 315.0 6166 53 54
3 Brazil 65.0 4.0 684 68 62
4 Canada 76.5 1.7 449 80 73
5 China 70.0 8.0 643 72 68
6 Colombia 71.0 5.6 1551 74 68
7 Egypt 60.5 15.0 616 61 60
8 Ethiopia 51.5 503.0 36660 53 50
9 France 78.0 2.6 403 82 74
10 Germany 76.0 2.6 346 79 73
11 India 57.5 44.0 2471 58 57
12 Indonesia 61.0 24.0 7427 63 59
13 Iran 64.5 23.0 2992 65 64
14 Italy 78.5 3.8 233 82 75
15 Japan 79.0 1.8 609 82 76
R Console Page 3

16 Kenya 61.0 96.0 7615 63 59


17 Korea, North 70.0 90.0 370 73 67
18 Korea, South 70.0 4.9 1066 73 67
19 Mexico 72.0 6.6 600 76 68
20 Morocco 64.5 21.0 4873 66 63
21 Burma 54.5 592.0 3485 56 53
22 Pakistan 56.5 73.0 2364 57 56
23 Peru 64.5 14.0 1016 67 62
24 Philippines 64.5 8.8 1062 67 62
25 Poland 73.0 3.9 480 77 69
26 Romania 72.0 6.0 559 75 69
27 Russia 69.0 3.2 259 74 64
28 South Africa 64.0 11.0 1340 67 61
29 Spain 78.5 2.6 275 82 75
30 Sudan 53.0 23.0 12550 54 52
31 Taiwan 75.0 3.2 965 78 72
32 Thailand 68.5 11.0 4883 73 66
33 Turkey 70.0 5.0 1189 72 68
34 Ukraine 70.5 3.0 226 75 66
35 United Kingdom 76.0 3.0 611 79 73
36 United States 75.5 1.3 404 79 72
37 Venezuela 74.5 5.6 576 78 71
38 Vietnam 65.0 29.0 3096 67 63
>
> ##a)Multiple regression model
> ModelA=lm(LifeExp~[Link]+[Link],data2);ModelA

Call:
lm(formula = LifeExp ~ [Link] + [Link], data = data2)

Coefficients:
(Intercept) [Link] [Link]
70.251957 -0.023495 -0.000432

> ModelB=lm(LifeExpMale~[Link]+[Link],data2);ModelB

Call:
lm(formula = LifeExpMale ~ [Link] + [Link], data = data2)

Coefficients:
(Intercept) [Link] [Link]
73.1096732 -0.0266842 -0.0004616

> ModelC=lm(LifeExpFemale~[Link]+[Link],data2);ModelC

Call:
lm(formula = LifeExpFemale ~ [Link] + [Link], data = data2)

Coefficients:
(Intercept) [Link] [Link]
67.4436190 -0.0206490 -0.0003953

>
> ##b)To check significance of regression model
> #H0:B1=B2=B3=B4=B5=B6=B7=B8=0
> #H1:Bi!=0
>
>
> s=summary(ModelA);s

Call:
lm(formula = LifeExp ~ [Link] + [Link], data = data2)

Residuals:
Min 1Q Median 3Q Max
-11.2894 -4.6266 0.3977 5.0872 9.0535

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 70.2519573 1.0877047 64.587 <2e-16 ***
R Console Page 4

[Link] -0.0234954 0.0096469 -2.436 0.0201 *


[Link] -0.0004320 0.0002023 -2.136 0.0398 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 6.003 on 35 degrees of freedom


Multiple R-squared: 0.44, Adjusted R-squared: 0.408
F-statistic: 13.75 on 2 and 35 DF, p-value: 3.916e-05

> p_value=0.0000
> if(p_value<0.05){
+ cat("We reject [Link] is a statistically significant relationship between response variable(Y
) and regressor(x)")
+ }else{
+ cat("We accept [Link] is no statistically significant relationship between response variable(
Y) and regressor(x)")
+ }
We reject [Link] is a statistically significant relationship between response variable(Y) and r
egressor(x)>
>
> s=summary(ModelB);s

Call:
lm(formula = LifeExpMale ~ [Link] + [Link], data = data2)

Residuals:
Min 1Q Median 3Q Max
-13.070 -5.070 1.132 5.392 10.235

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 73.1096732 1.2451755 58.714 <2e-16 ***
[Link] -0.0266842 0.0110435 -2.416 0.0210 *
[Link] -0.0004616 0.0002316 -1.993 0.0541 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 6.872 on 35 degrees of freedom


Multiple R-squared: 0.4226, Adjusted R-squared: 0.3897
F-statistic: 12.81 on 2 and 35 DF, p-value: 6.687e-05

> p_value=0.0000
> if(p_value<0.05){
+ cat("We reject [Link] is a statistically significant relationship between response variable(Y
) and regressor(x)")
+ }else{
+ cat("We accept [Link] is no statistically significant relationship between response variable(
Y) and regressor(x)")
+ }
We reject [Link] is a statistically significant relationship between response variable(Y) and r
egressor(x)>
>
> s=summary(ModelC);s

Call:
lm(formula = LifeExpFemale ~ [Link] + [Link], data = data2)

Residuals:
Min 1Q Median 3Q Max
-10.0075 -4.2390 0.3964 4.5321 8.8343

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 67.4436190 0.9526619 70.795 <2e-16 ***
[Link] -0.0206490 0.0084492 -2.444 0.0197 *
[Link] -0.0003953 0.0001772 -2.231 0.0322 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 5.258 on 35 degrees of freedom


R Console Page 5

Multiple R-squared: 0.451, Adjusted R-squared: 0.4196


F-statistic: 14.38 on 2 and 35 DF, p-value: 2.77e-05

> p_value=0.0000
> if(p_value<0.05){
+ cat("We reject [Link] is a statistically significant relationship between response variable(Y
) and regressor(x)")
+ }else{
+ cat("We accept [Link] is no statistically significant relationship between response variable(
Y) and regressor(x)")
+ }
We reject [Link] is a statistically significant relationship between response variable(Y) and r
egressor(x)>
> ##c)
> s=summary(ModelA);s

Call:
lm(formula = LifeExp ~ [Link] + [Link], data = data2)

Residuals:
Min 1Q Median 3Q Max
-11.2894 -4.6266 0.3977 5.0872 9.0535

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 70.2519573 1.0877047 64.587 <2e-16 ***
[Link] -0.0234954 0.0096469 -2.436 0.0201 *
[Link] -0.0004320 0.0002023 -2.136 0.0398 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 6.003 on 35 degrees of freedom


Multiple R-squared: 0.44, Adjusted R-squared: 0.408
F-statistic: 13.75 on 2 and 35 DF, p-value: 3.916e-05

> p_value=s$coefficients[,4];p_value
(Intercept) [Link] [Link]
5.383314e-38 2.010291e-02 3.976301e-02
> for(i in 2:length(p_value)){
+ var_name=rownames(s$coefficients)[i]
+ p_val=p_value[i]
+ if(p_val<0.05){
+ cat(var_name,"is statistically significant(p_value=",round(p_val,4),")\n")
+ }else{
+ cat(var_name,"is NOT statistically significant(p_value=",round(p_val,4),")\n")
+ }
+ }
[Link] is statistically significant(p_value= 0.0201 )
[Link] is statistically significant(p_value= 0.0398 )
>
>
> s=summary(ModelB);s

Call:
lm(formula = LifeExpMale ~ [Link] + [Link], data = data2)

Residuals:
Min 1Q Median 3Q Max
-13.070 -5.070 1.132 5.392 10.235

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 73.1096732 1.2451755 58.714 <2e-16 ***
[Link] -0.0266842 0.0110435 -2.416 0.0210 *
[Link] -0.0004616 0.0002316 -1.993 0.0541 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 6.872 on 35 degrees of freedom


Multiple R-squared: 0.4226, Adjusted R-squared: 0.3897
R Console Page 6

F-statistic: 12.81 on 2 and 35 DF, p-value: 6.687e-05

> p_value=s$coefficients[,4];p_value
(Intercept) [Link] [Link]
1.469762e-36 2.103313e-02 5.406075e-02
> for(i in 2:length(p_value)){
+ var_name=rownames(s$coefficients)[i]
+ p_val=p_value[i]
+ if(p_val<0.05){
+ cat(var_name,"is statistically significant(p_value=",round(p_val,4),")\n")
+ }else{
+ cat(var_name,"is NOT statistically significant(p_value=",round(p_val,4),")\n")
+ }
+ }
[Link] is statistically significant(p_value= 0.021 )
[Link] is NOT statistically significant(p_value= 0.0541 )
>
>
> s=summary(ModelC);s

Call:
lm(formula = LifeExpFemale ~ [Link] + [Link], data = data2)

Residuals:
Min 1Q Median 3Q Max
-10.0075 -4.2390 0.3964 4.5321 8.8343

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 67.4436190 0.9526619 70.795 <2e-16 ***
[Link] -0.0206490 0.0084492 -2.444 0.0197 *
[Link] -0.0003953 0.0001772 -2.231 0.0322 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 5.258 on 35 degrees of freedom


Multiple R-squared: 0.451, Adjusted R-squared: 0.4196
F-statistic: 14.38 on 2 and 35 DF, p-value: 2.77e-05

> p_value=s$coefficients[,4];p_value
(Intercept) [Link] [Link]
2.220559e-39 1.971049e-02 3.216421e-02
> for(i in 2:length(p_value)){
+ var_name=rownames(s$coefficients)[i]
+ p_val=p_value[i]
+ if(p_val<0.05){
+ cat(var_name,"is statistically significant(p_value=",round(p_val,4),")\n")
+ }else{
+ cat(var_name,"is NOT statistically significant(p_value=",round(p_val,4),")\n")
+ }
+ }
[Link] is statistically significant(p_value= 0.0197 )
[Link] is statistically significant(p_value= 0.0322 )
>
> ##d)
> CIA=confint(ModelA,level=0.95);CIA
2.5 % 97.5 %
(Intercept) 68.0437994245 7.246012e+01
[Link] -0.0430795581 -3.911172e-03
[Link] -0.0008427015 -2.139253e-05
> B1_CIA=CIA[2, ];B1_CIA
2.5 % 97.5 %
-0.043079558 -0.003911172
> B0_CIA=CIA[1, ];B0_CIA
2.5 % 97.5 %
68.04380 72.46012
> CIB=confint(ModelB,level=0.95);CIB
2.5 % 97.5 %
(Intercept) 70.5818325727 7.563751e+01
[Link] -0.0491036391 -4.264709e-03
R Console Page 7

[Link] -0.0009317063 8.506519e-06


> B1_CIB=CIB[2, ];B1_CIB
2.5 % 97.5 %
-0.049103639 -0.004264709
> B0_CIB=CIB[1, ];B0_CIB
2.5 % 97.5 %
70.58183 75.63751
> CIC=confint(ModelC,level=0.95);CIC
2.5 % 97.5 %
(Intercept) 65.5096124541 6.937763e+01
[Link] -0.0378017788 -3.496299e-03
[Link] -0.0007549873 -3.564701e-05
> B1_CIC=CIC[2, ];B1_CIC
2.5 % 97.5 %
-0.037801779 -0.003496299
> B0_CIC=CIC[1, ];B0_CIC
2.5 % 97.5 %
65.50961 69.37763
>
>
> ##Q.3##
> data3=[Link]([Link]());data3
Satisfaction Age Severity [Link] Anxiety
1 68 55 50 0 2.1
2 77 46 24 1 2.8
3 96 30 46 1 3.3
4 80 35 48 1 4.5
5 43 59 58 0 2.0
6 44 61 60 0 5.1
7 26 74 65 1 5.5
8 88 38 42 1 3.2
9 75 27 42 0 3.1
10 57 51 50 1 2.4
11 56 53 38 1 2.2
12 88 41 30 0 2.1
13 88 37 31 0 1.9
14 102 24 34 0 3.1
15 88 42 30 0 3.0
16 70 50 48 1 4.2
17 82 58 61 1 4.6
18 43 60 71 1 5.3
19 46 62 62 0 7.2
20 56 68 38 0 7.8
21 59 70 41 1 7.0
22 26 79 66 1 6.2
23 52 63 31 1 4.1
24 83 39 42 0 3.5
25 75 49 40 1 2.1
>
> ##a)Multiple regression model
> Model3=lm(Satisfaction~Age+Severity+Anxiety,data3);Model3

Call:
lm(formula = Satisfaction ~ Age + Severity + Anxiety, data = data3)

Coefficients:
(Intercept) Age Severity Anxiety
140.3193 -1.1233 -0.4629 1.2126

> cat("The multiple regression model is,\nY=140.3193-1.1233x1-0.4629x2+1.2126x3")


The multiple regression model is,
Y=140.3193-1.1233x1-0.4629x2+1.2126x3>
> ##b)To check significance of regression model
> #H0:B1=B2=B3=B4=B5=B6=B7=B8=0
> #H1:Bi!=0
> s=summary(Model3);s

Call:
lm(formula = Satisfaction ~ Age + Severity + Anxiety, data = data3)
R Console Page 8

Residuals:
Min 1Q Median 3Q Max
-19.3058 -5.7938 0.1994 5.1102 29.4939

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 140.3193 8.1725 17.170 7.74e-14 ***
Age -1.1233 0.1837 -6.114 4.57e-06 ***
Severity -0.4629 0.1830 -2.530 0.0195 *
Anxiety 1.2126 1.4633 0.829 0.4166
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 9.752 on 21 degrees of freedom


Multiple R-squared: 0.8156, Adjusted R-squared: 0.7893
F-statistic: 30.97 on 3 and 21 DF, p-value: 6.729e-08

> p_value=0.0000
> if(p_value<0.05){
+ cat("We reject [Link] is a statistically significant relationship between response variable(Y
) and regressor(x)")
+ }else{
+ cat("We accept [Link] is no statistically significant relationship between response variable(
Y) and regressor(x)")
+ }
We reject [Link] is a statistically significant relationship between response variable(Y) and r
egressor(x)>
> ##c)
> s=summary(Model3);s

Call:
lm(formula = Satisfaction ~ Age + Severity + Anxiety, data = data3)

Residuals:
Min 1Q Median 3Q Max
-19.3058 -5.7938 0.1994 5.1102 29.4939

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 140.3193 8.1725 17.170 7.74e-14 ***
Age -1.1233 0.1837 -6.114 4.57e-06 ***
Severity -0.4629 0.1830 -2.530 0.0195 *
Anxiety 1.2126 1.4633 0.829 0.4166
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 9.752 on 21 degrees of freedom


Multiple R-squared: 0.8156, Adjusted R-squared: 0.7893
F-statistic: 30.97 on 3 and 21 DF, p-value: 6.729e-08

> p_value=s$coefficients[,4];p_value
(Intercept) Age Severity Anxiety
7.739896e-14 4.572725e-06 1.946775e-02 4.165986e-01
> for(i in 2:length(p_value)){
+ var_name=rownames(s$coefficients)[i]
+ p_val=p_value[i]
+ if(p_val<0.05){
+ cat(var_name,"is statistically significant(p_value=",round(p_val,4),")\n")
+ }else{
+ cat(var_name,"is NOT statistically significant(p_value=",round(p_val,4),")\n")
+ }
+ }
Age is statistically significant(p_value= 0 )
Severity is statistically significant(p_value= 0.0195 )
Anxiety is NOT statistically significant(p_value= 0.4166 )
>
>
> ##Q.4##
> data4=[Link]([Link]());data4
y x1 x2 x3 x4 x5 x6 x7 x8
R Console Page 9

1 343 0 52.8 811.7 2.11 220 261 87 1.8


2 356 1 52.8 811.7 2.11 220 261 87 1.8
3 344 0 50.0 821.3 2.11 223 260 87 16.6
4 356 1 50.0 821.3 2.11 223 260 87 16.6
5 352 0 47.2 832.0 2.09 221 261 92 23.0
6 361 1 47.2 832.0 2.09 221 261 92 25.1
7 372 0 47.0 831.3 2.26 190 323 75 25.1
8 355 1 47.0 831.3 2.26 190 323 75 26.1
9 375 0 48.3 836.8 2.47 180 364 71 26.1
10 359 1 48.3 836.8 2.47 180 364 71 20.0
11 364 0 44.7 808.3 1.41 180 300 64 20.0
12 357 1 44.7 808.3 1.41 180 300 64 20.5
13 368 0 55.7 808.7 1.44 176 299 64 20.5
14 360 1 55.7 808.7 1.44 176 299 64 20.5
15 372 0 52.8 813.2 1.96 175 301 75 17.3
16 352 1 52.8 813.2 1.96 175 301 75 17.3
>
> ##a)Multiple regression model
> Model4=lm(y~x2+x3+x4+x5+x6+x7+x8,data4);Model4

Call:
lm(formula = y ~ x2 + x3 + x4 + x5 + x6 + x7 + x8, data = data4)

Coefficients:
(Intercept) x2 x3 x4 x5 x6
1196.6206 0.5856 -1.6803 -24.7374 0.4330 0.9279
x7 x8
2.2549 1.5043

> cat("The multiple regression model is,\nY=1196.6206+0.5856x2-1.6803x3-24.7374x4+0.433x5+0.9279x


6+2.2549x7+1.5043x8")
The multiple regression model is,
Y=1196.6206+0.5856x2-1.6803x3-24.7374x4+0.433x5+0.9279x6+2.2549x7+1.5043x8>
> ##b)To check significance of regression model
> #H0:B1=B2=B3=B4=B5=B6=B7=B8=0
> #H1:Bi!=0
> s=summary(Model4);s

Call:
lm(formula = y ~ x2 + x3 + x4 + x5 + x6 + x7 + x8, data = data4)

Residuals:
Min 1Q Median 3Q Max
-10.8626 -4.6637 -0.1431 3.7665 11.7250

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1196.6206 1350.5029 0.886 0.401
x2 0.5856 0.9577 0.611 0.558
x3 -1.6803 2.4481 -0.686 0.512
x4 -24.7374 44.6862 -0.554 0.595
x5 0.4330 0.8846 0.490 0.638
x6 0.9279 1.1862 0.782 0.457
x7 2.2549 3.0976 0.728 0.487
x8 1.5043 1.7248 0.872 0.409

Residual standard error: 9.135 on 8 degrees of freedom


Multiple R-squared: 0.4949, Adjusted R-squared: 0.05294
F-statistic: 1.12 on 7 and 8 DF, p-value: 0.434

> p_value=0.434
> if(p_value<0.05){
+ cat("We reject [Link] is a statistically significant relationship between response variable(Y
) and regressor(x)")
+ }else{
+ cat("We accept [Link] is no statistically significant relationship between response variable(
Y) and regressor(x)")
+ }
We accept [Link] is no statistically significant relationship between response variable(Y) and
regressor(x)>
R Console Page 10

> ##c)
> s=summary(Model4);s

Call:
lm(formula = y ~ x2 + x3 + x4 + x5 + x6 + x7 + x8, data = data4)

Residuals:
Min 1Q Median 3Q Max
-10.8626 -4.6637 -0.1431 3.7665 11.7250

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1196.6206 1350.5029 0.886 0.401
x2 0.5856 0.9577 0.611 0.558
x3 -1.6803 2.4481 -0.686 0.512
x4 -24.7374 44.6862 -0.554 0.595
x5 0.4330 0.8846 0.490 0.638
x6 0.9279 1.1862 0.782 0.457
x7 2.2549 3.0976 0.728 0.487
x8 1.5043 1.7248 0.872 0.409

Residual standard error: 9.135 on 8 degrees of freedom


Multiple R-squared: 0.4949, Adjusted R-squared: 0.05294
F-statistic: 1.12 on 7 and 8 DF, p-value: 0.434

> p_value=s$coefficients[,4];p_value
(Intercept) x2 x3 x4 x5 x6 x7
0.4014364 0.5578953 0.5118747 0.5949945 0.6376037 0.4565638 0.4874063
x8
0.4085490
> for(i in 2:length(p_value)){
+ var_name=rownames(s$coefficients)[i]
+ p_val=p_value[i]
+ if(p_val<0.05){
+ cat(var_name,"is statistically significant(p_value=",round(p_val,4),")\n")
+ }else{
+ cat(var_name,"is NOT statistically significant(p_value=",round(p_val,4),")\n")
+ }
+ }
x2 is NOT statistically significant(p_value= 0.5579 )
x3 is NOT statistically significant(p_value= 0.5119 )
x4 is NOT statistically significant(p_value= 0.595 )
x5 is NOT statistically significant(p_value= 0.6376 )
x6 is NOT statistically significant(p_value= 0.4566 )
x7 is NOT statistically significant(p_value= 0.4874 )
x8 is NOT statistically significant(p_value= 0.4085 )
>
>
>

You might also like