#1 (Bayesian): A new credit scoring system has been developed to predict the likelihood of loan defaults. The system has a 90% sensitivity, meaning that it correctly identifies 90% of those who will default on their loans. It also has a 95% specificity, meaning that it correctly identifies 95% of those who will not default. The default rate among borrowers is 2%. Given these prevalence, sensitivity, and specificity estimates, what is the probability that a borrower flagged by the system as likely to default will actually default? If the average loss per defaulted loan is $200,000 and the cost to run the credit scoring test on each borrower is $500, what is the total first-year cost for evaluating 10,000 borrowers?
# 1
P_D <- 0.02
sensitivity <- 0.9
specificity <- 0.95
cost_per_test <- 500
loss_per_default <- 200000
num_borrowers <- 10000
false_positive_rate <- 1 - specificity
true_negative_rate <- specificity
numerator <- sensitivity * P_D
denominator <- (sensitivity * P_D) + (false_positive_rate * (1 - P_D))
P_D_given_T <- numerator / denominator
total_testing_cost <- num_borrowers * cost_per_test
expected_positives <- num_borrowers * ((sensitivity * P_D) + (false_positive_rate * (1 - P_D)))
expected_false_positives <- num_borrowers * false_positive_rate * (1 - P_D)
total_default_cost <- expected_false_positives * loss_per_default
total_first_year_cost <- total_testing_cost + total_default_cost
print(list(
posterior_probability = P_D_given_T,
total_first_year_cost = format(round(total_first_year_cost), big.mark = ",", scientific = FALSE)
))
## $posterior_probability
## [1] 0.2686567
##
## $total_first_year_cost
## [1] "103,000,000"
#2 (Binomial): The probability that a stock will pay a dividend in any given quarter is 0.7. What is the probability that the stock pays dividends exactly 6 times in 8 quarters? What is the probability that it pays dividends 6 or more times? What is the probability that it pays dividends fewer than 6 times? What is the expected number of dividend payments over 8 quarters? What is the standard deviation?
#2
n <- 8
p <- 0.7
x <- 6
prob_exactly_6 <- dbinom(x, size = n, prob = p)
print(prob_exactly_6)
## [1] 0.2964755
# Prob it pays dividends 6 or more times
prob_6_or_more <- sum(dbinom(6:8, size = n, prob = p))
print(prob_6_or_more)
## [1] 0.5517738
# Prob it pays dividends fewer than 6 times
prob_fewer_than_6 <- sum(dbinom(0:5, size = n, prob = p))
print(prob_fewer_than_6)
## [1] 0.4482262
#Expected number of dividend payments over 8 quarters
expected_dividends <- n * p
print(expected_dividends)
## [1] 5.6
# STD of the number of dividend payments
std_dev_dividends <- sqrt(n * p * (1 - p))
print(std_dev_dividends)
## [1] 1.296148
#3 (Poisson): A financial analyst notices that there are an average of 12 trading days each month when a certain stock’s price increases by more than 2%. What is the probability that exactly 4 such days occur in a given month? What is the probability that more than 12 such days occur in a given month? How many such days would you expect in a 6-month period? What is the standard deviation of the number of such days? If an investment strategy requires at least 70 days of such price increases in a year for profitability, what is the percent utilization and what are your recommendations?
#3
lambda <- 12
x <- 4
prob_exactly_4 <- dpois(x, lambda)
print(prob_exactly_4)
## [1] 0.005308599
prob_more_than_12 <- 1 - ppois(12, lambda)
print(prob_more_than_12)
## [1] 0.4240348
expected_days_6_months <- lambda * 6
print(expected_days_6_months)
## [1] 72
std_dev_days_6_months <- sqrt(lambda * 6)
print(std_dev_days_6_months)
## [1] 8.485281
expected_days_12_months <- lambda * 12
percent_utilization <- (expected_days_12_months / 70) * 100
print(percent_utilization)
## [1] 205.7143
#4 (Hypergeometric): A hedge fund has a portfolio of 25 stocks, with 15 categorized as high-risk and 10 as low-risk. The fund manager randomly selects 7 stocks to closely monitor. If the manager selected 5 high-risk stocks and 2 low-risk stocks, what is the probability of selecting exactly 5 high-risk stocks if the selection was random? How many high-risk and low-risk stocks would you expect to be selected?
#4
N <- 25
K <- 15
n <- 7
k <- 5
prob_exactly_5_high_risk <- dhyper(k, K, N - K, n)
print(prob_exactly_5_high_risk)
## [1] 0.2811213
expected_high_risk <- n * (K / N)
expected_low_risk <- n * ((N - K) / N)
print(expected_high_risk)
## [1] 4.2
print(expected_low_risk)
## [1] 2.8
#5 (Geometric): The probability that a bond defaults in any given year is 0.5%. A portfolio manager holds this bond for 10 years. What is the probability that the bond will default during this period? What is the probability that it will default in the next 15 years? What is the expected number of years before the bond defaults? If the bond has already survived 10 years, what is the probability that it will default in the next 2 years?
#5
p <- 0.005
years_10 <- 10
prob_no_default_10 <- (1 - p)^years_10
prob_default_10 <- 1 - prob_no_default_10
print(prob_default_10)
## [1] 0.04888987
years_15 <- 15
prob_no_default_15 <- (1 - p)^years_15
prob_default_15 <- 1 - prob_no_default_15
print(prob_default_15)
## [1] 0.07243103
expected_years_to_default <- 1 / p
print(expected_years_to_default)
## [1] 200
years_2 <- 2
prob_no_default_2 <- (1 - p)^years_2
prob_default_next_2 <- 1 - prob_no_default_2
print(prob_default_next_2)
## [1] 0.009975
#6 (Poisson): A high-frequency trading algorithm experiences a system failure about once every 1500 trading hours. What is the probability that the algorithm will experience more than two failures in 1500 hours? What is the expected number of failures?
#6
lambda <- 1
expected_failures <- lambda
print(expected_failures)
## [1] 1
prob_more_than_2_failures <- 1 - ppois(2, lambda)
print(prob_more_than_2_failures)
## [1] 0.0803014
#7 (Uniform Distribution): An investor is trying to time the market and is monitoring a stock that they believe has an equal chance of reaching a target price between 20 and 60 days. What is the probability that the stock will reach the target price in more than 40 days? If it hasn’t reached the target price by day 40, what is the probability that it will reach it in the next 10 days? What is the expected time for the stock to reach the target price?
#7
a <- 20
b <- 60
prob_more_than_40 <- (b - 40) / (b - a)
print(prob_more_than_40)
## [1] 0.5
prob_40_to_50_given_40 <- (50 - 40) / (60 - 40)
print(prob_40_to_50_given_40)
## [1] 0.5
expected_time <- (a + b) / 2
print(expected_time)
## [1] 40
#8 (Exponential Distribution): A financial model estimates that the lifetime of a successful start-up before it either goes public or fails follows an exponential distribution with an expected value of 8 years. What is the expected time until the start-up either goes public or fails? What is the standard deviation? What is the probability that the start-up will go public or fail after 6 years? Given that the start-up has survived for 6 years, what is the probability that it will go public or fail in the next 2 years?
#8
lambda <- 1 / 8
prob_more_than_6 <- exp(-lambda * 6)
print(prob_more_than_6)
## [1] 0.4723666
prob_next_2_given_6 <- 1 - exp(-lambda * 2)
print(prob_next_2_given_6)
## [1] 0.2211992
#1 (Product Selection): A company produces 5 different types of green pens and 7 different types of red pens. The marketing team needs to create a new promotional package that includes 5 pens. How many different ways can the package be created if it contains fewer than 2 green pens?
# 1
# only red pens
comb1 <- choose(7, 5)
# 1 green pen, 4 red pens
comb2_green <- choose(5, 1)
comb2_red <- choose(7, 4)
comb2 <- comb2_green * comb2_red
# Total number of ways
total_comb <- comb1 + comb2
print(total_comb)
## [1] 196
#2 (Team Formation for a Project): A project committee is being formed within a company that includes 14 senior managers and 13 junior managers. How many ways can a project team of 5 members be formed if at least 4 of the members must be junior managers?
#2
# 4 junior managers, 1 senior manager
form1 <- choose(13, 4) * choose(14, 1)
# 5 junior managers
form2 <- choose(13, 5)
# Total number of ways
total_forms <- form1 + form2
print(total_forms)
## [1] 11297
#3 (Marketing Campaign Outcomes): A marketing campaign involves three stages: first, a customer is sent 5 email offers; second, the customer is targeted with 2 different online ads; and third, the customer is presented with 3 personalized product recommendations. If the email offers, online ads, and product recommendations are selected randomly, how many different possible outcomes are there for the entire campaign?
# 3
email_outcomes <- 5
ad_outcomes <- 2
recommendation_outcomes <- 3
total_outcomes <- email_outcomes * ad_outcomes * recommendation_outcomes
print(total_outcomes)
## [1] 30
#4 (Product Defect Probability): A quality control team draws 3 products from a batch of size N without replacement. What is the probability that at least one of the products drawn is defective if the defect rate is known to be consistent?
# 4
#sample batch of 30
N <- 30
p_defective <- 0.1
sample_size <- 3
num_defective <- N * p_defective
num_non_defective <- N - num_defective
prob_no_defective <- dhyper(3, num_non_defective, num_defective, sample_size)
prob_at_least_one_defective <- 1 - prob_no_defective
cat("Probability of at least one defective product:", prob_at_least_one_defective, "\n")
## Probability of at least one defective product: 0.2795567
#5 (Business Strategy Choices): A business strategist is choosing potential projects to invest in, focusing on 17 high-risk, high-reward projects and 14 low-risk, steady-return projects. #Step 1: How many different combinations of 5 projects can the strategist select? #Step 2: How many different combinations of 5 projects can the strategist select if they want at least one low-risk project?
# 5
total_combinations <- choose(31, 5)
all_high_risk_combinations <- choose(17, 5)
at_least_one_low_risk <- total_combinations - all_high_risk_combinations
print(total_combinations)
## [1] 169911
print(at_least_one_low_risk)
## [1] 163723
#6(Event Scheduling): A business conference needs to schedule 9 different keynote sessions from three different industries: technology, finance, and healthcare. There are 4 potential technology sessions, 104 finance sessions, and 17 healthcare sessions to choose from. How many different schedules can be made? Express your answer in scientific notation rounding to the hundredths place.
#6
tech_sessions <- 4
finance_sessions <- 104
health_sessions <- 17
total_sessions <- 9
total_combinations <- 0
for (tech in 0:tech_sessions) {
for (fin in 0:finance_sessions) {
health <- total_sessions - tech - fin
if (health >= 0 && health <= health_sessions) {
tech_ways <- choose(tech_sessions, tech)
fin_ways <- choose(finance_sessions, fin)
health_ways <- choose(health_sessions, health)
total_combinations <- total_combinations + (tech_ways * fin_ways * health_ways)
}
}
}
cat("Total number of possible schedules:", format(total_combinations, scientific = FALSE, digits = 2), "\n")
## Total number of possible schedules: 15290266473625
#7 (Book Selection for Corporate Training): An HR manager needs to create a reading list for a corporate leadership training program, which includes 13 books in total. The books are categorized into 6 novels, 6 business case studies, 7 leadership theory books, and 5 strategy books.
#Step 1: If the manager wants to include no more than 4 strategy books, how many different reading schedules are possible? Express your answer in scientific notation rounding to the hundredths place. #Step 2: If the manager wants to include all 6 business case studies, how many different reading schedules are possible? Express your answer in scientific notation rounding to the hundredths place.
#7
case1 <- choose(19, 13)
case2 <- choose(5, 1) * choose(19, 12)
case3 <- choose(5, 2) * choose(19, 11)
case4 <- choose(5, 3) * choose(19, 10)
case5 <- choose(5, 4) * choose(19, 9)
total_step1 <- case1 + case2 + case3 + case4 + case5
print(format(total_step1, scientific = FALSE, digits = 3))
## [1] "2420562"
total_step2 <- choose(18, 7)
print(format(total_step2, scientific = FALSE, digits = 3))
## [1] "31824"
#8(Product Arrangement): A retailer is arranging 10 products on a display shelf. There are 5 different electronic gadgets and 5 different accessories. What is the probability that all the gadgets are placed together and all the accessories are placed together on the shelf? Express your answer as a fraction or a decimal number rounded to four decimal places.
#8
total_arrangements <- factorial(10)
block_arrangements <- factorial(2)
gadget_arrangements <- factorial(5)
accessory_arrangements <- factorial(5)
favorable_arrangements <- block_arrangements * gadget_arrangements * accessory_arrangements
probability <- favorable_arrangements / total_arrangements
probability <- round(probability, 4) # rounding to 4 decimal places
print(probability)
## [1] 0.0079
#9 (Expected Value of a Business Deal): A company is evaluating a deal where they either gain $4 for every successful contract or lose $16 for every unsuccessful contract. A “successful” contract is defined as drawing a queen or lower from a standard deck of cards. (Aces are considered the highest card in the deck.)
#9
P_success <- 3 / 13
P_failure <- 10 / 13
gain <- 4
loss <- -16
EV_per_deal <- (P_success * gain) + (P_failure * loss)
print(round(EV_per_deal, 2))
## [1] -11.38
total_expected_value <- EV_per_deal * 833
print(round(total_expected_value, 2))
## [1] -9483.38
#1(Supply Chain Risk Assessment): Let X1,X2,…,Xn #represent the lead times (in days) for the delivery of key components from n = 5 #different suppliers. Each lead time is uniformly distributed across a range of 1 to k=20 #days, reflecting the uncertainty in delivery times. Let Y #denote the minimum delivery time among all suppliers. Understanding the distribution of Y #is crucial for assessing the earliest possible time you can begin production. Determine the distribution of #to better manage your supply chain and minimize downtime.
#1
n <- 5
k <- 20
F_Y <- function(y) {
1 - ((k - y) / (k - 1))^n
}
f_Y <- function(y) {
n / (k - 1) * ((k - y) / (k - 1))^(n - 1)
}
print(F_Y(10))
## [1] 0.9596139
print(f_Y(10))
## [1] 0.02019305
y_vals <- seq(1, k, by = 0.1)
cdf_vals <- sapply(y_vals, F_Y)
pdf_vals <- sapply(y_vals, f_Y)
par(mfrow = c(1, 2))
plot(y_vals, cdf_vals, type = "l", main = "CDF of Y", xlab = "Lead Time (y)", ylab = "CDF")
plot(y_vals, pdf_vals, type = "l", main = "PDF of Y", xlab = "Lead Time (y)", ylab = "PDF")
#2 (Maintenance Planning for Critical Equipment): Your organization owns a critical piece of equipment, such as a high-capacity photocopier (for a law firm) or an MRI machine (for a healthcare provider). The manufacturer estimates the expected lifetime of this equipment to be 8 years, meaning that, on average, you expect one failure every 8 years. It’s essential to understand the likelihood of failure over time to plan for maintenance and replacements.
# 2
lambda <- 1 / 8
CDF <- function(t, lambda) {
1 - exp(-lambda * t)
}
Survival <- function(t, lambda) {
exp(-lambda * t)
}
prob_fail_3_years <- CDF(3, lambda)
prob_no_fail_10_years <- Survival(10, lambda)
print(cat("Probability of failure within 3 years:", round(prob_fail_3_years, 4), "\n"))
## Probability of failure within 3 years: 0.3127
## NULL
print(cat("Probability of no failure by 10 years:", round(prob_no_fail_10_years, 4), "\n"))
## Probability of no failure by 10 years: 0.2865
## NULL
t_values <- seq(0, 20, by = 0.1) # Time from 0 to 20 years
cdf_values <- sapply(t_values, CDF, lambda)
survival_values <- sapply(t_values, Survival, lambda)
par(mfrow = c(1, 2))
plot(t_values, cdf_values, type = "l", col = "blue", main = "CDF of Equipment Failure",
xlab = "Time (years)", ylab = "CDF", lwd = 2)
plot(t_values, survival_values, type = "l", col = "red", main = "Survival Function of Equipment",
xlab = "Time (years)", ylab = "Survival Probability", lwd = 2)
#2a Geometric Model: Calculate the probability that the machine will not fail for the first 6 years. Also, provide the expected value and standard deviation. This model assumes each year the machine either fails or does not, independently of previous years.
#2A
p <- 1 / 8
prob_no_fail_6_years <- (1 - p)^6
expected_value <- 1 / p
std_dev <- sqrt((1 - p) / p^2)
print(cat("Probability of no failure for the first 6 years:", round(prob_no_fail_6_years, 4), "\n"))
## Probability of no failure for the first 6 years: 0.4488
## NULL
print(cat("Expected lifetime (years):", expected_value, "\n"))
## Expected lifetime (years): 8
## NULL
print(cat("Standard deviation of lifetime (years):", round(std_dev, 2), "\n"))
## Standard deviation of lifetime (years): 7.48
## NULL
#2B Exponential Model: Calculate the probability that the machine will not fail for the first 6 years. Provide the expected value and standard deviation, modeling the time to failure as a continuous process.
#2B
lambda <- 1 / 8
prob_no_fail_6_years <- exp(-lambda * 6)
expected_value <- 1 / lambda
std_dev <- 1 / lambda
print(cat("Probability of no failure in the first 6 years:", round(prob_no_fail_6_years, 4), "\n"))
## Probability of no failure in the first 6 years: 0.4724
## NULL
print(cat("Expected lifetime (years):", expected_value, "\n"))
## Expected lifetime (years): 8
## NULL
print(cat("Standard deviation of lifetime (years):", std_dev, "\n"))
## Standard deviation of lifetime (years): 8
## NULL
#2C Binomial Model: Calculate the probability that the machine will not fail during the first 6 years, given that it is expected to fail once every 8 years. Provide the expected value and standard deviation, assuming a fixed number of trials (years) with a constant failure probability each year.
#2C
n <- 6
p <- 0.125
prob_no_fail <- dbinom(0, size = n, prob = p)
expected_value <- n * p
std_dev <- sqrt(n * p * (1 - p))
print(cat("Probability of no failure in the first 6 years:", round(prob_no_fail, 4), "\n"))
## Probability of no failure in the first 6 years: 0.4488
## NULL
print(cat("Expected number of failures in 6 years:", expected_value, "\n"))
## Expected number of failures in 6 years: 0.75
## NULL
print(cat("Standard deviation of failures in 6 years:", round(std_dev, 2), "\n"))
## Standard deviation of failures in 6 years: 0.81
## NULL
#2D Poisson Model: Calculate the probability that the machine will not fail during the first 6 years, modeling the failure events as a Poisson process. Provide the expected value and standard deviation.
#2D
lambda_6_years <- 6 / 8
prob_no_fail <- dpois(0, lambda_6_years)
expected_value <- lambda_6_years
std_dev <- sqrt(lambda_6_years)
print(cat("Probability of no failure in the first 6 years:", round(prob_no_fail, 4), "\n"))
## Probability of no failure in the first 6 years: 0.4724
## NULL
print(cat("Expected number of failures in 6 years:", expected_value, "\n"))
## Expected number of failures in 6 years: 0.75
## NULL
print(cat("Standard deviation of failures in 6 years:", round(std_dev, 2), "\n"))
## Standard deviation of failures in 6 years: 0.87
## NULL
#1 Scenario: You are managing two independent servers in a data center. The time until the next failure for each server follows an exponential distribution with different rates: #Server A has a failure rate of LambdaA = .5 failures per hour. #Server B has a failure rate of LambdaB = ,3 failures per hour. #Question: What is the distribution of the total time until both servers have failed at least once? Use the moment generating function (MGF) to find the distribution of the sum of the times to failure.
#1
lambda_A <- 0.5
lambda_B <- 0.3 #
lambda_total <- lambda_A + lambda_B
k <- 2
t_values <- seq(0, 10, by = 0.1)
pdf_total_time <- dgamma(t_values, shape = k, rate = lambda_total)
plot(t_values, pdf_total_time, type = "l", col = "blue",
main = "PDF of Total Time to Failure for Both Servers",
xlab = "Time (hours)", ylab = "Density")
n_simulations <- 10000
simulated_failures <- rgamma(n_simulations, shape = k, rate = lambda_total)
hist(simulated_failures, breaks = 30, col = "lightblue",
main = "Simulated Distribution of Total Time to Failure",
xlab = "Time (hours)", ylab = "Frequency")
#2Scenario: An investment firm is analyzing the returns of two independent assets, Asset X and Asset Y. The returns on these assets are normally distributed: #Question: Find the distribution of the combined return of the portfolio consisting of these two assets using the moment generating function (MGF).
#2
mu_X <- 0.05
sigma_X <- 0.2
mu_Y <- 0.07
sigma_Y <- 0.3
mu_Z <- mu_X + mu_Y
sigma_Z <- sqrt(sigma_X^2 + sigma_Y^2)
n_simulations <- 10000
combined_returns <- rnorm(n_simulations, mean = mu_Z, sd = sigma_Z)
hist(combined_returns, breaks = 50, col = "lightblue",
main = "Simulated Distribution of Combined Portfolio Returns",
xlab = "Portfolio Return", ylab = "Frequency")
print(cat("Combined Mean Return: ", mu_Z, "\n"))
## Combined Mean Return: 0.12
## NULL
print(cat("Combined Standard Deviation: ", sigma_Z, "\n"))
## Combined Standard Deviation: 0.3605551
## NULL
plot(ecdf(combined_returns), main = "Cumulative Distribution of Combined Portfolio Returns",
xlab = "Portfolio Return", ylab = "CDF")
#3 Scenario: A call center receives calls independently from two different regions. The number of calls received from Region A and Region B in an hour follows a Poisson distribution: #Question: Determine the distribution of the total number of calls received in an hour from both regions using the moment generating function (MGF).
#3
lambda_A <- 3
lambda_B <- 5
n <- 10000
X_A <- rpois(n, lambda_A)
X_B <- rpois(n, lambda_B)
T <- X_A + X_B
hist(T, breaks = 30, probability = TRUE, col = "lightblue", main = "Total Number of Calls (T)", xlab = "Total Calls", border = "black")
curve(dpois(x, lambda = 8), add = TRUE, col = "red", lwd = 2)
## Warning in dpois(x, lambda = 8): non-integer x = 0.210000
## Warning in dpois(x, lambda = 8): non-integer x = 0.420000
## Warning in dpois(x, lambda = 8): non-integer x = 0.630000
## Warning in dpois(x, lambda = 8): non-integer x = 0.840000
## Warning in dpois(x, lambda = 8): non-integer x = 1.050000
## Warning in dpois(x, lambda = 8): non-integer x = 1.260000
## Warning in dpois(x, lambda = 8): non-integer x = 1.470000
## Warning in dpois(x, lambda = 8): non-integer x = 1.680000
## Warning in dpois(x, lambda = 8): non-integer x = 1.890000
## Warning in dpois(x, lambda = 8): non-integer x = 2.100000
## Warning in dpois(x, lambda = 8): non-integer x = 2.310000
## Warning in dpois(x, lambda = 8): non-integer x = 2.520000
## Warning in dpois(x, lambda = 8): non-integer x = 2.730000
## Warning in dpois(x, lambda = 8): non-integer x = 2.940000
## Warning in dpois(x, lambda = 8): non-integer x = 3.150000
## Warning in dpois(x, lambda = 8): non-integer x = 3.360000
## Warning in dpois(x, lambda = 8): non-integer x = 3.570000
## Warning in dpois(x, lambda = 8): non-integer x = 3.780000
## Warning in dpois(x, lambda = 8): non-integer x = 3.990000
## Warning in dpois(x, lambda = 8): non-integer x = 4.200000
## Warning in dpois(x, lambda = 8): non-integer x = 4.410000
## Warning in dpois(x, lambda = 8): non-integer x = 4.620000
## Warning in dpois(x, lambda = 8): non-integer x = 4.830000
## Warning in dpois(x, lambda = 8): non-integer x = 5.040000
## Warning in dpois(x, lambda = 8): non-integer x = 5.250000
## Warning in dpois(x, lambda = 8): non-integer x = 5.460000
## Warning in dpois(x, lambda = 8): non-integer x = 5.670000
## Warning in dpois(x, lambda = 8): non-integer x = 5.880000
## Warning in dpois(x, lambda = 8): non-integer x = 6.090000
## Warning in dpois(x, lambda = 8): non-integer x = 6.300000
## Warning in dpois(x, lambda = 8): non-integer x = 6.510000
## Warning in dpois(x, lambda = 8): non-integer x = 6.720000
## Warning in dpois(x, lambda = 8): non-integer x = 6.930000
## Warning in dpois(x, lambda = 8): non-integer x = 7.140000
## Warning in dpois(x, lambda = 8): non-integer x = 7.350000
## Warning in dpois(x, lambda = 8): non-integer x = 7.560000
## Warning in dpois(x, lambda = 8): non-integer x = 7.770000
## Warning in dpois(x, lambda = 8): non-integer x = 7.980000
## Warning in dpois(x, lambda = 8): non-integer x = 8.190000
## Warning in dpois(x, lambda = 8): non-integer x = 8.400000
## Warning in dpois(x, lambda = 8): non-integer x = 8.610000
## Warning in dpois(x, lambda = 8): non-integer x = 8.820000
## Warning in dpois(x, lambda = 8): non-integer x = 9.030000
## Warning in dpois(x, lambda = 8): non-integer x = 9.240000
## Warning in dpois(x, lambda = 8): non-integer x = 9.450000
## Warning in dpois(x, lambda = 8): non-integer x = 9.660000
## Warning in dpois(x, lambda = 8): non-integer x = 9.870000
## Warning in dpois(x, lambda = 8): non-integer x = 10.080000
## Warning in dpois(x, lambda = 8): non-integer x = 10.290000
## Warning in dpois(x, lambda = 8): non-integer x = 10.500000
## Warning in dpois(x, lambda = 8): non-integer x = 10.710000
## Warning in dpois(x, lambda = 8): non-integer x = 10.920000
## Warning in dpois(x, lambda = 8): non-integer x = 11.130000
## Warning in dpois(x, lambda = 8): non-integer x = 11.340000
## Warning in dpois(x, lambda = 8): non-integer x = 11.550000
## Warning in dpois(x, lambda = 8): non-integer x = 11.760000
## Warning in dpois(x, lambda = 8): non-integer x = 11.970000
## Warning in dpois(x, lambda = 8): non-integer x = 12.180000
## Warning in dpois(x, lambda = 8): non-integer x = 12.390000
## Warning in dpois(x, lambda = 8): non-integer x = 12.600000
## Warning in dpois(x, lambda = 8): non-integer x = 12.810000
## Warning in dpois(x, lambda = 8): non-integer x = 13.020000
## Warning in dpois(x, lambda = 8): non-integer x = 13.230000
## Warning in dpois(x, lambda = 8): non-integer x = 13.440000
## Warning in dpois(x, lambda = 8): non-integer x = 13.650000
## Warning in dpois(x, lambda = 8): non-integer x = 13.860000
## Warning in dpois(x, lambda = 8): non-integer x = 14.070000
## Warning in dpois(x, lambda = 8): non-integer x = 14.280000
## Warning in dpois(x, lambda = 8): non-integer x = 14.490000
## Warning in dpois(x, lambda = 8): non-integer x = 14.700000
## Warning in dpois(x, lambda = 8): non-integer x = 14.910000
## Warning in dpois(x, lambda = 8): non-integer x = 15.120000
## Warning in dpois(x, lambda = 8): non-integer x = 15.330000
## Warning in dpois(x, lambda = 8): non-integer x = 15.540000
## Warning in dpois(x, lambda = 8): non-integer x = 15.750000
## Warning in dpois(x, lambda = 8): non-integer x = 15.960000
## Warning in dpois(x, lambda = 8): non-integer x = 16.170000
## Warning in dpois(x, lambda = 8): non-integer x = 16.380000
## Warning in dpois(x, lambda = 8): non-integer x = 16.590000
## Warning in dpois(x, lambda = 8): non-integer x = 16.800000
## Warning in dpois(x, lambda = 8): non-integer x = 17.010000
## Warning in dpois(x, lambda = 8): non-integer x = 17.220000
## Warning in dpois(x, lambda = 8): non-integer x = 17.430000
## Warning in dpois(x, lambda = 8): non-integer x = 17.640000
## Warning in dpois(x, lambda = 8): non-integer x = 17.850000
## Warning in dpois(x, lambda = 8): non-integer x = 18.060000
## Warning in dpois(x, lambda = 8): non-integer x = 18.270000
## Warning in dpois(x, lambda = 8): non-integer x = 18.480000
## Warning in dpois(x, lambda = 8): non-integer x = 18.690000
## Warning in dpois(x, lambda = 8): non-integer x = 18.900000
## Warning in dpois(x, lambda = 8): non-integer x = 19.110000
## Warning in dpois(x, lambda = 8): non-integer x = 19.320000
## Warning in dpois(x, lambda = 8): non-integer x = 19.530000
## Warning in dpois(x, lambda = 8): non-integer x = 19.740000
## Warning in dpois(x, lambda = 8): non-integer x = 19.950000
## Warning in dpois(x, lambda = 8): non-integer x = 20.160000
## Warning in dpois(x, lambda = 8): non-integer x = 20.370000
## Warning in dpois(x, lambda = 8): non-integer x = 20.580000
## Warning in dpois(x, lambda = 8): non-integer x = 20.790000
print(mean(T))
## [1] 8.0326
print(var(T))
## [1] 8.092346
#1 1. Customer Retention and Churn Analysis
#Scenario: A telecommunications company wants to model the behavior of its customers regarding their likelihood to stay with the company (retention) or leave for a competitor (churn). The company segments its customers into three states:
#State 1: Active customers who are satisfied and likely to stay (Retention state). #State 2: Customers who are considering leaving (At-risk state). #State 3: Customers who have left (Churn state). #The company has historical data showing the following monthly transition probabilities:
#From State 1 (Retention): 80% stay in State 1, 15% move to State 2, and 5% move to State 3. #From State 2 (At-risk): 30% return to State 1, 50% stay in State 2, and 20% move to State 3. #From State 3 (Churn): 100% stay in State 3. #The company wants to analyze the long-term behavior of its customer base.
#Question: (a) Construct the transition matrix for this Markov Chain. (b) If a customer starts as satisfied (State 1), what is the probability that they will eventually churn (move to State 3)? (c) Determine the steady-state distribution of this Markov Chain. What percentage of customers can the company expect to be in each state in the long run?
#1
P <- matrix(c(0.80, 0.15, 0.05,
0.30, 0.50, 0.20,
0.00, 0.00, 1.00),
nrow = 3, byrow = TRUE)
# (b) Probability of eventually reaching State 3 from State 1
A <- matrix(c(0.20, -0.15, -0.30, 0.50), nrow = 2, byrow = TRUE)
b <- c(0.05, 0.20)
p <- solve(A, b)
p1 <- p[1]
p2 <- p[2]
# (c) Steady-state distribution
A_steady <- matrix(c(0.20, -0.15,
0.50, -0.50),
nrow = 2, byrow = TRUE)
b_steady <- c(0.05, 0.20)
steady_state <- solve(A_steady, b_steady)
p1_steady <- steady_state[1]
p2_steady <- steady_state[2]
p3_steady <- 1 - p1_steady - p2_steady
print(p1)
## [1] 1
print(p2)
## [1] 1
print(c(p1_steady, p2_steady, p3_steady))
## [1] -0.2 -0.6 1.8
#2 Inventory Management in a Warehouse #Scenario: A warehouse tracks the inventory levels of a particular product using a Markov Chain model. The inventory levels are categorized into three states:
#State 1: High inventory (More than 100 units in stock). #State 2: Medium inventory (Between 50 and 100 units in stock). #State 3: Low inventory (Less than 50 units in stock). #The warehouse has the following transition probabilities for inventory levels from one month to the next:
#From State 1 (High): 70% stay in State 1, 25% move to State 2, and 5% move to State 3. #From State 2 (Medium): 20% move to State 1, 50% stay in State 2, and 30% move to State 3. #From State 3 (Low): 10% move to State 1, 40% move to State 2, and 50% stay in State 3. #The warehouse management wants to optimize its restocking strategy by understanding the long-term distribution of inventory levels.
#Question: (a) Construct the transition matrix for this Markov Chain. (b) If the warehouse starts with a high inventory level (State 1), what is the probability that it will eventually end up in a low inventory level (State 3)? (c) Determine the steady-state distribution of this Markov Chain. What is the long-term expected proportion of time that the warehouse will spend in each inventory state?
P <- matrix(c(0.70, 0.25, 0.05,
0.20, 0.50, 0.30,
0.10, 0.40, 0.50),
nrow = 3, byrow = TRUE)
P13 <- 0.05
P12 <- 0.25
P23 <- 0.30
P22 <- 0.50
p2 <- P23 / (1 - P22)
p1 <- P13 + P12 * p2
A_steady <- matrix(c(-0.30, 0.20,
0.25, -0.50),
nrow = 2, byrow = TRUE)
b_steady <- c(0.10, 0.40)
steady_state <- solve(A_steady, b_steady)
pi1 <- steady_state[1]
pi2 <- steady_state[2]
pi3 <- 1 - pi1 - pi2
steady_state <- c(pi1, pi2, pi3)
print(cat("Probability of reaching State 3 from State 1 (p1):", p1, "\n"))
## Probability of reaching State 3 from State 1 (p1): 0.2
## NULL
print(cat("Steady-state distribution (pi1, pi2, pi3):", steady_state, "\n"))
## Steady-state distribution (pi1, pi2, pi3): -1.3 -1.45 3.75
## NULL