Binomial Probability Distribution Using R

 

Experiment

 Binomial Probability Distribution Using R

1. Aim

To study and implement the Binomial probability distribution in R by calculating individual and cumulative probabilities, generating the probability distribution, finding its mean and variance, and visualizing the distribution.


2. Objectives

After completing this experiment, students should be able to:

  1. Understand the concept and characteristics of the Binomial distribution.
  2. Identify the parameters nn, pp, and qq.
  3. Calculate binomial probabilities manually using the mathematical formula.
  4. Calculate probabilities using R.
  5. Generate the complete binomial probability distribution.
  6. Calculate the mean, variance, and standard deviation.
  7. Visualize and interpret the binomial distribution.

3. Theory

3.1 Binomial Distribution

The Binomial distribution is a discrete probability distribution that describes the number of successes obtained in a fixed number of independent trials.

A random experiment follows a Binomial distribution when:

  • The number of trials nn is fixed.
  • Each trial has only two possible outcomes: success or failure.
  • The probability of success pp is constant for every trial.
  • The trials are independent.

If XX represents the number of successes in nn trials, then:

X∼B(n,p)X \sim B(n,p)

where:

  • nn = number of trials
  • pp = probability of success
  • q=1−pq=1-p = probability of failure
  • xx = number of successes

3.2 Binomial Probability Formula

The probability of obtaining exactly xx successes in nn trials is:

P(X=x)=(nx)pxqn−xP(X=x)=\binom{n}{x}p^xq^{n-x}

where

(nx)=n!x!(n−x)!\binom{n}{x}=\frac{n!}{x!(n-x)!}

Therefore,

P(X=x)=n!x!(n−x)!px(1−p)n−xP(X=x)= \frac{n!}{x!(n-x)!}p^x(1-p)^{n-x}

3.3 Manual Calculation for the Given Problem

Consider the experiment:

A company produces electronic components. The probability that a component is defective is 0.10. If 10 components are selected independently, find the probability of exactly 2 defective components.

Here:

n=10n=10 p=0.10p=0.10 q=1−p=1−0.10=0.90q=1-p=1-0.10=0.90

and

x=2x=2

Therefore:

P(X=2)=(102)(0.10)2(0.90)8P(X=2)=\binom{10}{2}(0.10)^2(0.90)^8

First calculate the binomial coefficient:

(102)=10!2!(10−2)!\binom{10}{2} = \frac{10!}{2!(10-2)!}
=10!2!8!
=\frac{10!}{2!8!}


=10×92×1=45
=\frac{10\times9}{2\times1} =45

Therefore:

P(X=2)=45(0.10)2(0.90)8P(X=2)=45(0.10)^2(0.90)^8
=45(0.01)(0.43046721)
=45(0.01)(0.43046721)

=0.1937102
=0.1937102

Hence,

P(X=2)=0.1937102\boxed{P(X=2)=0.1937102}

or approximately:

19.37%\boxed{19.37\%}

3.4 Manual Calculation of Cumulative Probability

Probability of at most 2 defective components

"At most 2" means:

P(X≤2)P(X\leq2)

Therefore:

P(X≤2)=P(X=0)+P(X=1)+P(X=2)P(X\leq2)=P(X=0)+P(X=1)+P(X=2)

For X=0X=0:

P(X=0)=(100)(0.1)0(0.9)10P(X=0)=\binom{10}{0}(0.1)^0(0.9)^{10}
=0.3486784
=0.3486784

For X=1X=1:

P(X=1)=(101)(0.1)1(0.9)9P(X=1)=\binom{10}{1}(0.1)^1(0.9)^9
=0.3874205
=0.3874205

For X=2X=2:

P(X=2)=0.1937102P(X=2)=0.1937102

Therefore:

P(X≤2)=0.3486784+0.3874205+0.1937102P(X\leq2) = 0.3486784+0.3874205+0.1937102 P(X≤2)=0.9298092\boxed{P(X\leq2)=0.9298092}

or approximately 92.98%.


3.5 Probability of At Least 2 Defective Components

"At least 2" means:

P(X≥2)P(X\geq2)

It is easier to use the complement:

P(X≥2)=1−P(X<2)P(X\geq2)=1-P(X<2)

Since:

P(X<2)=P(X=0)+P(X=1)P(X<2)=P(X=0)+P(X=1)

we get:

