Professional Documents
Culture Documents
Lab Experiment-Ii: Answer
Lab Experiment-Ii: Answer
Answer :
> x=temp
> y=sale
>x
[1] 15.2 16.4 13.9 15.2 19.5 22.1 19.4 24.1 23.4 18.1 22.9 18.2 19.2
>y
[1] 215 305 185 302 406 522 422 614 554 421 345 408 215
> mx=mean(x)
> mx
[1] 19.04615
> my=mean(y)
> my
[1] 378
> dx=x-mx
> dy=y-my
> cov=sum(dx*dy)/13
> cov
[1] 331.8692
Answer :
> cr1=cor(temp,sale)
> cr1
[1] 0.8037914
> cr2=cor(temp,melt)
> cr2
[1] 0.9461618
> cr3=cor(temp,exp)
> cr3
[1] 0.5060445
> cr4=cor(sale,melt)
> cr4
[1] 0.8925183
> cr5=cor(sale,exp)
> cr5
[1] 0.4331184
> cr6=cor(melt,exp)
> cr6
[1] 0.4685135
d) Find which pair is strongly correlated among all and which pair is weakly
correlated among all.
Answer :
The strongly correlated pair is temperature and ice melting level
The weaky correlated pair is ice cream sales and expenditure
e) Find the following regression line.
i) Temperature on ice cream sales.
Answer :
> #temperature on sales
> x=sale
>x
[1] 215 305 185 302 406 522 422 614 554 421 345 408 215
> y=temp
>y
[1] 15.2 16.4 13.9 15.2 19.5 22.1 19.4 24.1 23.4 18.1 22.9 18.2 19.2
> tab1=data.frame(x,y)
> tab1
x y
1 215 15.2
2 305 16.4
3 185 13.9
4 302 15.2
5 406 19.5
6 522 22.1
7 422 19.4
8 614 24.1
9 554 23.4
10 421 18.1
11 345 22.9
12 408 18.2
13 215 19.2
> lm(y~x)
Call:
lm(formula = y ~ x)
Coefficients:
(Intercept) x
11.47714 0.02002
# Regression line: y = 11.47714 + 0.02002 x
ii) Temperature on expenditure.
Answer :
> #temp on exp
> x=exp
> y=temp
> tab2=data.frame(x,y)
> tab2
x y
1 201 15.2
2 212 16.4
3 241 13.9
4 155 15.2
5 132 19.5
6 583 22.1
7 226 19.4
8 474 24.1
9 205 23.4
10 217 18.1
11 237 22.9
12 130 18.2
13 320 19.2
> lm(y~x)
Call:
lm(formula = y ~ x)
Coefficients:
(Intercept) x
15.77675 0.01275
# Regression line: y = 15.77675 + 0.01275 x
iii) Expenditure on temperature.
Answer :
> #exp on temp
> x=temp
> y=exp
> tab3=data.frame(x,y)
> tab3
x y
1 15.2 201
2 16.4 212
3 13.9 241
4 15.2 155
5 19.5 132
6 22.1 583
7 19.4 226
8 24.1 474
9 23.4 205
10 18.1 217
11 22.9 237
12 18.2 130
13 19.2 320
> lm(y~x)
Call:
lm(formula = y ~ x)
Coefficients:
(Intercept) x
-126.09 20.08
# Regression line: y = -126.09 + 20.08 x
e) Plot the Scatter diagram along regression line of expenditure on ice cream sales.
Answer:
> x=sale
> y=exp
> tab4=data.frame(x,y)
> tab4
x y
1 215 201
2 305 212
3 185 241
4 302 155
5 406 132
6 522 583
7 422 226
8 614 474
9 554 205
10 421 217
11 345 237
12 408 130
13 215 320
> lm(y~x)
Call:
lm(formula = y ~ x)
Coefficients:
(Intercept) x
94.5340 0.4282
> plot(x,y)
> abline(lm(y~x))
Plot:
g) Predict the following.
i) Ice cream sales if the melting level is 11.2.
Answer :
> x=melt
> y=sale
> tab5=data.frame(x,y)
> tab5
x y
1 -2.2 215
2 1.0 305
3 -4.5 185
4 -1.2 302
5 2.1 406
6 5.7 522
7 3.2 422
8 8.7 614
9 7.1 554
10 1.7 421
11 6.2 345
12 0.8 408
13 -1.2 215
> lm(y~x)
Call:
lm(formula = y ~ x)
Coefficients:
(Intercept) x
314.05 30.34
> y=314.05+(11.2*30.34)
>y
[1] 653.858
> #If the melting level is 11.2 , the sales is $653.858
Call:
lm(formula = y ~ x)
Coefficients:
(Intercept) x
-126.09 20.08
> y=-126.09+(27.5*20.08)
>y
[1] 426.11
> #When temperature is 27.5 degrees , the expenditure is $426.11
> x=temp
> y=melt
> tab7=data.frame(x,y)
> tab7
x y
1 15.2 -2.2
2 16.4 1.0
3 13.9 -4.5
4 15.2 -1.2
5 19.5 2.1
6 22.1 5.7
7 19.4 3.2
8 24.1 8.7
9 23.4 7.1
10 18.1 1.7
11 22.9 6.2
12 18.2 0.8
13 19.2 -1.2
> lm(y~x)
Call:
lm(formula = y ~ x)
Coefficients:
(Intercept) x
-19.171 1.117
> y=-19.171+(27.5*1.117)
>y
[1] 11.5465
>
> #When temperature is 27.5 degrees, the melting level is 11.5465