Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AIM:
- Write the R programming code for computing the mean, median, mode, quartile deviation, variance,
- standard deviation, co-efficient of variation, first four moments about the mean and Pearson’s coefficients for the following frequency distribution
- KEY WORDS:
- Example:
- M = Mean
- MD = Median
- Mode = mode
- Cl = cumulative frequency
- H = height of the class
- F = frequency
- V = variance
- SD = standard deviation
- CV = coefficient of variation
- B1 & B2 = Pearson’s Coefficients
- M1,M2,M3,M4 = Moments about mean
- R-CODE:
- h=10
- x=seq(175,245,h)
- f=c(53,68,85,92,100,95,70,28)
- N=sum(f)
- Reg. No: XXXXX
- Name: YYYYY
- M=(sum(x*f))/sum(f)
- M
- cl=cumsum(f)
- cl
- ml=min(which(cl>=N/2))
- ml
- F=f[ml]
- F
- c=cl[ml-1]
- c
- l=midx[ml]-h/2
- MD=l+(((N/2)-c)/f)*h
- MD
- m=which(f==max(f))
- m
- fm=f[m]
- fm
- f1=f[m-1]
- f2=f[m+1]
- f1
- f2
- l=midx[m]-h/2
- l
- mode=l+((fm-f1)/(2*fm-f1-f2))*h
- mode
- var=((1/N)*(sum(x^2*f)))-((1/N)*(sum(x*f)))^2
- var
- SD=sqrt(var)
- SD
- CV=100*(SD/M)
- CV
- Reg. No: XXXXX
- Name: YYYYY
- M1=sum(((x-M)^1)*f)/N
- M2=sum(((x-M)^2)*f)/N
- M3=sum(((x-M)^3)*f)/N
- M4=sum(((x-M)^4)*f)/N
- B1=(M3^2)/(M2^3)
- B2=(M4)/(M2^2)
- B1
- B2
- G1=sqrt(B1)
- G2=B2-3
- G1
- G2
- ________________________________________________________________________________________________
- DIGITAL ASSIGNMENT – 3
- PROBABILITY AND STATISTICS LAB
- Course Code: BMAT202P
- NAME :-Muhammad Idris
- REG NO – 21BCE37776
- CLASS NUMBER: VL2022230503586
- LAB SLOT: L5 + L6
- AIM :- SOLVING THE GIVEN QUESTIONS USING Binomial, poisson and Normal distributions.
- 21BCE3695
- Code
- It is known that probability of an item produced by a certain machine will be defective is
- 0.05. If the produced items are sent to the market in 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 consignment of 1000 packets.
- # Exp 3 - Binomial, poisson and Normal distributions
- # Binomial Distribution
- n = 20
- p = 0.05
- q = 1 - p
- N = 1000
- #1. Number of items containing at least 2 defective items in a consignment
- k = 2
- N1 = round(N*(1 - pbinom(k-1,n,p)))
- N1
- #2. Number of packets containing exactly 2 defective itens in a
- consignment k = 2
- N2 = round(N*dbinom(k,n,p))
- N2
- #3. Number of packets containing at most 2 defective items in a consignment
- of k = 2
- N3 = round(N*(pbinom(k,n,p)))
- N3
- 21BCE3695
- Output:-
- Conclusion
- Hence,
- The probability of packets containing at least 2 defective items is – 264
- The probability of packets containing exactly 2 defective items is – 189
- The probability of packets containing at most 2 defective items is – 925
- 21BCE3695
- 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 car is not fulfilled
- Code:-
- # Poissons Distribution
- lam = 1.5
- #1. Propotional of days on which neither car is used
- x = 0
- P1 = dpois(x,lam)
- P1
- #2. Propotional of days on which atmost one car is
- used x = 1
- P2 = ppois(x,lam)
- P2
- #3. Propotional of days on which some demands of car is not fullfilled
- x = 2
- P3 = 1 - ppois(x,lam)
- P3
- 21BCE3695
- Output:-
- Conclusion:-
- Hence from the analysis,
- The proportion of days on which neither car is used – 0.2231302 The
- proportion of days on which at most 1 car is used – 0.5578254
- The proportion of days on which some demand of car is not fullfilled – 0.1911532.
- 21BCE3695
- The local corporation authorities in a certain city install 10,000 electric lamps in the
- streets of the city with the assumption that the life of lamps is normally distributed. If
- these 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.
- Code:-
- # Normal distribution
- Mu = 1000
- SD = 200
- N = 10000
- #1. Number of lamps might be expected to fail in the first 800 burning
- hours x1 = 800
- N1 = round(N*pnorm(x1,Mu,SD))
- N1
- #2. Number of lamps might be expected to fail between 800 to 1200 burning hours
- x1 = 800
- x2 = 1200
- N2 = round(N*(pnorm(x2,Mu,SD)-pnorm(x1,Mu,SD)))
- N2
- 21BCE3695
- Output:-
- Conclusion:-
- Hence,
- The number of lamps might be expected to fail in the first 800 burning hours – 1587
- The number of lamps might be expected to fail in between 800 to 1200 burning hours – 6827
- NAME : Muhammad Idris
- REG.NO : 21BCE3776
- SUBJECT CODE : BMAT202P
- SUBJECT TITLE : Probability and Statistics LAB
- SLOT : L5+L6
- SEMESTER : Winter Semester 2022-2023 GUIDED
- BY : Dr. MANIMARAN A
- Question 1)
- Experience has shown that 20% of a manufactured product is of top 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 day chosen is a representative sample at 95%
- confidence level.
- p_hat <- 50/400
- p_null <- 0.2
- n <- 400
- z_score <- (p_hat - p_null) / sqrt(p_null * (1 - p_null) / n)
- p_value <- 2 * pnorm(-abs(z_score))
- alpha <- 0.05
- if (p_value < alpha) {
- cat("Reject the null hypothesis, the production of the day chosen is not a representative sample.")
- } else {
- cat("Fail to reject the null hypothesis, the production of the day chosen is a representative sample.")
- }
- Output:
- Reject the null hypothesis, the production of the day chosen is not a representative sample.
- Question 2)
- Before an increase in excise duty on tea, 800 people out of a sample of 1000 were
- consumers of tea. After the increase in duty, 800 people were consumers of tea in a
- sample of 1200 persons. Write down the R programming code to test whether the
- significant decrease in the consumption of tea after the increase in duty at 1 % level of
- significance.
- Print (“H0:= p1 = p2”)
- Print(“H1:= p1 != p2”)
- Alpha = 0.01
- ZTab = gnorm(1-alpha)
- ZTab
- N1 = 1000
- N2 = 1200
- P1 = 800/1000
- P2 = 800/1200
- P = ((n1 * p1) + (n2 * p2))/(n1 + n2)
- Q = 1 – P
- ZCal = ((p1 – p2) / sqrt(P * Q * (1/n1) + (1/n2)))
- ZCal
- If (abs(ZCal) < abs(ZTab)) {
- Print (“H0 is accepted and H1 is rejected”)
- } else {
- Print (“H0 is accepted and H1 is rejected”)
- }
- Question 3)
- A sample of 900 items is found to have a mean of 3.47 cm. Write down the R
- programming code to test whether it can be reasonably regarded as a simple sample
- from a population with mean 3.23 cm and SD 2.31 cm at 99% level of confidence.
- Print (“H0:= x0 = Mu”)
- Print (“H1:= x0 !- Mu”)
- Alpha = 0.01
- ZTab = gnorm(1 – alpha)
- ZTab
- Mu = 3.23
- Sigma = 2.31
- N = 900
- X0 = 3.47
- ZCal = (x0 – Mu)/ ( Sigma/ sqrt(n))
- ZCal
- If (abs(ZCal) < abs(ZTab)) {
- Print (“H0 is accepted and H1 is rejected”)
- } else {
- Print (“H0 is rejected and H1 is accepted”)
- }
- Question 4)
- The average mark scored by 32 boys is 72 with a standard deviation of 8, while that for
- 36 girls is 70 with a standard deviation of 6. Write down the R programming code to
- test whether the boys are performing better than girls on the basis of average mark at
- 5 % level of significance.
- Print (“H0 := x1 = x2”)
- Print (“H1 := x1 != x2”)
- Alpha = 0.05
- ZTab = gnorm(1 – alpha)
- ZTab
- N1 = 32
- N2 = 36
- X1 = 72
- X2 = 70
- s1 = 8
- S2 = 6
- ZCal = (x1-x2) / sqrt(((s1^2) / n1) + ((s2 ^ 2)/n2))
- ZCal
- If(abs(ZCal) < abs(ZTab)) {
- Print (“H0 is accepted and H1 is rejected”)
- } else {
- Print (“H0 is rejected and H1 is accepted”)
- }
- NAME : Muhammad Idris
- REG.NO : 21BCE3776
- SUBJECT CODE : MAT202P
- SUBJECT TITLE : PROBABILITY AND STATISTICS LAB
- LAB SLOT : L5+L6
- SEMESTER : Winter Semester 2022-2023
- GUIDED BY : Dr. MANIMARAN A
- AIM:
- Finding the test statistic in t test, paired test and F test
- KEY WORDS:
- Mean
- Var=Variance
- QN 1)
- A random sample of 10 boys with the following IQs: 70, 120, 110, 101, 88, 83,
- 95, 98, 107, and 100. Write down the R programming code to test whether
- the data support the assumption of a population mean IQ of 100 at 5 % level
- of significance
- R-CODE:
- print("H0 := X0=Mu")
- print("H1 := x0!=Mu")
- alpha=0.05
- Mu=100
- n=10
- x=c(70,120,110,101,88,83,95,98,107,100)
- x0=mean(x)
- s=sqrt(var(x))
- tTab=qt((1-alpha),(n-1))
- tTab
- tCal=(x0-Mu)/(s/sqrt(n-1))
- tCal
- if(abs(tCal)<abs(tTab)){
- print("H0 is accepted and H1 is rejected")
- } else {
- print("H0 is rejected and H1 is accepted")
- }
- t.test(x,mu=Mu)
- CONCLUSION:
- tTab=1.833113
- tCal=-0.5885024
- H0 is accepted and H1 is rejected
- OUPUT SIMULATION AND R-CODE:
- QN2)
- The mean height and the standard deviation height of 8 randomly chosen soldiers are
- 166.9 cm and 8.29 cm respectively. The corresponding values of 6 randomly chosen sailors
- are 170.3 cm and 8.50 cm respectively. Write down the R programming code to test
- whether the soldiers are shorter than the sailors on the basis of average height.
- R-CODE:
- print("H0 := x1=x2")
- print("H1 := x1!=x2")
- alpha=0.01
- n1=8
- n2=6
- x1=166.9
- x2=170.3
- s1=8.29
- s2=8.50
- Sigma=sqrt(((n1*s1^2)+(n2*s2^2))/(n1+n2-2))
- tTab=qt((1-alpha),(n1+n2-2))
- tTab
- tCal=(x1-x2)/(Sigma*sqrt((1/n1)+(1/n2)))
- tCal
- if(abs(tCal)<abs(tTab)){
- print("H0 is accepted and H1 is rejected")
- } else {
- print("H0 is rejected and H1 is accepted")
- }
- CONCLUSION:
- tTab=2.680998
- tCal=-0.6954801
- H0 is accepted and H1 is rejected
- RCODE SIMULATION AND OUTPUT:
- Q3)
- The following data relate to the marks obtained by 11 students 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 programming code to test whether the data indicate that the students have benefited by
- coaching at 5 % level of significance?
- Test I : 19 23 16 24 17 18 20 18 21 19 20
- Test II : 17 24 20 24 20 22 20 20 18 22 19
- RCODE:
- print("H0 := x1=x2")
- print("H1 := x1!=x2")
- alpha=0.05
- 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=qt((1-alpha),(n-1))
- tTab
- tCal=d/(s/sqrt(n-1))
- tCal
- if(abs(tCal)<abs(tTab)){
- print("H0 is accepted and H1 is rejected")
- } else {
- print("H0 is rejected and H1 is accepted")
- }
- CONCLUSION:
- tTab=1.812461
- tCal=-1.313064
- H0 is accepted and H1 is rejected
- RCODE AND SIMLUATION:
- Q.4) Two random samples drawn from two normal populations with the following
- observations.
- Sample I : 21 24 25 26 27
- Sample II : 22 27 28 30 31 36
- Write down the R programming code to test whether the two populations have the same
- variance at 5 % level of significance.
- RCODE:
- print ("HO := s1=s2")
- print ("H1 := s1!=s2")
- alpha=0.05
- 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) )
- Var1=(n1/(n1-1))*(s1^2)
- Var2=(n2/(n2-1))*(s2^2)
- FTab=qf((1-alpha),(n1-1),(n2-1))
- FTab
- if (Var1>Var2) {
- FCal=Var1/Var2
- } else {
- FCal=Var2/Var1
- }
- FCal
- if(abs(FCal)<abs(FTab)) {
- print ("HO Is accepted and H1 is rejected")
- } else {
- print ("HO Is rejected and H1 is accepted")
- }
- CONCLUSION:
- FTab=5.192168
- FCal=3.912453
- HO Is accepted and H1 is rejected
- OUTPUT AND RCODE SIMULATION:
- Sss
- NAME : Muhammad Idris
- REG.NO : 21BCE3776
- SUBJECT CODE : BMAT202P
- SUBJECT TITLE : Probability and Statistics Lab
- LAB SLOT : L5+L6
- SEMESTER : Winter Semester 2022-2023
- GUIDED BY : Dr. MANIMARAN A
- AIM:
- Finding Measures of Central Tendency, Dispersion, Skewness and Kurtosis for the
- given data.
- KEY WORDS:
- Example:
- n=Sample Size
- alpha= Level of Significance
- OF= Given values
- Tot= Total of the given values
- EV= Calculated Mean
- EF= Mean Frequency
- ChiTab = Tabular Value
- ChiCal = Calculated Value
- Dim = Dimensions
- . The following table gives the number of fatal road accidents that occurred during the 7
- days of a week. Write down the R programming code to test whether the accidents are
- uniformly distributed over the week at 95 % level of confidence.
- R-CODE:
- message(sprintf("80 := The accidents are uniformly distributed over the week"))
- message(sprintf("80 := The accidents are not uniformly distributed over the
- week"))
- alpha=0.05
- OF=c(8, 14, 16, 12, 11, 14, 9)
- Tot= sum(OF)
- n=length(OF)
- EV=Tot/n
- EF=rep(EV,n)
- ChiTab=qchisq((1-alpha),(n-1))
- ChiTab
- ChiCal=sum(((OF-EF)^2)/EF)
- ChiCal
- if(abs(ChiCal)<abs(ChiTab)){
- message(sprintf("H0 is accepted and H1 is rejected"))
- }else{
- message(sprintf("H0 is rejected and H1 is accepted"))
- }
- message(sprintf("H0 := There is no association between gender and attitude"))
- message(sprintf("H0 := There is an association between gender and attitude"))
- A total number of 3759 individuals were interviewed according to gender and decision in
- a public opinion survey on a political proposal with the results as in the following table.
- Write down the R programming code to test the hypothesis that there is no association
- between gender and attitude 5 % level of significance.
- Favoured Opposed Undecided
- Male 1154 475 243
- Female 1103 442 342
- alpha=0.05
- OF=matrix(c(1154, 475, 243, 1103, 442, 342),nrow=2,ncol=3)
- Dim=dim(OF)
- m=Dim[1]
- n=Dim[2]
- EF=matrix(nrow=m,ncol=n)
- for(i in 1:Dim[1])
- {
- for(j in 1:Dim[2])
- {
- EF[i,j]=round(sum(OF[i,])*sum(OF[,j])/sum(OF))
- }
- }
- ChiTab=qchisq((1-alpha),(m-1)*(n-1))
- message(sprintf("Tabulated Chi-Square Value = %0.4f",ChiTab))
- ChiCal=sum(((OF-EF)^2)/EF)
- message(sprintf("Calculated Chi-Square Value = %0.4f",ChiCal))
- if((abs(ChiCal)<abs(ChiTab))){
- message(sprintf("H0 is accepted and H1 is rejected"))
- message(sprintf("Attributes are independent"))
- } else{
- message(sprintf("H0 is rejected and H1 is accepted"))
- message(sprintf("Attributes are nit independent"))
- }
- A random sample is selected from each of 3 makes of ropes (Type 1, Type 2 and Type
- 3) and their breaking strength (in certain units) are measured with the results in the
- following table.
- Type 1 : 70 72 75 80 83
- Type 2 : 60 65 57 84 87 73
- Type 3 : 100 110 108 112 113 120 107
- Write down the R programming code to test whether the breaking strengths of the ropes
- differ significantly at 5 % level of significance.
- #CRD - ANOVA for 1 way classification
- D1=c(70, 72, 75, 90, 83)
- D2=c(60, 65, 57, 84, 87, 73)
- D3=c(100, 110, 108, 112, 113, 120, 107)
- Data=c(D1,D2,D3)
- Data
- Type=c(rep("Type1",length(D1)),rep("Type2",length(D2)),rep("Type3",length(D
- 3)))
- Type
- ANOVA1=aov(Data~Type)
- summary(ANOVA1)
- #RBD - ANOVA for 2 way classification
- Data=c(36, 36, 21, 35, 28, 29, 31, 32, 26, 28, 29, 29)
- Data
- Season=c(rep("Summer",4),rep("Winter",4),rep("Monsoon",4))
- Season
- Salesman=c(rep(c("SalesA","SalesB","SalesC","SalesD"),3))
- Salesman
- ANOVA2=aov(Data~(Season+Salesman))
- summary(ANOVA2)
- #LSD - ANOVA for 3 way classification
- Data=c(16, 17, 20, 16, 21, 15, 15, 12, 13)
- Data
- Day=c(rep("Day1",3),rep("Day2",3),rep("Day3",3))
- Day
- Engine=c(rep(c("Eng1","Eng2","Eng3"),3))
- Engine
- Burner=c("B1","B2","B3","B2","B3","B1","B3","B1","B2")
- Burner
- ANOVA3=aov(Data~(Day+Engine+Burner))
- summary(ANOVA3)
- CONCLUSION:
- 1. H0 is accepted H1 is rejected
- 2. H0 is rejected and H1 is accepted
- The attributes are not independent
- 3.
- I. CRD:
- II. RBD:
- III. LSD:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement