[go: up one dir, main page]

100% found this document useful (1 vote)
139 views12 pages

Matlab-Median and Mode

This document contains a student's solutions to 4 questions in a statistics assignment involving calculating measures of central tendency and dispersion from frequency distributions. The student provides R code and results for each question: calculating the mean, median, and mode of a frequency distribution; comparing the consistency of 2 students' test scores; finding the lower quartile of a frequency distribution; and calculating the median, lower quartile, and upper quartile from a grouped frequency distribution of exam scores.

Uploaded by

Yash Garg
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
100% found this document useful (1 vote)
139 views12 pages

Matlab-Median and Mode

This document contains a student's solutions to 4 questions in a statistics assignment involving calculating measures of central tendency and dispersion from frequency distributions. The student provides R code and results for each question: calculating the mean, median, and mode of a frequency distribution; comparing the consistency of 2 students' test scores; finding the lower quartile of a frequency distribution; and calculating the median, lower quartile, and upper quartile from a grouped frequency distribution of exam scores.

Uploaded by

Yash Garg
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
You are on page 1/ 12

Digital Assignment No.

1
MAT 2001 – Statistics for Engineers
EMBEDDED LAB – Programming with R

Name: YASH GARG


Reg. No: 20BEC0461

Submitted to: Mr. Prabhujit Mohapatra


Q-1:

R Code: -

> mid=seq(50,650,100)

> mid

[1] 50 150 250 350 450 550 650

> f=c(200,450,800,950,700,550,350)

> fr.distr=data.frame(mid,f)

> fr.distr

mid f

1 50 200

2 150 450

3 250 800

4 350 950

5 450 700

6 550 550

7 650 350

> #MEAN:

> mean=(sum(mid*f))/sum(f)

> mean

[1] 363.75

> #MEDIAN:

>

> midx=seq(50,650,100)

> frequency=c(200,450,800,950,700,550,350)

> fr.dist<-data.frame(midx,frequency)

> fr.dist
midx frequency

1 50 200

2 150 450

3 250 800

4 350 950

5 450 700

6 550 550

7 650 350

> cl=cumsum(frequency)

> cl

[1] 200 650 1450 2400 3100 3650 4000

> n=sum(frequency)

>n

[1] 4000

> ml=min(which(cl>n/2))

> ml

[1] 4

> H=100

>H

[1] 100

> f=frequency[ml]

>f

[1] 950

> c=cl[ml-1]

>c

[1] 1450

> l=mid[ml]-H/2

>l

[1] 300

> median=l+(((n/2)-c)/f)*H

> median
[1] 357.8947

> m=which(f==max(f))

>m

[1] 1

> f0=f[m]

> f0

[1] 950

> f1=frequency[3]

> f1

[1] 800

> f2=frequency[5]

> f2

[1] 700

> mode=l+((f0-f1)/(2*f0-f1-f2))*H

> mode

[1] 337.5
Result
Mean-363.75
Median-357.8947
Mode-337.5
Q-2:

R-code:
> A=c(25,50,45,30,70,42,36,48,35,60)

> B=c(10,70,50,20,95,55,42,60,48,80)

> mean(A)

[1] 44.1

> mean(B)

[1] 53

> var(A)

[1] 187.8778

> var(B)

[1] 658.6667

> #Standard deviattion for A:

> SDA_A=sqrt(var(A))

> SDA_A

[1] 13.70685

> #Standard deviattion for B:

> SDA_B=sqrt(var(B))

> SDA_B

[1] 25.6645

> # Coefficient of Variation for A:

> CVA_A=(SDA_A/mean(A))*100

> CVA_A

[1] 31.0813

> # Coefficient of Variation for B:

> CVA_B=(SDA_B/mean(B))*100
> CVA_B

[1] 48.42359

> # CVA_A < CVA_B

> #Hence Student A is more consistent than Student B.

Hence Student A is more consistent than Student B.


Q-3:

Solution:

R-code:
> x=seq(5,55,10)

>x

[1] 5 15 25 35 45 55

> f=c(40,60,200,100,70,30)

> mean=sum(x*f)/sum(f)

> mean

[1] 28.8

> c=cumsum(f)

> cl=cumsum(f)

> cl

[1] 40 100 300 400 470 500


> N=sum(f)

>N

[1] 500

> ml=min(which(cl>N/2))

> ml

[1] 3

> h=10

>h

[1] 10

> fm=f[ml]

> fm

[1] 200

> cf=cl[ml-1]

> cf

[1] 100

> l=x[ml]-h/2

>l

[1] 20

> #Q1=lower quartiles

> Q1=min(which(cl>N/4))

> Q1

[1] 3

> fq1=f[Q1]

> fq1

[1] 200

> cf1=cl[Q1-1]

> cf1

[1] 100

> l=x[Q1]-h/2

>l

[1] 20
> quartile1=l+(((N/4)-cf1)/fq1)*h

> quartile1

[1] 21.25

Result: Hence lower quartile marks(Q1) is 21.25.


Q-4:

Solution:
Marks/Grades Mid value No. of Student

0-10 5 15

10-20 15 35

20-30 25 60

30-40 35 84

40-50 45 94

50-60 55 127

60-70 65 198

70-80 75 249

R-Code:
> cf=c(15,35,60,84,94,127,198,249)

> f=c(cf[1],diff(cf))

> x=seq(10,80,10)

> N=sum(f)

> #Median

> M=x[c(sum(cf<=N/2),sum(cf<=N/2)+1)]

> fo=f[sum(cf<=N/2)+1]

> Median=M[1]+(N/2-cf[sum(cf<=N/2)])/fo*(x[2]-x[1])

> Median
[1] 59.24242

> #Lower Quartile

> Q1=x[c(sum(cf<=N/4),sum(cf<=N/4)+1)]

> fo=f[sum(cf<=N/4)+1]

> LowerQ1=Q1[1]+(N/4-cf[sum(cf<=N/4)])/fo*(x[2]-x[1])

> LowerQ1

[1] 30.9375

> #Upper Quartile

> Q3=x[c(sum(cf<=N*3/4),sum(cf<=N*3/4)+1)]

> fo=f[sum(cf<=N*3/4)+1]

> UpperQ3=Q3[1]+(N*3/4-cf[sum(cf<=N*3/4)])/fo*(x[2]-x[1])

> UpperQ3

[1] 68.41549

Result:
Median-59.24242
Lower Quartile-30.9375
Upper Quartile-68.41549

You might also like