Here is the results and python code. Feel free to reach out to me if you want me to walk you through the process:
import scipy.stats as stats
import pandas as pd
import ace_tools as tools
# Given data
p_defective = 0.023 # Probability of defective bean
p_good = 1 - p_defective # Probability of good bean
cost_manual_defective = 90 # cents per 1000 beans
cost_manual_good = 0 # cents per 1000 beans
# a. Constructing Probability Distribution Table for Manual Sorting Costs
data_manual_sorting = {
"Bean Type": ["Good", "Defective"],
"Probability": [p_good, p_defective],
"Cost (cents per 1000 beans)": [cost_manual_good, cost_manual_defective],
"Expected Cost Contribution": [p_good * cost_manual_good, p_defective * cost_manual_defective],
}
df_manual_sorting = pd.DataFrame(data_manual_sorting)
# Calculate Expected Cost for Manual Sorting
expected_cost_manual = df_manual_sorting["Expected Cost Contribution"].sum()
# Displaying the manual sorting cost table
tools.display_dataframe_to_user(name="Manual Sorting Cost Table", dataframe=df_manual_sorting)
# b. Probability that a good bean is rejected P(Rejected | Good)
threshold = 54
mean_good = 27
std_good = 10
p_rejected_given_good = 1 - stats.norm.cdf(threshold, loc=mean_good, scale=std_good)
# c. Probability that a defective bean is kept P(Kept | Defective)
mean_defective = 58
std_defective = 12
p_kept_given_defective = stats.norm.cdf(threshold, loc=mean_defective, scale=std_defective)
# d. Constructing a probability tree
p_rejected_given_defective = 1 - p_kept_given_defective
p_kept_given_good = 1 - p_rejected_given_good
# Marginal Probabilities
p_rejected = (p_good * p_rejected_given_good) + (p_defective * p_rejected_given_defective)
p_kept = (p_good * p_kept_given_good) + (p_defective * p_kept_given_defective)
# Joint Probabilities
p_good_and_rejected = p_good * p_rejected_given_good
p_defective_and_rejected = p_defective * p_rejected_given_defective
p_good_and_kept = p_good * p_kept_given_good
p_defective_and_kept = p_defective * p_kept_given_defective
# e. Constructing a probability distribution table for machine sorting costs
cost_defective_kept = 90 # cents per 1000 beans
cost_good_rejected = 25 # cents per 1000 beans
rental_cost = 1.05 # cents per 1000 beans
data_machine_sorting = {
"Outcome": ["Good bean kept", "Defective bean rejected", "Defective bean kept", "Good bean rejected"],
"Probability": [p_good_and_kept, p_defective_and_rejected, p_defective_and_kept, p_good_and_rejected],
"Cost (cents per 1000 beans)": [0, 0, cost_defective_kept, cost_good_rejected],
"Expected Cost Contribution": [p_good_and_kept * 0, p_defective_and_rejected * 0, p_defective_and_kept * cost_defective_kept, p_good_and_rejected * cost_good_rejected],
}
df_machine_sorting = pd.DataFrame(data_machine_sorting)
# Calculate Expected Cost for Machine Sorting
expected_cost_machine = df_machine_sorting["Expected Cost Contribution"].sum() + rental_cost
# Displaying the machine sorting cost table
tools.display_dataframe_to_user(name="Machine Sorting Cost Table", dataframe=df_machine_sorting)
# f. Probability that a randomly selected bean is rejected and P(Good | Rejected)
p_good_given_rejected = p_good_and_rejected / p_rejected
# g. Probability that a randomly selected bean is kept and P(Defective | Kept)
p_defective_given_kept = p_defective_and_kept / p_kept
# Displaying results
results = {
"P(Rejected | Good)": p_rejected_given_good,
"P(Kept | Defective)": p_kept_given_defective,
"P(Rejected)": p_rejected,
"P(Good | Rejected)": p_good_given_rejected,
"P(Kept)": p_kept,
"P(Defective | Kept)": p_defective_given_kept,
"Expected Cost (Manual)": expected_cost_manual,
"Expected Cost (Machine)": expected_cost_machine,
}
results