P(X≥2)=1−[P(X=0)+P(X=1)]P(X\geq2) = 1-[P(X=0)+P(X=1)]
=1−(0.3486784+0.3874205)
=1-(0.3486784+0.3874205)
P(X≥2)=0.2639011\boxed{P(X\geq2)=0.2639011}

Note: This is the value for the given interpretation of "at least 2." In R, it can be calculated as 1 - pbinom(1, 10, 0.1).


3.6 Mean of Binomial Distribution

The mean or expected value of a Binomial distribution is:

μ=np\mu=np

For the given problem:

μ=10(0.10)\mu=10(0.10) μ=1\boxed{\mu=1}

Thus, the expected number of defective components in 10 components is 1.


3.7 Variance of Binomial Distribution

The variance is:

σ2=npq\sigma^2=npq

Since:

q=1−p=0.90q=1-p=0.90

we get:

σ2=10(0.10)(0.90)\sigma^2=10(0.10)(0.90) σ2=0.9\boxed{\sigma^2=0.9}

3.8 Standard Deviation

The standard deviation is:

σ=npq\sigma=\sqrt{npq}

Therefore:

σ=10(0.10)(0.90)\sigma=\sqrt{10(0.10)(0.90)}
=0.9
=\sqrt{0.9}


σ=0.9486833
\boxed{\sigma=0.9486833}

3.9 R Functions for Binomial Distribution

R provides four important functions:

FunctionMeaning
dbinom(x,n,p)         P(X=x)P(X=x), exactly xx successes
pbinom(x,n,p)         P(X≤x)P(X\leq x), at most xx successes
qbinom()         Finds the value of xx for a given cumulative probability
rbinom()        Generates random observations from a Binomial distribution

4. Program

# Binomial Probability Distribution

# Parameters
n <- 10
p <- 0.10
q <- 1 - p

# Possible number of defective components
x <- 0:n

# Probability distribution
probability <- dbinom(x, size = n, prob = p)

# Display probability distribution
distribution <- data.frame(
    Defective = x,
    Probability = probability
)

print(distribution)


# Probability of exactly 2 defective components
p_exactly_2 <- dbinom(2, size = n, prob = p)

cat("\nProbability of exactly 2 defective components =",
    p_exactly_2, "\n")


# Probability of at most 2 defective components
p_at_most_2 <- pbinom(2, size = n, prob = p)

cat("Probability of at most 2 defective components =",
    p_at_most_2, "\n")


# Probability of at least 2 defective components
p_at_least_2 <- 1 - pbinom(1, size = n, prob = p)

cat("Probability of at least 2 defective components =",
    p_at_least_2, "\n")


# Mean
mean_value <- n * p

# Variance
variance <- n * p * q

# Standard deviation
standard_deviation <- sqrt(variance)

cat("\nMean =", mean_value, "\n")
cat("Variance =", variance, "\n")
cat("Standard Deviation =", standard_deviation, "\n")


# Plot the Binomial distribution
barplot(probability,
        names.arg = x,
        main = "Binomial Probability Distribution",
        xlab = "Number of Defective Components",
        ylab = "Probability")

5. Expected Result

The program produces the binomial probability distribution for X=0,1,…,10X=0,1,\ldots,10.

Important results are:

Defective  Probability
1          0 0.3486784401
2          1 0.3874204890
3          2 0.1937102445
4          3 0.0573956280
5          4 0.0111602610
6          5 0.0014880348
7          6 0.0001377810
8          7 0.0000087480
9          8 0.0000003645
10         9 0.0000000090
11        10 0.0000000001

Probability of exactly 2 defective components = 0.1937102 
Probability of at most 2 defective components = 0.9298092 
Probability of at least 2 defective components = 0.2639011 

Mean = 1 
Variance = 0.9 
Standard Deviation = 0.9486833 

The bar plot represents the probability associated with each possible number of defective components.




6. Result

Thus, the Binomial probability distribution was studied and implemented in R. The probability of exactly 2, at most 2, and at least 2 defective components was calculated. The complete probability distribution was generated and represented graphically. The mean, variance, and standard deviation were also calculated using the standard Binomial distribution formulas and verified using R.

Comments

Popular posts from this blog

Statistical Methods Lab ( R Language) PCCBL308 Semester 3 KTU BTech CB and CU 2024 Scheme - Dr Binu V P

Programs in R - using control statements - Assignment 2

Programs to try using Functions in R - Assignment 3