R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

# Question 1
# Probability of one defective bolt out of 4
prob_one_defective <- dbinom(1, size = 4, prob = 0.20)

# Probability of zero defective bolts out of 4
prob_zero_defective <- dbinom(0, size = 4, prob = 0.20)

# Probability of at most two defective bolts out of 4
prob_at_most_two_defective <- sum(dbinom(0:2, size = 4, prob = 0.20))

# Output the probabilities
print(paste("Probability of one defective bolt:", prob_one_defective))
## [1] "Probability of one defective bolt: 0.4096"
print(paste("Probability of zero defective bolts:", prob_zero_defective))
## [1] "Probability of zero defective bolts: 0.4096"
print(paste("Probability of at most two defective bolts:", prob_at_most_two_defective))
## [1] "Probability of at most two defective bolts: 0.9728"
# Question 2
# Probability of a worker suffering from the disease
p <- 0.20

# Number of workers
n <- 6

# Calculate the probability that 4 or more workers will suffer from the disease
probability <- sum(dbinom(4:6, size = n, prob = p))

# Print the probability
print(probability)
## [1] 0.01696
# Question 3
# Mean demand for a car per day
lambda <- 1.5

# Proportion of days on which there is no demand (P(X = 0))
no_demand <- dpois(0, lambda)

# Proportion of days on which demand is refused (P(X > 2) since there are only 2 cars available)
demand_refused <- 1 - ppois(1, lambda)

# Print the results
print(paste("Proportion of days on which there is no demand:", no_demand))
## [1] "Proportion of days on which there is no demand: 0.22313016014843"
print(paste("Proportion of days on which demand is refused:", demand_refused))
## [1] "Proportion of days on which demand is refused: 0.442174599628925"
# Question 4
# Probability of a tool being defective
p <- 0.10

# Number of tools in the sample
n <- 10

# Number of defective tools we want in the sample
k <- 2

# Calculate the probability using the binomial distribution
probability_binomial <- dbinom(k, size = n, prob = p)

# Print the probability
print(probability_binomial)
## [1] 0.1937102
# Expected number of defective tools in the sample (mean of binomial distribution)
lambda <- n * p

# Calculate the probability using the Poisson distribution
probability_poisson <- dpois(k, lambda)

# Print the probability
print(probability_poisson)
## [1] 0.1839397
# Question 5
lambda <- 2
prob_3_bad_reactions <- (lambda^3) * exp(-lambda) / factorial(3)
prob_3_bad_reactions
## [1] 0.180447
prob_0_bad_reactions <- (lambda^0) * exp(-lambda) / factorial(0)
prob_1_bad_reactions <- (lambda^1) * exp(-lambda) / factorial(1)
prob_2_bad_reactions <- (lambda^2) * exp(-lambda) / factorial(2)
prob_more_than_2_bad_reactions <- 1 - (prob_0_bad_reactions + prob_1_bad_reactions + prob_2_bad_reactions)
prob_more_than_2_bad_reactions
## [1] 0.3233236
# Question 6
n <- 6
r <- 4
p <- 1/8
prob_4_successes <- choose(n, r) * p^r * (1 - p)^(n - r)
prob_4_successes
## [1] 0.002803802
prob_zero_successes <- choose(n, 0) * p^0 * (1 - p)^n
prob_at_least_one_success <- 1 - prob_zero_successes
prob_at_least_one_success
## [1] 0.5512047