s
s
1. Problem Statement: Write the R programming code for computing the mean, median,
mode, quartile
2. R Programming Part
• Mid- value of classinterval: x=seq(175,245,10) i.e.{175, 185, 195, 205, 215, 225, 235,
245}
• Given frequencies of class: f=c(52, 68, 85, 92, 100, 95, 70, 28)
#ASSESSMENT 1
> h=10
> x=seq(175,245,10)
> f=c(52,68,85,92,100,95,70,28)
> N=sum(f)
> mean=sum(x*f)/N
> mean
[1] 208.9831
> cf=cumsum(f)
> medianclass=min(which(cf>=(N/2)))
> ll=x[medianclass]-(h/2)
> median=ll+((h/f[medianclass])*((N/2)-cf[medianclass-1]))
> median
[1] 209.7826
> modalclass=which(f==max(f))
> f1=f[modalclass]
> f0=f[modalclass-1]
> f2=f[modalclass+1]
> llmodal=x[modalclass]-(h/2)
> mode=llmodal+((h*(f1-f0))/(f1-f0-f2+f1))
> mode
[1] 216.1538
> q1=min(which(cf>=(N/4)))
> q3=min(which(cf>=((3*N)/4)))
> lq1=x[q1]-(h/2)
> lq3=x[q3]-(h/2)
> Q1=lq1+((h/f[q1])*((N/4)-cf[q1-1]))
> Q3=lq3+((h/f[q3])*(((3*N)/4)-cf[q3-1]))
> QD=0.5*(Q3-Q1)
> QD
[1] 15.77709
> var=sum(f*(x-mean)*(x-mean))/N
> SD=sqrt(var)1
> SD
[1] 19.69857
> var
[1] 388.0336
> CV=(SD/mean)*100
> CV
[1] 9.425917
> m1=sum((f*x)-(f*mean))/N
> m2=sum((f*((x-mean)^2)))/N
> m3=sum((f*((x-mean)^3)))/N
> m4=sum((f*((x-mean)^4)))/N
> m1
[1] -1.233213e-14
> m2
[1] 388.0336
> m3
[1]-447.3203
> m4
[1] 306260.9
defective is 0.05. If the produced items are sentto the marketin packets of 20, then write
down the R
code to find the number of packets containing at least, exactly and at most 2 defective
items in a
2. R Programming Part
• Probability : p=0.05
# binomial distribution
n=20
p=0.05
N=1000
#the number ofpackets containingatleast 2 defective items
k=2
N1=round(N*(1-pbinom(k-1,n,p)))
k=2
N2=round(N*dbinom(k,n,p))
k=2
N3=round(N*pbinom(k,n,p))
> N1
[1] 264
> N2
[1] 189
> N3
[1] 925
. Problem Statement: A car hire firm has 2 cars which it hires out day by day. The
number of demands for
a car on each day follows a Poisson distribution with mean 1.5. Write down the R code
to compute the
proportion of days on which (i). neither car is used,(ii). at most one car is used and (iii).
some demand of
2. R Programming Part
#QUESTION 2
lam=1.5
#Proportion of days on which neither car is used:
x=0
P1=dpois(x,lam)
x=1
P2=ppois(x,lam)
x=2
P3=1-ppois(x,lam)
> P1
[1] 0.2231302
> P2
[1] 0.5578254
> P3
[1] 0.1911532
1. Problem Statement: The local corporation authorities in a certain city install 10,000
electric lamps in
the streets ofthe city with the assumption thatthe life of lamps is normally distributed.
Ifthese lamps
have an average life of 1,000 burning hours with a standard deviation of 200 hours, then
write down
the R code to calculate the number of lamps might be expected to fail in the first 800
burning hours
and also the number of lamps might be expected to fail between 800 and 1,200 burning
hours.
2. R Programming Part
#QUESTION 3
#NORMALDISTRIBUTION
Mu=1000
SD=200
N=10000
#1 the number oflamps might be expectedto fail in the first800 burning hours:
x1=800
N1=round(N*pnorm(x1,Mu,SD))
#2 the number oflamps might be expected to fail between 800and 1200 burning hours:
x1=800
x2=1200
N2=round(N*(pnorm(x2,Mu,SD)-pnorm(x1,Mu,SD)))
> N1
[1] 1587
> N2
[1] 6827
Write down the R code to compute the coe icient of correlation between X and Y from
the following data:
Y : 60, 71, 72, 83, 110, 84, 100, 92, 113, 135
Code:
> #CORRELATION
>
> X=c(21,23,30,54,57,58,72,78,87,90)
> Y=c(60,71,72,83,110,84,100,92,113,135)
> Cor1=cor(X,Y)
> Cor1
[1] 0.8775417
Write down the R code to find the rank correlation between the ranks of the variable X
and Y from the following data:
X : 10 15 12 17 13 16 24 14 22
Y : 30 42 45 46 33 34 40 35 39
CODE:
>#RANK CORRELATION
> X=c(10,15,12,17,13,16,24,14,22)
> Y=c(30,42,45,46,33,34,40,35,39)
>
> n=length(X)
> U=rank(X)
> V=rank(Y)
> SumD2=sum((U-V)^2)
> RankCor=1-((6*SumD2)/(n*(n^2-1)))
> RankCor
[1] 0.4
Program / Problem No.:3
Write down the R code to obtain the equation of the regression line of X on Y from the
following data:
X : 4.7 8.2 12.4 15.8 20.7 24.9 31.9 35.0 39.1 38.8
Y : 4.0 8.0 12.5 16.0 20.0 25.0 31.0 36.0 40.0 40.0
CODE:
>
> X=c(4.7,8.2,12.4,15.8,20.7,24.9,31.9,35.0,39.1,38.8)
> Y=c(4.0,8.0,12.5,16.0,20.0,25.0,31.0,36.0,40.0,40.0)
>
> Reg=lm(X~Y)
> Reg
Call:
lm(formula = X ~ Y)
Coe icients:
(Intercept) Y
0.7508 0.9634
Write down the R code to obtain the equation of the regression plane of Y on X 1 and X 2
from the following data:
X1 : 30 40 20 50 60 40 20 60
X2 : 11 10 7 15 19 12 8 14
>
> X1=c(30,40,20,50,60,40,20,60)
> X2=c(11,10,7,15,19,12,8,14)
> Y=c(110,80,70,120,150,90,70,120)
>
> MultiReg=lm(Y~X1+X2)
> MultiReg
Call:
lm(formula = Y ~ X1 + X2)
Coe icients:
(Intercept) X1 X2
ExperimentNo.: 4:
quality. In one day’s production of 400 articles, only 50 are of top quality.
Write down the R programming code to test whether the production of the
1000 were consumers of tea. After the increase in duty, 800 people were
Q.3 A sample of 900 items is found to have a mean of 3.47 cm. Write down
70, 120, 110, 101, 88, 83, 95, 98, 107, and 100. Write down the
significance.
Code:
> mu = 100
> n = 10
> x = c(70,120,110,101,88,83,95,98,107,100)
> x0 = mean(x)
> s = sqrt(var(x))
> ttab
[1] 1.833113
> tcal
[1] -0.5885024
> if(abs(tcal)<abs(ttab)){
+ }else{
+ print("h0 is rejected and h1 is accepted")
+}
whether the soldiers are shorter than the sailors on the basis of
average height.
CODE:
> #2
> n1 = 8
> n2 = 6
> x1 = 166.9
> x2 = 170.3
> s1 = 8.29
> s2 = 8.50
> ttab
[1] 2.680998
> tcal = (x1-x2)/(sigma*sqrt((1/n1)+(1/n2)))
> tcal
[1] -0.6954801
> if(abs(tcal)<abs(ttab)){
+ }else{
+}
in two sets, one held at the beginning of a year and the other at
the end of the year after intensive coaching. Write down the R
significance?
CODE:
> #3
> s1 = c(19,23,16,24,17,18,20,18,21,19,20)
> s2 = c(17,24,20,24,20,22,20,20,18,22,19)
> d = s1-s2
> D = mean(d)
> n = length(d)
> s = sqrt(var(d))
> ttab
[1] 1.812461
> tcal
[1] -1.313064
> if(abs(tcal)<abs(ttab)){
+ }else{
+}
Two random samples drawn from two normal populations with the
following observations.
CODE:
> #4
> s1 = c(21,24,25,26,27)
> s2 = c(22,27,28,30,31,36)
> n1 = length(s1)
> n2 = length(s2)
> x1 = mean(s1)
> x2 = mean(s2)
> s1 = sqrt(var(s1))
> s2 = sqrt(var(s2))
> ftab
[1] 5.192168
> fcal
[1] 3.912453
> if(abs(fcal)<abs(ftab)){
+ }else{
+}