DIGITAL ASSIGNMENT-1
NAME:MICAH JOSEPH
REGISTRATION NO. : 19BIT0404
SAMPLE PROBLEM DONE IN CLASS
RCODE:
> #19BIT0404
> #MICAH JOSEPH
> date()
[1] "Thu Aug 06 17:12:27 2020"
> a<-c(18,19,19,19,19,20,20,20,20,20,21,21,21,21,22,23,24,27,30,36)
> length(a)
[1] 20
> summary(a)
Min. 1st Qu. Median Mean 3rd Qu. Max.
18.00 19.75 20.50 22.00 22.25 36.00
> mean(a)
[1] 22
> median(a)
[1] 20.5
> c<-table(a)
>c
a
18 19 20 21 22 23 24 27 30 36
1 4 5 4 1 1 1 1 1 1
> mode<-which(c==max(c))
> mode
20
3
> sd<-sqrt(var(x))
> sd
[,1] [,2] [,3]
[1,] 3.577709 4.647580 5.440588
[2,] 4.647580 6.099180 7.155418
[3,] 5.440588 7.155418 8.555700
> sd<-sqrt(var(a))
> sd
[1] 4.388981
> Qd<-(22.25-19.75)/2
> Qd
[1] 1.25
> md<-sum(abs(a-mean(a)))/length(a)
> md
[1] 3
> mu3<-(sum(x-mean(x))^3)/length(x)
> mu3<-(sum(a-mean(a))^3)/length(a)
> mu3
[1] 0
> mu3<-(sum((a-mean(a))^3))/length(a)
> mu3
[1] 158.7
> mu4<-(sum((a-mean(a))^4))/length(a)
> mu4
[1] 2190.9
> mu2<-(sum((a-mean(a))^2))/length(a)
> mu2
[1] 18.3
> beta1<-(mu3)^2/(mu2)^3
> beta1
[1] 4.10961
> beta2<-mu4/(mu2)^2
> beta2
Practice Problems
AIM:
1) Compute all the measure of central tendency of the following data:
Height in Cm 145- 150 150- 155 155- 160 160- 165 165- 170 170- 175 175- 180180-185
No. of Adult men 4 6 28 58 64 30 5 5
SYNTAX USED:
1) Midx - finds the middle values of the interval
2) Length(f) - finds the length of frequency table
3) medianserial<-min(which(cf>=N/2))
4) freq<-f[medianserial]
5)
RCODE:
> midx<-seq(147.5,182.5,5)
> midx
[1] 147.5 152.5 157.5 162.5 167.5 172.5 177.5 182.5
> f<-c(4,6,28,58,64,30,5,5)
> length(f)
[1] 8
> cf<-cumsum(f)
> cf
[1] 4 10 38 96 160 190 195 200
> sum(f)
[1] 200
> which(cf>=N/2)
[1] 5 6 7 8
> medianserial<-min(which(cf>=N/2))
> medianserial
[1] 5
> freq<-f[medianserial]
> freq
[1] 64
> cfreq<-cf[medianserial-1]
> cfreq
[1] 96
> h<-5
> l<-midx[medianserial]-h/2
>l
[1] 165
> median<-l+(((N/2)-cfreq)*(h/freq))
> median
[1] 165.625
> mean<-sum(f*midx)/N
> mean
[1] 158.8221
> modeserial<-which(f==max(f))
> modeserial
[1] 5
> f0<-f[modeserial-1]
> f0
[1] 58
> f1<-f[modeserial]
> f1
[1] 64
> f2<-f[modeserial]
> f2
[1] 64
> f2<-f[modeserial+1]
> f2
[1] 30
> mode<-l+((f1-f0)/(2*f1-f0-f2))*h
> mode
[1] 165.75
>
> std_dev<-sqrt((sum(f*midx*midx)/N)-mean**2)
> std_dev
[1] 32.40084
> mean_dev<-sum(f*(abs(midx-mean)))/N
> mean_dev
[1] 7.2647
RSNAPSHOT
Problem 2:-
An entomologist studying morphological variation in species
of mosquito recorded the following data on body length:
1.2,1.4,1.3,1.6,1.0,1.5,1.7,1.1,1.2,1.3
Compute all the measures of dispersion
Formula used:-
1. Range=largest value-smallest value
2. Quartile deviation=Q3-Q1/Q3+Q1
3. Mean deviation = E|x-a|/n
4. Standard Deviation =square root(var(x))
RCODE:
#19BIT0404
> #MICAH JOSEPH
> date()
[1] "Thu Aug 06 18:29:36 2020"
> x=c(1.2,1.4,1.3,1.6,1.0,1.5,1.7,1.1,1.2,1.3)
>x
[1] 1.2 1.4 1.3 1.6 1.0 1.5 1.7 1.1 1.2 1.3
> summary(x)
Min. 1st Qu. Median Mean 3rd Qu. Max.
1.000 1.200 1.300 1.330 1.475 1.700
> range=1.7-1.0#range
> range
[1] 0.7
> var(x)
[1] 0.049
> sd=sqrt(var(x))#standard deviation
> sd
[1] 0.2213594
> cqd=(1.475-1.2)/(1.475+1.2)#quartile deviation
> cqd
[1] 0.1028037
> >#mean deviation about mean
Error: unexpected '>' in ">"
> y=(x-mean(x))
>y
[1] -0.13 0.07 -0.03 0.27 -0.33 0.17 0.37 -0.23 -0.13 -0.03
> y=abs(y)
>y
[1] 0.13 0.07 0.03 0.27 0.33 0.17 0.37 0.23 0.13 0.03
> mdl=sum(y)/length(y)
> mdl
[1] 0.176
> #about median
> z=abs(x-median(x))
> z=abs(x-median(x))
>z
[1] 0.1 0.1 0.0 0.3 0.3 0.2 0.4 0.2 0.1 0.0
> mdl2=sum(z)/length(z)
> mdl2
[1] 0.17
>
RSNAPSHOT:
Challenging tasks:
1) Import the following datas from Excel sheet, Frame the continuous class
frequency distribution table having width 10 and Calculate the measures
of central tendency and dispersion of it.
RCODE
> #19BIT0404
> #MICAH JOSEPH
> date()
[1] "Thu Aug 06 18:05:19 2020"
>
x<-c(32,54,38,44,68,41,30,43,46,41,40,31,40,40,36,46,48,32,40,17,48,4
7,37,52,48,47,32,26,21,41,53,33,32,50,58,33,51,43,45,32,40,50,31,50,4
2,50,55,52,45,44,41,31,50,45,30,48,37,34,36,40,42,45,40,19,61,32,43,4
2,17,57,31,57,47,23,60,51,46,40,31,52,21,35,38,15,37,36,41,34,24,30,3
4,55,34,47,35,58,37,46,41,38,41,15,38,37,52,28,29,38,23,40,51,50,34,3
4,44,44,43,34,34,38,33,41,44,47,38,30,37,42,41,60,49,37,22,42,48,42,5
3,44,47,43,54,39,32,44,17,44,54,50,33,44,39,32,35,44,42,42,38,41,25,4
5,56,50,38,37,50,35,41,33,34,33,26,42,44,42,38,18,56,22,18,38,36,40,5
0,52,30,44,32,58,33,31,39,48,24,33,46,29,45,38,24,43,48,42,62,37,38,4
1,32,17,38,28,35,45,49,37,38,31,53,43,47,36,31,47,42,48,40,53,48,51,4
7,34,49,49,46,46,31,38,48,28,36,45,48,34,39,42,23,37,43,19,39,48)
> x
[1] 32 54 38 44 68 41 30 43 46 41 40 31 40 40 36 46 48 32 40 17 48 47
37 52 48
[26] 47 32 26 21 41 53 33 32 50 58 33 51 43 45 32 40 50 31 50 42 50 55
52 45 44
[51] 41 31 50 45 30 48 37 34 36 40 42 45 40 19 61 32 43 42 17 57 31 57
47 23 60
[76] 51 46 40 31 52 21 35 38 15 37 36 41 34 24 30 34 55 34 47 35 58 37
46 41 38
[101] 41 15 38 37 52 28 29 38 23 40 51 50 34 34 44 44 43 34 34 38 33 41
44 47 38
[126] 30 37 42 41 60 49 37 22 42 48 42 53 44 47 43 54 39 32 44 17 44 54
50 33 44
[151] 39 32 35 44 42 42 38 41 25 45 56 50 38 37 50 35 41 33 34 33 26 42
44 42 38
[176] 18 56 22 18 38 36 40 50 52 30 44 32 58 33 31 39 48 24 33 46 29 45
38 24 43
[201] 48 42 62 37 38 41 32 17 38 28 35 45 49 37 38 31 53 43 47 36 31 47
42 48 40
[226] 53 48 51 47 34 49 49 46 46 31 38 48 28 36 45 48 34 39 42 23 37 43
19 39 48
> summary(x)
Min. 1st Qu. Median Mean 3rd Qu. Max.
15.00 34.00 40.50 39.97 47.00 68.00
> range=68-15
> range
[1] 53
> var(x)
[1] 93.81423
> sd=sqrt(var(x))
> sd
[1] 9.685775
> >cqd=(47-34)/(47+34)
Error: unexpected '>' in ">"
> >cqd=(47-34)/(47+34)
Error: unexpected '>' in ">"
> cqd=(47-34)/(47+34)
> cqd
[1] 0.1604938
> y=(x-mean(x))
> y
[1] -7.968 14.032 -1.968 4.032 28.032 1.032 -9.968 3.032
6.032
[10] 1.032 0.032 -8.968 0.032 0.032 -3.968 6.032 8.032
-7.968
[19] 0.032 -22.968 8.032 7.032 -2.968 12.032 8.032 7.032
-7.968
[28] -13.968 -18.968 1.032 13.032 -6.968 -7.968 10.032 18.032
-6.968
[37] 11.032 3.032 5.032 -7.968 0.032 10.032 -8.968 10.032
2.032
[46] 10.032 15.032 12.032 5.032 4.032 1.032 -8.968 10.032
5.032
[55] -9.968 8.032 -2.968 -5.968 -3.968 0.032 2.032 5.032
0.032
[64] -20.968 21.032 -7.968 3.032 2.032 -22.968 17.032 -8.968
17.032
[73] 7.032 -16.968 20.032 11.032 6.032 0.032 -8.968 12.032
-18.968
[82] -4.968 -1.968 -24.968 -2.968 -3.968 1.032 -5.968 -15.968
-9.968
[91] -5.968 15.032 -5.968 7.032 -4.968 18.032 -2.968 6.032
1.032
[100] -1.968 1.032 -24.968 -1.968 -2.968 12.032 -11.968 -10.968
-1.968
[109] -16.968 0.032 11.032 10.032 -5.968 -5.968 4.032 4.032
3.032
[118] -5.968 -5.968 -1.968 -6.968 1.032 4.032 7.032 -1.968
-9.968
[127] -2.968 2.032 1.032 20.032 9.032 -2.968 -17.968 2.032
8.032
[136] 2.032 13.032 4.032 7.032 3.032 14.032 -0.968 -7.968
4.032
[145] -22.968 4.032 14.032 10.032 -6.968 4.032 -0.968 -7.968
-4.968
[154] 4.032 2.032 2.032 -1.968 1.032 -14.968 5.032 16.032
10.032
[163] -1.968 -2.968 10.032 -4.968 1.032 -6.968 -5.968 -6.968
-13.968
[172] 2.032 4.032 2.032 -1.968 -21.968 16.032 -17.968 -21.968
-1.968
[181] -3.968 0.032 10.032 12.032 -9.968 4.032 -7.968 18.032
-6.968
[190] -8.968 -0.968 8.032 -15.968 -6.968 6.032 -10.968 5.032
-1.968
[199] -15.968 3.032 8.032 2.032 22.032 -2.968 -1.968 1.032
-7.968
[208] -22.968 -1.968 -11.968 -4.968 5.032 9.032 -2.968 -1.968
-8.968
[217] 13.032 3.032 7.032 -3.968 -8.968 7.032 2.032 8.032
0.032
[226] 13.032 8.032 11.032 7.032 -5.968 9.032 9.032 6.032
6.032
[235] -8.968 -1.968 8.032 -11.968 -3.968 5.032 8.032 -5.968
-0.968
[244] 2.032 -16.968 -2.968 3.032 -20.968 -0.968 8.032
> y=abs(y)
> y
[1] 7.968 14.032 1.968 4.032 28.032 1.032 9.968 3.032 6.032
1.032
[11] 0.032 8.968 0.032 0.032 3.968 6.032 8.032 7.968 0.032
22.968
[21] 8.032 7.032 2.968 12.032 8.032 7.032 7.968 13.968 18.968
1.032
[31] 13.032 6.968 7.968 10.032 18.032 6.968 11.032 3.032 5.032
7.968
[41] 0.032 10.032 8.968 10.032 2.032 10.032 15.032 12.032 5.032
4.032
[51] 1.032 8.968 10.032 5.032 9.968 8.032 2.968 5.968 3.968
0.032
[61] 2.032 5.032 0.032 20.968 21.032 7.968 3.032 2.032 22.968
17.032
[71] 8.968 17.032 7.032 16.968 20.032 11.032 6.032 0.032 8.968
12.032
[81] 18.968 4.968 1.968 24.968 2.968 3.968 1.032 5.968 15.968
9.968
[91] 5.968 15.032 5.968 7.032 4.968 18.032 2.968 6.032 1.032
1.968
[101] 1.032 24.968 1.968 2.968 12.032 11.968 10.968 1.968 16.968
0.032
[111] 11.032 10.032 5.968 5.968 4.032 4.032 3.032 5.968 5.968
1.968
[121] 6.968 1.032 4.032 7.032 1.968 9.968 2.968 2.032 1.032
20.032
[131] 9.032 2.968 17.968 2.032 8.032 2.032 13.032 4.032 7.032
3.032
[141] 14.032 0.968 7.968 4.032 22.968 4.032 14.032 10.032 6.968
4.032
[151] 0.968 7.968 4.968 4.032 2.032 2.032 1.968 1.032 14.968
5.032
[161] 16.032 10.032 1.968 2.968 10.032 4.968 1.032 6.968 5.968
6.968
[171] 13.968 2.032 4.032 2.032 1.968 21.968 16.032 17.968 21.968
1.968
[181] 3.968 0.032 10.032 12.032 9.968 4.032 7.968 18.032 6.968
8.968
[191] 0.968 8.032 15.968 6.968 6.032 10.968 5.032 1.968 15.968
3.032
[201] 8.032 2.032 22.032 2.968 1.968 1.032 7.968 22.968 1.968
11.968
[211] 4.968 5.032 9.032 2.968 1.968 8.968 13.032 3.032 7.032
3.968
[221] 8.968 7.032 2.032 8.032 0.032 13.032 8.032 11.032 7.032
5.968
[231] 9.032 9.032 6.032 6.032 8.968 1.968 8.032 11.968 3.968
5.032
[241] 8.032 5.968 0.968 2.032 16.968 2.968 3.032 20.968 0.968
8.032
> mdl=sum(y)/length(y)
> mdl
[1] 7.602816
> #mean deviation about median
> z=abs(x-median(x))
> mdl2=sum(z)/length(z)
> mdl2
[1] 7.6
RSNAPSHOT
Problem 2:-
A quality control engineer is interested in determining
whether a machine is properly adjusted to dispense 16
ounces of sugar. Following data refer to the net weight (in
ounces) packed in twenty on-pound bags after the
machine was adjusted . Compute the measures of
skewness and kurtosis.
15.9,16.2,16.0,15.6,16.2,15.9,16.0,15.6,15.6,16.0
15.8,16.0,15.8,15.9,16.2,15.8,15.8,16.2,16.0,15.9
RCODE:
#19BIT0404
> #MICAH JOSEPH
> date()
[1] "Thu Aug 06 18:19:05 2020"
>
x=c(15.9,16.2,16.0,15.6,16.2,15.9,16.0,15.6,16.0,15.8,16.0,15.8,15.9,
16.2,15.8,16.2,15.8,16.2,16.0,15.9)
> x
[1] 15.9 16.2 16.0 15.6 16.2 15.9 16.0 15.6 16.0 15.8 16.0 15.8 15.9 16.2
15.8
[16] 16.2 15.8 16.2 16.0 15.9
> >n=length(x)
Error: unexpected '>' in ">"
> n=length(x)
> n [1]
[1] 20
> mean=mean(x)
> mean
[1] 15.95
> m4=sum((x-mean)^4)/n
> m4
[1] 0.00258125
> m2=var(x)
> m2
[1] 0.03526316
>
> beta2=m4/(m2^2)
> beta2
[1] 2.07581
> gam2=beta2-3
> gam2
[1] -0.9241897
>
RSNAPSHOT:
FORMULAE USED:
1. Mean = ∑fixi/∑fi
2. Range = Largest value – Smallest value
3. Quartile deviation(Q.D)=Q3-Q2/2
4. Mean deviation:∑|x-A|/n
5. Median=l+((n/2-cf)/f) *h
6. Mode=l+(f1-f0/2f1-f0-f2)*h
7. Mean deviation about median:∑|x-M|/n
8. β1=µ3^2/µ2^3
9. β2=µ4/µ2^2
10. ɤ2=β2-3
LAB OBSERVATION COPY: