1 - Min / Max Distribution

Let X1, X2, . . . , Xn be n mutually independent random variables, each of which is uniformly distributed on the integers from 1 to k. Let Y denote the minimum of the Xi’s. Find the distribution of Y.

The Min / Max Distribution is \(P(Y \leq y) = 1 - \left(\frac{k - y}{k}\right)^n\)


2a - Geometric Distribution

Your organization owns a copier (future lawyers, etc.) or MRI (future doctors). This machine has a manufacturer’s expected lifetime of 10 years. This means that we expect one failure every ten years. (Include the probability statements and R Code for each part.).

What is the probability that the machine will fail after 8 years?. Provide also the expected value and standard deviation. Model as a geometric. (Hint: the probability is equivalent to not failing during the first 8 years.)

The geometric distribution is: \(P(X = k) = (1 - p)^{k-1} \cdot p\)

Expected value: \(\mu = \frac{1}{p}\)

Standard deviation: \(\sigma = \frac{\sqrt{1-p}}{p}\)


The geometric distribution is : \(P(X = 9) = (1 - 0.1)^{9-1} \cdot 0.1\)

Expected value: \(\mu = \frac{1}{0.1}\)

Standard deviation: \(\sigma = \frac{\sqrt{1-0.1}}{0.1}\)

# Probability of failure in a given year
p <- 1/10  

# Probability of not failing in a given year
q <- 1 - p  
probability_not_failing_first_8_years <- q^8

# Expected value and standard deviation
expected_value <- 1 / p
standard_deviation <- sqrt(1 - p) / p

# Results
cat("Probability that the machine fails after 8 years: ", 1 - probability_not_failing_first_8_years, "\n")
## Probability that the machine fails after 8 years:  0.5695328
cat("Expected value (years): ", expected_value, "\n")
## Expected value (years):  10
cat("Standard deviation (years): ", standard_deviation, "\n")
## Standard deviation (years):  9.486833
# Probability of failure in any given year
p <- 1/10

# Calculate first success happening from 1 to 20 trials (years)
trials <- 1:20
probabilities <- dgeom(trials - 1, p)

# Create a data frame for plotting
data <- data.frame(Trials = trials, Probability = probabilities)

# Plot
ggplot(data, aes(x = Trials, y = Probability)) +
  geom_point(color = "steelblue") +
  geom_line(aes(group=1), color="steelblue") +
  labs(title = "Geometric Distribution of Time Until First Failure",
       x = "Trial (Year)",
       y = "Probability") +
  theme_minimal()


2b - Exponential Distribution

What is the probability that the machine will fail after 8 years?. Provide also the expected value and standard deviation. Model as an exponential.

Exponential Distribution: \(f(x;\lambda) = \lambda e^{-\lambda x}\)

Expected value: \(\mu = \frac{1}{\lambda}\)

Standard deviation: \(\sigma = \frac{1}{\lambda}\)


For \(\lambda = 0.1\): \(f(x;0.1) = 0.1 e^{-0.1 x}\)

Expected value: \(\mu = \frac{1}{0.1}\)

Standard deviation: \(\sigma = \frac{1}{0.1}\)

#To calculate the probability that the machine will fail after 8 years, we use the cumulative distribution function.

# Rate
lambda <- 0.1 

# Probability of failures after 8 years
probability_failure_after_8_years <- 1 - exp(-lambda * 8)

# Expected value and standard deviation
expected_value <- 1 / lambda
standard_deviation <- 1 / lambda

# Results
cat("Probability that the machine fails after 8 years:", probability_failure_after_8_years, "\n")
## Probability that the machine fails after 8 years: 0.550671
cat("Expected value (years):", expected_value, "\n")
## Expected value (years): 10
cat("Standard deviation (years):", standard_deviation, "\n")
## Standard deviation (years): 10
# Rate
lambda <- 0.1

# Time values
time_values <- seq(0, 50, by = 0.1)

# Calculate exponential distribution
density_values <- dexp(time_values, rate = lambda)

# Create a data frame for plotting
data <- data.frame(Time = time_values, Density = density_values)

# Plot
ggplot(data, aes(x = Time, y = Density)) +
  geom_line(color = "steelblue") +
  labs(title = "Exponential Distribution of Time Between Failures",
       x = "Time (Years)",
       y = "Density") +
  theme_minimal()


2c - Binomial Distribution

What is the probability that the machine will fail after 8 years?. Provide also the expected value and standard deviation. Model as a binomial. (Hint: 0 success in 8 years)

Binomial Distribution: \(P(X = k) = \binom{n}{k} p^k (1-p)^{n-k}\)

Expected Value: \(\mu = np\)

Standard Deviation: \(\sigma = \sqrt{np(1-p)}\)


Binomial Distribution: \(P(X = 0) = \binom{8}{0} 0.1^0 (1-0.1)^{8-0}\)

Expected value: \(\mu = 8 \times 0.1\)

Standard deviation: \(\sigma = \sqrt{8 \times 0.1 \times (1-0.1)}\)

# Parameters
n <- 8  
p <- 0.1

# Probability of no failure in the first 8 years
probability_no_failures <- dbinom(0, n, p)

# Expected value and standard deviation
expected_value <- n * p
standard_deviation <- sqrt(n * p * (1 - p))

# Results
cat("Probability that the machine does not fail in the first 8 years:", probability_no_failures, "\n")
## Probability that the machine does not fail in the first 8 years: 0.4304672
cat("Expected value (failures in 8 years):", expected_value, "\n")
## Expected value (failures in 8 years): 0.8
cat("Standard deviation (failures in 8 years):", standard_deviation, "\n")
## Standard deviation (failures in 8 years): 0.8485281
# Parameters
n <- 8  
p <- 0.1

# Calculate probabilities
k_values <- 0:n
probabilities <- dbinom(k_values, n, p)

# Create a data frame for plotting
data <- data.frame(Failures = k_values, Probability = probabilities)

# Plot
ggplot(data, aes(x = Failures, y = Probability)) +
  geom_bar(stat = "identity", fill = "steelblue", alpha = 0.7) +
  labs(title = "Binomial Distribution of Machine Failures Over 8 Years",
       x = "Number of Failures",
       y = "Probability") +
  theme_minimal() +
  scale_x_continuous(breaks = k_values) # Ensure all k_values are shown


2d - Poisson Distribution

What is the probability that the machine will fail after 8 years?. Provide also the expected value and standard deviation. Model as a Poisson.

Given the expected lifetime of the machine is 10 years, we expect one failure every 10 years. For an 8-year period, the rate is: \(\lambda = 8 \times \frac{1}{10} = 0.8\)

Poisson Distribution: \(P(X = k) = \frac{\lambda^k e^{-\lambda}}{k!}\)

Expected Value; \(\mu = \lambda\)

Standard Deviation: \(\sigma = \sqrt{\lambda}\)


Poisson: \(P(X = k) = \frac{0.8^k e^{-0.8}}{0!}\)

Expected Value: \(\mu = 0.8\)

Standard Deviation: \(\sigma = \sqrt{0.8}\)

# Rate
lambda <- 0.8  

# Probability of no failures in 8 years (X = 0)
probability_no_failures <- dpois(0, lambda)

# Expected value and standard deviation
expected_value <- lambda
standard_deviation <- sqrt(lambda)

# Results
cat("Probability of no failures in 8 years:", probability_no_failures, "\n")
## Probability of no failures in 8 years: 0.449329
cat("Expected value (failures in 8 years):", expected_value, "\n")
## Expected value (failures in 8 years): 0.8
cat("Standard deviation (failures in 8 years):", standard_deviation, "\n")
## Standard deviation (failures in 8 years): 0.8944272
# Rate
lambda <- 0.8

# Poisson distribution for k = 0 to 10
k_values <- 0:10
probabilities <- dpois(k_values, lambda)

# Create a data frame for plotting
data <- data.frame(Failures = k_values, Probability = probabilities)

# Plot
ggplot(data, aes(x = Failures, y = Probability)) +
  geom_bar(stat = "identity", fill = "skyblue", alpha = 0.7) +
  labs(title = "Poisson Distribution (lambda = 0.8)",
       x = "Number of Failures in 8 Years",
       y = "Probability") +
  theme_minimal() +
  scale_x_continuous(breaks = k_values) # Ensure all k_values are shown