Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Name : Badigi Shivakumar Reg.

No : 20MIS0173

Lab.Slot : L9+L10 Date : 02-09-2021

LAB ASSIGNMENT - 2
Problem 1: You can choose your data: Collect the data for 50 pair of
observations say . Here, the pair of observations can be represent heights and
weights of a 50 persons, or heights of father and sons, or price and sales of a
product per 50 days, marks of 50 students in two different subjects and so on .
Write the R code to obtain the coefficient of linear relationship between the
above said pair of observations and comment on the result.

> # NAME = BADIGI SHIVA KUMAR


> # REG.NO = 20MIS0173
> # QUESTION 1
>
> x=seq(50,148,2)
> x
[1] 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80
82 84 86
[20] 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118
120 122 124
[39] 126 128 130 132 134 136 138 140 142 144 146 148
> length(x)
[1] 50
> y=seq(152,201,1)
> y
[1] 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
168 169 170
[20] 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
187 188 189
[39] 190 191 192 193 194 195 196 197 198 199 200 201
> length(y)
[1] 50
> data.frame(x,y)
x y
1 50 152
2 52 153
3 54 154
4 56 155
5 58 156
6 60 157
7 62 158
8 64 159
9 66 160
10 68 161
11 70 162
12 72 163
13 74 164
14 76 165
15 78 166
16 80 167
17 82 168
18 84 169
19 86 170
20 88 171
21 90 172
22 92 173
23 94 174
24 96 175
25 98 176
26 100 177
27 102 178
28 104 179
29 106 180
30 108 181
31 110 182
32 112 183
33 114 184
34 116 185
35 118 186
36 120 187
37 122 188
38 124 189
39 126 190
40 128 191
41 130 192
42 132 193
43 134 194
44 136 195
45 138 196
46 140 197
47 142 198
48 144 199
49 146 200
50 148 201
> cor.test(x,y,method="pearson")

Pearson's product-moment correlation


data: x and y
t = Inf, df = 48, p-value < 2.2e-16
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
1 1
sample estimates:
cor
1
> cor(x,y)
[1] 1
> cor(x,y,method="pearson")
[1] 1
> var(x)
[1] 850
> var(y)
[1] 212.5
> var(x,y)
[1] 425
> r=var(x,y)/sqrt(var(x)*var(y))
> r
[1] 1
> # correlation coeff can be found by any of these 4 commands , so
here for the given data its 1 therefore its very strong into the
positive direction.
> plot(y,x,main="HEIGHT vs WEIGHT OF CLASS A STUDENTS")
Problem 2: Ten management students got the following percentages of marks in
mental ability and human resource subjects:
Mental ability (x): 56 64 75 85 85 87 91 96 97 98
Human Resources (y): 89 90 86 74 78 66 56 74 86 90
Write down R code to find the linear regression lines between mental ability (x)
and human resources (y). Comment on the correlation coefficient.

> # NAME = BADIGI SHIVA KUMAR


> # REG.NO = 20MIS0173
> # QUESTION 2
>
>
> x=c(56,64,75,85,85,87,91,96,97,98)
> x
[1] 56 64 75 85 85 87 91 96 97 98
> y=c(89,90,86,74,78,66,56,74,86,90)
> y
[1] 89 90 86 74 78 66 56 74 86 90
> lm(x~y)
Call:
lm(formula = x ~ y)

Coefficients:
(Intercept) y
122.1963 -0.4917

> lm(y~x)

Call:
lm(formula = y ~ x)
Coefficients:
(Intercept) x
105.5366 -0.3194

> # linear regression lines between mental ability (x) and human
resources (y) are y= -0.3194x+105.5366 (or) x= -0.4917y+122.1963
>
> cor(x,y)
[1] -0.39629
> cor(x,y,method="pearson")
[1] -0.39629
> # HENCE, CORRELATION IS WEAK INTO THE NEGITIVE DIRECTION .,
>
> plot(x,y,main= ' PERCENTAGES OF MARKS IN MENTAL ABILITY vs
PERSENTAGES OF MARKS IN HUMAN RESOURCES')
> lines(x,y,col="black",type="o")
Problem 3: Suppose we have ranks of 10 days sales of a product in three
localities. Find which two localities have the same trend of sales.
Jaipur: 4 6 2 3 5 8 10 9 1 7
Vellore: 3 10 4 5 6 7 2 8 19
Nagpur: 5 1 3 10 4 8 7 9 2 6

> # NAME = BADIGI SHIVA KUAMR


> # REG.NO = 20MIS0173
> #QUESTION 3
>
>
> x=c(4,6,2,3,5,8,10,9,1,7)
> y=c(3,10,4,5,6,7,2,8,1,9)
> z=c(5,1,3,10,4,8,7,9,2,6)
> x
[1] 4 6 2 3 5 8 10 9 1 7
> y
[1] 3 10 4 5 6 7 2 8 1 9
> z
[1] 5 1 3 10 4 8 7 9 2 6
> cor(x,y)
[1] 0.4181818
> cor(y,z)
[1] 0.07878788
> cor(x,z)
[1] 0.4666667
>
> # OUT OF THESE THREE, CORRELATION OF X and Z IS QUITE STRONG THAN
REMAINING.
> #JAIPUR & NAGPUR HAVE THE SAME TREND OF SALES COMPARED WITH
OTHERS.
> plot(x,z)
> lines(x,z,col="black",type="o")

You might also like