The Week 3 readings cover Chapter 4 (Probability) and Chapter 5 (Discrete Distributions) from Ken Black’s Business Statistics, supplemented by Allen Downey’s Think Bayes (Chapters 1–2), Teetor (Chapter 8), and Davies (Chapter 10). By the end of this module, you should be able to:
d*,
p*, q*, r* functions) for
Binomial, Poisson, and
Hypergeometric distributions.Probability is a numerical measure (between \(0\) and \(1\), inclusive) of the likelihood or degree of belief that a particular event will occur.
union(A, B).intersect(A, B).choose(N, n) (or
factorial(N) / (factorial(n) * factorial(N - n))).## [1] 4 2 6 5 4 1 5 6 4 2
dice_grid <- expand.grid(die1 = 1:6, die2 = 1:6)
mn_outcomes <- 6 * 6
prob_sum_12 <- mean(rowSums(dice_grid) == 12)
prob_sum_not_12 <- 1 - prob_sum_12
prob_sum_lt6 <- mean(rowSums(dice_grid) < 6)
print(sprintf("mn rule / N^r outcomes (6^2): %d | Two-dice P(sum = 12): %.4f | Complement P(sum != 12): %.4f | P(sum < 6): %.4f",
mn_outcomes, prob_sum_12, prob_sum_not_12, prob_sum_lt6))## [1] "mn rule / N^r outcomes (6^2): 36 | Two-dice P(sum = 12): 0.0278 | Complement P(sum != 12): 0.9722 | P(sum < 6): 0.2778"
## [1] 1 3 5 2 4 6 8 10
## [1] 2 4 6
law_firm_combos <- choose(16, 3)
law_firm_manual <- factorial(16) / (factorial(3) * factorial(16 - 3))
print(sprintf("Small law firm combinations C(16, 3): %d (factorial check: %d)",
law_firm_combos, law_firm_manual))## [1] "Small law firm combinations C(16, 3): 560 (factorial check: 560)"
Four core types of probability appear in contingency (joint probability) tables:
survey_tbl <- matrix(c(42, 18, 28, 12), nrow = 2, byrow = TRUE,
dimnames = list(Status = c("Full_Time", "Part_Time"),
Remote = c("Yes", "No")))
n_total <- sum(survey_tbl)
p_A <- sum(survey_tbl["Full_Time", ]) / n_total
p_B <- sum(survey_tbl[, "Yes"]) / n_total
p_A_and_B <- survey_tbl["Full_Time", "Yes"] / n_total
p_A_or_B <- p_A + p_B - p_A_and_B
p_A_given_B <- p_A_and_B / p_B
p_B_given_A <- p_A_and_B / p_A
p_mult_gen <- p_A * p_B_given_A
p_mult_indep <- p_A * p_B
p_die_1_or_2 <- (1 / 6) + (1 / 6)
print(sprintf("Marginal P(A)=%.2f, P(B)=%.2f | Joint P(A n B)=%.2f | General Union P(A u B)=%.2f",
p_A, p_B, p_A_and_B, p_A_or_B))## [1] "Marginal P(A)=0.60, P(B)=0.70 | Joint P(A n B)=0.42 | General Union P(A u B)=0.88"
print(sprintf("Conditional P(A|B)=%.2f (equals P(A)=%.2f -> Independent) | Gen Mult=%.2f | Spec Mult=%.2f",
p_A_given_B, p_A, p_mult_gen, p_mult_indep))## [1] "Conditional P(A|B)=0.60 (equals P(A)=0.60 -> Independent) | Gen Mult=0.42 | Spec Mult=0.42"
## [1] "Mutually Exclusive Special Addition P(Die=1 or Die=2): 0.3333"
Bayes’ Theorem updates prior probabilities (\(P(H_i)\)) in light of new observed data \(D\) using the likelihood (\(P(D \mid H_i)\)) to produce posterior probabilities (\(P(H_i \mid D)\)):
\[P(H_i \mid D) = \frac{P(H_i) \cdot P(D \mid H_i)}{P(D)} = \frac{P(H_i) \cdot P(D \mid H_i)}{\sum_{j=1}^{k} P(H_j) \cdot P(D \mid H_j)}\]
In the diachronic interpretation, Bayes’ Theorem describes how the probability of a hypothesis \(H\) changes over time as new data \(D\) arrive:
bayes_table <- function(hypos, prior, likelihood) {
unnorm <- prior * likelihood
norm_const <- sum(unnorm)
posterior <- unnorm / norm_const
data.frame(
Hypothesis = hypos,
Prior = prior,
Likelihood = likelihood,
Product = unnorm,
Posterior = round(posterior, 4)
)
}
supplier_tbl <- bayes_table(
hypos = c("Supplier A1", "Supplier A2"),
prior = c(0.60, 0.40),
likelihood = c(0.02, 0.05)
)
print(supplier_tbl)## Hypothesis Prior Likelihood Product Posterior
## 1 Supplier A1 0.6 0.02 0.012 0.375
## 2 Supplier A2 0.4 0.05 0.020 0.625
cookie_tbl <- bayes_table(
hypos = c("Bowl 1", "Bowl 2"),
prior = c(0.5, 0.5),
likelihood = c(0.75, 0.50)
)
print(cookie_tbl)## Hypothesis Prior Likelihood Product Posterior
## 1 Bowl 1 0.5 0.75 0.375 0.6
## 2 Bowl 2 0.5 0.50 0.250 0.4
mm_tbl <- bayes_table(
hypos = c("A: Bag1=1994, Bag2=1996", "B: Bag1=1996, Bag2=1994"),
prior = c(0.5, 0.5),
likelihood = c(0.20 * 0.20, 0.14 * 0.10)
)
print(mm_tbl)## Hypothesis Prior Likelihood Product Posterior
## 1 A: Bag1=1994, Bag2=1996 0.5 0.040 0.020 0.7407
## 2 B: Bag1=1996, Bag2=1994 0.5 0.014 0.007 0.2593
monty_tbl <- bayes_table(
hypos = c("Door A", "Door B", "Door C"),
prior = c(1/3, 1/3, 1/3),
likelihood = c(0.5, 0, 1)
)
print(monty_tbl)## Hypothesis Prior Likelihood Product Posterior
## 1 Door A 0.3333333 0.5 0.1666667 0.3333
## 2 Door B 0.3333333 0.0 0.0000000 0.0000
## 3 Door C 0.3333333 1.0 0.3333333 0.6667
A random variable (\(X\)) is a numerical description of the outcome of a statistical experiment.
For a discrete random variable \(X\) with probability mass function \(P(X = x)\) (where \(0 \le P(x) \le 1\) and \(\sum P(x) = 1\)):
Expected Value (Long-Run Average / Mean, \(\mu\)): \[\mu = E(X) = \sum_{i} x_i \cdot P(x_i)\]
Variance (\(\sigma^2\)): \[\sigma^2 = \text{Var}(X) = \sum_{i} (x_i - \mu)^2 \cdot P(x_i) = \left[ \sum_{i} x_i^2 \cdot P(x_i) \right] - \mu^2\]
Standard Deviation (\(\sigma\)): \[\sigma = \sqrt{\sigma^2}\]
Demonstration (Crises Data, Black Table 5.2): Let \(X \in \{0, 1, 2, 3, 4, 5\}\) denote the number of organizational crises with probabilities \(\{0.37, 0.31, 0.18, 0.09, 0.04, 0.01\}\). The expected value is \(\mu = 1.15\), variance is \(\sigma^2 = 1.4075\), and standard deviation is \(\sigma = 1.1864\).
discrete_summary <- function(outcomes, probs) {
expect_val <- sum(outcomes * probs)
var_val <- sum((outcomes - expect_val)^2 * probs)
var_shortcut <- sum(outcomes^2 * probs) - expect_val^2
data.frame(
Expected_Value = expect_val,
Variance = var_val,
Variance_Shortcut = var_shortcut,
Standard_Deviation = sqrt(var_val)
)
}
no_of_crises <- 0:5
prob_of_crises <- c(0.37, 0.31, 0.18, 0.09, 0.04, 0.01)
print(discrete_summary(outcomes = no_of_crises, probs = prob_of_crises))## Expected_Value Variance Variance_Shortcut Standard_Deviation
## 1 1.15 1.4075 1.4075 1.186381
For probability distributions in R (such as binom,
pois, and hyper), R provides four standardized
function prefixes:
d* (Density / PMF): Returns exact
point probability \(P(X = x)\) (e.g.,
dbinom(), dpois(),
dhyper()).p* (Cumulative Probability): Returns
cumulative probability \(P(X \le q)\)
when lower.tail = TRUE (default), or upper-tail probability
\(P(X > q)\) when
lower.tail = FALSE (e.g., pbinom(),
ppois(), phyper()).q* (Quantile): Returns the quantile
\(x\) corresponding to a given
cumulative probability \(p\) (e.g.,
qbinom(), qpois(),
qhyper()).r* (Random Generation): Generates
random samples from the distribution (e.g., rbinom(),
rpois(), rhyper()).Models the number of successes \(x\) in \(n\) independent trials under four conditions: 1. Fixed number of trials (\(n\)). 2. Each trial has only two mutually exclusive outcomes: Success or Failure. 3. The probability of success (\(p\)) remains constant from trial to trial (\(q = 1 - p\)). 4. Trials are statistically independent (sampling with replacement, or \(n < 0.05N\)).
p_cnn <- pbinom(q = 9, size = 20, prob = 0.60, lower.tail = TRUE)
p_pmf_manual <- choose(20, 10) * (0.60^10) * (0.40^10)
p_pmf_r <- dbinom(x = 10, size = 20, prob = 0.60)
print(sprintf("Demo 5.4 P(X < 10) for n=20, p=0.60: %.4f | PMF P(X=10) manual: %.6f vs dbinom: %.6f",
p_cnn, p_pmf_manual, p_pmf_r))## [1] "Demo 5.4 P(X < 10) for n=20, p=0.60: 0.1275 | PMF P(X=10) manual: 0.117142 vs dbinom: 0.117142"
n_t58 <- 20
p_t58 <- 0.14
mu_t58 <- n_t58 * p_t58
var_t58 <- n_t58 * p_t58 * (1 - p_t58)
sd_t58 <- sqrt(var_t58)
print(sprintf("Table 5.8 (n=20, p=0.14) -> mu = %.2f | sigma^2 = %.4f | sigma = %.4f",
mu_t58, var_t58, sd_t58))## [1] "Table 5.8 (n=20, p=0.14) -> mu = 2.80 | sigma^2 = 2.4080 | sigma = 1.5518"
mug_probs <- c(0.10, 0.20, 0.30, 0.40)
lot_acceptance <- data.frame(
Defect_Rate_p = mug_probs,
Accept_Prob_P_X_le_2 = round(pbinom(q = 2, size = 10, prob = mug_probs), 3),
Expected_Defects = 10 * mug_probs
)
print(lot_acceptance)## Defect_Rate_p Accept_Prob_P_X_le_2 Expected_Defects
## 1 0.1 0.930 1
## 2 0.2 0.678 2
## 3 0.3 0.383 3
## 4 0.4 0.167 4
ggplot(data = data.frame(x = 0:8, prob = dbinom(0:8, size = 8, prob = 0.20)),
aes(x = x, y = prob)) +
geom_bar(stat = "identity", fill = "steelblue") +
labs(title = "Binomial Distribution (n = 8, p = 0.20)",
x = "x Values", y = "Probability") +
scale_x_continuous(breaks = 0:8) +
theme_minimal()Named after French mathematician Siméon Denis Poisson, this distribution models the number of discrete, typically rare occurrences (\(x\)) over a continuous interval of time, area, volume, or distance, assuming occurrences are independent and happen at a constant average rate (\(\lambda\)).
p_ups <- ppois(q = 4, lambda = 2.3, lower.tail = FALSE)
p_ups_x2_manual <- (2.3^2 * exp(-2.3)) / factorial(2)
p_ups_x2_r <- dpois(x = 2, lambda = 2.3)
lambda_5min <- 2.3 * (5 / 1)
print(sprintf("Demo 5.6 UPS P(X > 4): %.4f | P(X=2) manual: %.6f vs dpois: %.6f | 5-min lambda = %.1f",
p_ups, p_ups_x2_manual, p_ups_x2_r, lambda_5min))## [1] "Demo 5.6 UPS P(X > 4): 0.0838 | P(X=2) manual: 0.265185 vs dpois: 0.265185 | 5-min lambda = 11.5"
lambda_t10 <- 1.6
print(sprintf("Table 5.10 (lambda = 1.6) -> mu = %.2f | var = %.2f | sd = %.4f",
lambda_t10, lambda_t10, sqrt(lambda_t10)))## [1] "Table 5.10 (lambda = 1.6) -> mu = 1.60 | var = 1.60 | sd = 1.2649"
exact_binom_rare <- dbinom(x = 3, size = 100, prob = 0.02)
approx_pois_rare <- dpois(x = 3, lambda = 100 * 0.02)
print(sprintf("Poisson Approx to Binomial (n=100, p=0.02, x=3) -> Exact: %.5f | Poisson: %.5f",
exact_binom_rare, approx_pois_rare))## [1] "Poisson Approx to Binomial (n=100, p=0.02, x=3) -> Exact: 0.18228 | Poisson: 0.18045"
ggplot(data = data.frame(x = 0:9, prob = dpois(0:9, lambda = 1.6)),
aes(x = x, y = prob)) +
geom_bar(stat = "identity", fill = "darkorange") +
labs(title = expression("Poisson Distribution (" * lambda * " = 1.6)"),
x = "x Values", y = "Probability") +
scale_x_continuous(breaks = 0:9) +
theme_minimal()Models the number of successes (\(x\)) in a sample of size \(n\) drawn without replacement from a finite population of size \(N\) containing \(A\) total successes (required when sampling without replacement and \(n \ge 0.05N\)).
dhyper(x, m, n, k) and phyper(q, m, n, k):
m \(= A\) (total
population successes), n \(= N -
A\) (total population failures), and k \(= n\) (sample size).p_sv <- phyper(q = 0, m = 12, n = 18 - 12, k = 3, lower.tail = FALSE)
p_sv_comp <- 1 - (choose(12, 0) * choose(6, 3) / choose(18, 3))
mu_sv <- 3 * (12 / 18)
sd_sv <- sqrt(3 * (12 / 18) * (1 - 12 / 18) * ((18 - 3) / (18 - 1)))
p_women <- dhyper(x = 3, m = 8, n = 24 - 8, k = 5)
mu_women <- 5 * (8 / 24)
sd_women <- sqrt(5 * (8 / 24) * (1 - 8 / 24) * ((24 - 5) / (24 - 1)))
print(sprintf("Demo 5.8 Silicon Valley P(X >= 1): %.4f (comb: %.4f) | mu = %.2f, sigma = %.4f",
p_sv, p_sv_comp, mu_sv, sd_sv))## [1] "Demo 5.8 Silicon Valley P(X >= 1): 0.9755 (comb: 0.9755) | mu = 2.00, sigma = 0.7670"
print(sprintf("Table 5.13/5.14 P(X = 3 women): %.4f | mu = %.4f, sigma = %.4f",
p_women, mu_women, sd_women))## [1] "Table 5.13/5.14 P(X = 3 women): 0.1581 | mu = 1.6667, sigma = 0.9581"
| Concept / Distribution | Probability / Metric Formula | Mean (\(\mu\)), Std. Dev. (\(\sigma\)) & R Function |
|---|---|---|
| Combinations | \(\binom{N}{n} = \frac{N!}{n!(N-n)!}\) | choose(N, n) |
| Addition Law | \(P(A \cup B) = P(A) + P(B) - P(A \cap B)\) | — |
| Conditional Probability | \(P(A \mid B) = \frac{P(A \cap B)}{P(B)}\) | — |
| Bayes’ Theorem | \(P(H_i \mid D) = \frac{P(H_i)P(D \mid H_i)}{\sum P(H_j)P(D \mid H_j)}\) | — |
| General Discrete RV | \(\sum P(x_i) = 1\) | \(\mu = \sum x_i P(x_i)\), \(\sigma = \sqrt{\sum (x_i - \mu)^2 P(x_i)}\) |
| Binomial | \(P(x) = \binom{n}{x} p^x (1-p)^{n-x}\) | \(\mu = np\), \(\sigma = \sqrt{np(1-p)}\);
dbinom(), pbinom() |
| Poisson | \(P(x) = \frac{\lambda^x e^{-\lambda}}{x!}\) | \(\mu = \lambda\), \(\sigma = \sqrt{\lambda}\);
dpois(), ppois() |
| Hypergeometric | \(P(x) = \frac{\binom{A}{x}\binom{N-A}{n-x}}{\binom{N}{n}}\) | \(\mu = n\frac{A}{N}\), \(\sigma =
\sqrt{n\frac{A}{N}\left(1-\frac{A}{N}\right)\left(\frac{N-n}{N-1}\right)}\);
dhyper(), phyper() |