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

Kaushal Bhadra

Comps A1-1 16010122015

14th February 2023

Tutorial-4 : R – R Program on Probability Distribution

Q1) If X is Binomial Distribution B(n,p) where n=50 p=0.35


Write R-program to evaluate and print (i) P(X=15) (ii) P(X≤26)
(iii) P(X≥17)

CODE

d <- dbinom(15, 50, 0.35)

e <- pbinom(26, 50, 0.35)

f <- 1 - pbinom(16, 50, 0.35) # P(X≥17) = 1 - P(X≤16)

cat("For X ~ B(50, 0.35):\n")

cat("P(X=15) =", d, "\n")

cat("P(X≤26) =", e, "\n")

cat("P(X≥17) =", f, "\n")

cat("Name & Roll No: Kaushal Bhadra & 16010122015\n")

OUTPUT
Q2) If X is Poisson Distribution with mean 35
Write R-program to evaluate and print (i) P(X=0) (ii) P(X≤12) (iii) P(22≤X≤35)
CODE :
m <- 35
d <- dpois(0, m)
e <- ppois(12, m)
f <- ppois(35, m) - ppois(21, m)
cat("For X ~ Poisson(mean = 35):\n")
cat("P(X=0) =", d, "\n")
cat("P(X≤12) =", e, "\n")
cat("P(22≤X≤35) =", f, "\n")
cat("Name & Roll No:Kaushal Bhadra & 16010122015\n")

R Studio Screen
Q3. If X is Uniform Distribution over the range (1,15). Write R-
program to evaluate andprint (i) P(X<9.6) (ii) P(X>5.2) (iii) P(11.2<
X<14.5)

CODE :

d <- punif(9.6, 1, 15)


e <- 1 - punif(5.2, 1, 15)
f <- punif(14.5, 1, 15) - punif(11.2, 1, 15)
cat("For X ~ Uniform(1, 15):\n")
cat("P(X<9.6) =", d, "\n")
cat("P(X>5.2) =", e, "\n")
cat("P(11.2<X<14.5) =", f, "\n")
cat("Name, Roll No, Q No.: Kaushal Bhadra, 16010122015, Q3")

R Studio Screen

Q4) If X is Exponential Distribution with mean 40. Write R-program to evaluate


and print

(i) P(X<25) (ii) P(X>30) (iii) P(15< X<65).

CODE: pa <- 1/40 # rate parameter, not 1/200


a <- pexp(25, pa)
b <- 1 - pexp(30, pa)
c <- pexp(65, pa) - pexp(15, pa)
k <- qexp(0.8, pa)
cat("For X ~ Exponential(mean = 40):\n")
cat("P(X<25) =", a, "\n")
cat("P(X>30) =", b, "\n")
cat("P(15<X<65) =", c, "\n")
cat("The value of k is ", k, "\n")
cat("Name, Roll No, Q No.: Kaushal Bhadra, 16010122015, Q4")

OUTPUT:

Q5) If X is Normal Distribution with mean 60 and standard deviation 15. Write R-
program to evaluate

and print (i) P(X<88) (ii) P(X>35) (iii) P(70< X<95).

Find value of k1 such that P(X<k1) = 0.7. Also find k2 such that P(X>k2) = 0.84

CODE:
d <- pnorm(88, 60, 15)
e <- 1 - pnorm(35, 60, 15)
f <- pnorm(95, 60, 15) - pnorm(70, 60, 15)
k1 <- qnorm(0.7, 60, 15)
k2 <- qnorm(0.16, 60, 15) # 1 - 0.84 = 0.16
cat("For X ~ Normal(mean = 60, sd = 15):\n")
cat("P(X<88) =", d, "\n")
cat("P(X>35) =", e, "\n")
cat("P(70<X<95) =", f, "\n")
cat("Value of k1 such that P(X<k1) = 0.7 is", k1, "\n")
cat("Value of k2 such that P(X>k2) = 0.84 is", k2, "\n")
cat("Name, Roll No, Q No.: Kaushal Bhadra, 16010122015, Q5")

OUTPUT:

You might also like