The Week 4 readings cover Chapter 6 (Continuous Distributions) and Chapter 7 (Sampling and Sampling Distributions) from Ken Black’s Business Statistics, paired with Wilcox Chapter 4 (Section 4.7) on modern insights into non-normality, heavy-tailed distributions, and skewness, as well as R methods from Teetor (Chapter 8). By the end of this module, you should be able to:
punif,
pnorm, qnorm, pexp).sample(),
sample.int(), set.seed(), and grouped
sampling).Unlike discrete random variables that take countable values (e.g., counts of defects or arrivals) and sum individual probabilities, a continuous random variable arises from measuring and can assume any value over an uninterrupted interval. Probabilities are calculated over intervals \([a, b]\) via integration (the area under the probability density function \(f(x)\)), with total area equal to \(1\) and \(P(X = x) = 0\) at any single exact point.
Also known as the rectangular distribution, every sub-interval of equal width within \([a, b]\) has an equal probability of occurring because the density height is constant across the finite interval.
a <- 27
b <- 39
mu_unif <- (a + b) / 2
sd_unif <- (b - a) / sqrt(12)
prob_30_35_manual <- (35 - 30) / (b - a)
prob_30_35_r <- punif(q = 35, min = a, max = b, lower.tail = TRUE) -
punif(q = 30, min = a, max = b, lower.tail = TRUE)
prob_lt_30 <- punif(q = 30, min = a, max = b, lower.tail = TRUE)
prob_table_6_1 <- punif(q = 825, min = 200, max = 1182, lower.tail = TRUE) -
punif(q = 410, min = 200, max = 1182, lower.tail = TRUE)
print(sprintf("Demo 6.1 -> Mean: %.2f | SD: %.4f", mu_unif, sd_unif))## [1] "Demo 6.1 -> Mean: 33.00 | SD: 3.4641"
## [1] "P(30 <= X <= 35) manual: 0.4167 | punif(): 0.4167"
## [1] "P(X < 30): 0.2500 | Table 6.1 P(410 <= X <= 825): 0.4226"
unif_df <- data.frame(x = seq(25, 41, length.out = 400))
unif_df$y <- dunif(unif_df$x, min = a, max = b)
ggplot(unif_df, aes(x = x, y = y)) +
geom_area(data = subset(unif_df, x >= 30 & x <= 35), fill = "steelblue", alpha = 0.45) +
geom_step(color = "navy", linewidth = 1) +
labs(title = "Continuous Uniform Distribution U(27, 39): Shaded P(30 <= X <= 35) = 0.4167",
x = "Assembly Time (seconds)",
y = "Density f(x)") +
theme_minimal()The Normal (Gaussian) Distribution is symmetric around its mean (\(\text{Mean} = \text{Median} = \text{Mode}\)), unimodal, bell-shaped, asymptotic to the horizontal axis (tails extend to \(\pm\infty\) without touching the axis), and completely defined by two parameters: its mean (\(\mu\)) and standard deviation (\(\sigma\)).
In Demonstration Problem 6.3, daily per-capita waste
generation in the U.S. is normally distributed with \(\mu = 4.43\) pounds and \(\sigma = 1.32\) pounds. Unlike printed
\(z\)-tables (which round \(z\) to two decimal places), R computes
exact cumulative probabilities via pnorm() directly from
\(\mu\) and \(\sigma\) and exact inverse percentiles via
qnorm().
mu_waste <- 4.43
sd_waste <- 1.32
z_waste <- (6.00 - mu_waste) / sd_waste
p_gt_6_z <- pnorm(q = z_waste, mean = 0, sd = 1, lower.tail = FALSE)
p_gt_6_direct <- pnorm(q = 6.00, mean = mu_waste, sd = sd_waste, lower.tail = FALSE)
p_36_50 <- pnorm(q = 5.00, mean = mu_waste, sd = sd_waste, lower.tail = TRUE) -
pnorm(q = 3.60, mean = mu_waste, sd = sd_waste, lower.tail = TRUE)
p_53_65 <- pnorm(q = 6.50, mean = mu_waste, sd = sd_waste) -
pnorm(q = 5.30, mean = mu_waste, sd = sd_waste)
p90_waste <- qnorm(p = 0.90, mean = mu_waste, sd = sd_waste, lower.tail = TRUE)
emp_68 <- pnorm(1) - pnorm(-1)
emp_95 <- pnorm(1.96) - pnorm(-1.96)
emp_2sd <- pnorm(2) - pnorm(-2)
emp_997 <- pnorm(3) - pnorm(-3)
print(sprintf("Normal Benchmarks -> 1SD: %.4f | 1.96SD: %.4f | 2SD: %.4f | 3SD: %.4f",
emp_68, emp_95, emp_2sd, emp_997))## [1] "Normal Benchmarks -> 1SD: 0.6827 | 1.96SD: 0.9500 | 2SD: 0.9545 | 3SD: 0.9973"
print(sprintf("Demo 6.3 -> z(6.00) = %.4f | P(X > 6.00) via z: %.4f | direct: %.4f",
z_waste, p_gt_6_z, p_gt_6_direct))## [1] "Demo 6.3 -> z(6.00) = 1.1894 | P(X > 6.00) via z: 0.1171 | direct: 0.1171"
print(sprintf("P(3.60 <= X <= 5.00): %.4f | P(5.30 <= X <= 6.50): %.4f | 90th percentile: %.4f lbs",
p_36_50, p_53_65, p90_waste))## [1] "P(3.60 <= X <= 5.00): 0.4023 | P(5.30 <= X <= 6.50): 0.1965 | 90th percentile: 6.1216 lbs"
x_norm <- seq(mu_waste - 3.5 * sd_waste, mu_waste + 3.5 * sd_waste, length.out = 500)
norm_df <- data.frame(x = x_norm, y = dnorm(x_norm, mean = mu_waste, sd = sd_waste))
ggplot(norm_df, aes(x = x, y = y)) +
geom_area(data = subset(norm_df, x >= 3.60 & x <= 5.00), fill = "steelblue", alpha = 0.45) +
geom_area(data = subset(norm_df, x >= 6.00), fill = "firebrick", alpha = 0.45) +
geom_line(color = "gray20", linewidth = 1) +
geom_vline(xintercept = mu_waste, linetype = "dashed", color = "navy") +
labs(title = "U.S. Daily Waste per Person N(4.43, 1.32^2)",
subtitle = "Blue: P(3.60 <= X <= 5.00) = 0.4023 | Red: P(X > 6.00) = 0.1171",
x = "Waste Generated (lbs/day)",
y = "Density f(x)") +
theme_minimal()salaries.csv)To evaluate whether empirical data plausibly follow a Normal
distribution, combine a histogram (or kernel density
plot) with a Normal Q-Q plot (qqnorm() and
qqline()). Points aligning closely along the diagonal
reference line indicate approximate normality. Using salaries.csv
(\(n = 60\) small-business CEOs), CEO
AGE exhibits an approximately bell-shaped distribution and
linear Q-Q alignment, whereas SAL is right-skewed.
salaries <- read.csv("https://raw.githubusercontent.com/telpirion/CumulativeStudyGuide/refs/heads/main/data/salaries.csv")
print(sprintf("CEO AGE -> n = %d | Mean = %.2f | Median = %.2f | SD = %.2f",
nrow(salaries), mean(salaries$AGE), median(salaries$AGE), sd(salaries$AGE)))## [1] "CEO AGE -> n = 60 | Mean = 51.47 | Median = 50.00 | SD = 8.92"
par(mfrow = c(1, 2))
hist(salaries$AGE, probability = TRUE, col = "lightblue", border = "white",
main = "CEO Age Histogram & Density", xlab = "Age (years)")
lines(density(salaries$AGE), col = "navy", lwd = 2)
qqnorm(salaries$AGE, main = "Normal Q-Q Plot of CEO Age",
xlab = "Normal Quantiles", ylab = "Age Quantiles", pch = 19, col = "steelblue")
qqline(salaries$AGE, distribution = qnorm, probs = c(0.25, 0.75), qtype = 7, col = "firebrick", lwd = 2)When the number of binomial trials \(n\) is large enough that \(n p \ge 5\) and \(n q \ge 5\) (where \(q = 1 - p\), ensuring the interval \(\mu \pm 3\sigma\) lies comfortably inside \([0, n]\)), a discrete Binomial distribution \(X \sim \text{Binomial}(n, p)\) can be approximated by a continuous Normal distribution \(Y \sim N(\mu, \sigma^2)\) with:
\[\mu = n p, \qquad \sigma = \sqrt{n p q}, \qquad z = \frac{x_{\text{corrected}} - n p}{\sqrt{n p q}}\]
dbinom()
against the normal approximation over \([11.5,
12.5]\).pbinom() against the normal approximation \(P(Y \le 26.5)\).n_66 <- 25
p_66 <- 0.40
exact_66 <- dbinom(x = 12, size = n_66, prob = p_66)
approx_66 <- pnorm(q = 12.5, mean = n_66 * p_66, sd = sqrt(n_66 * p_66 * (1 - p_66))) -
pnorm(q = 11.5, mean = n_66 * p_66, sd = sqrt(n_66 * p_66 * (1 - p_66)))
n_67 <- 100
p_67 <- 0.37
exact_67 <- pbinom(q = 26, size = n_67, prob = p_67, lower.tail = TRUE)
z_67 <- (26.5 - n_67 * p_67) / sqrt(n_67 * p_67 * (1 - p_67))
approx_67 <- pnorm(q = z_67, mean = 0, sd = 1)
print(sprintf("Demo 6.6 P(X = 12) -> Exact Binomial: %.6f | Normal Approx: %.6f", exact_66, approx_66))## [1] "Demo 6.6 P(X = 12) -> Exact Binomial: 0.113950 | Normal Approx: 0.116429"
print(sprintf("Demo 6.7 P(X < 27) -> z = %.4f | Exact Binomial: %.6f | Normal Approx: %.6f",
z_67, exact_67, approx_67))## [1] "Demo 6.7 P(X < 27) -> z = -2.1748 | Exact Binomial: 0.013271 | Normal Approx: 0.014823"
mu_66 <- n_66 * p_66
sd_66 <- sqrt(n_66 * p_66 * (1 - p_66))
binom_df <- data.frame(x = 0:n_66, prob = dbinom(0:n_66, size = n_66, prob = p_66))
binom_df$highlight <- ifelse(binom_df$x == 12, "Target (x = 12)", "Other")
ggplot(binom_df, aes(x = x, y = prob, fill = highlight)) +
geom_col(width = 0.85, alpha = 0.8) +
stat_function(fun = dnorm, args = list(mean = mu_66, sd = sd_66),
color = "navy", linewidth = 1.1) +
scale_fill_manual(values = c("Other" = "gray70", "Target (x = 12)" = "firebrick")) +
labs(title = "Normal Approximation to Binomial(n = 25, p = 0.40)",
subtitle = "Continuity correction covers [11.5, 12.5] to approximate P(X = 12)",
x = "Number of Successes (x)",
y = "Probability / Density",
fill = NULL) +
theme_minimal()The Exponential Distribution is the continuous counterpart to the discrete Poisson distribution: whereas Poisson counts the number of random events occurring over an interval, the Exponential distribution models the continuous waiting time or space between independent events occurring at a constant average rate \(\lambda\). It is positively (right) skewed, left-bound at zero (\(x \ge 0\)), and exhibits strictly decreasing density as \(x\) increases.
In Demonstration Problem 6.8, defective parts arrive in a Poisson pattern at an average rate of \(1.38\) defects every \(20\) minutes. Converting to a per-minute rate gives \(\lambda_{\text{min}} = \frac{1.38}{20} = 0.069\) defects/minute, so the mean interarrival time is \(\mu = \frac{20}{1.38} = 14.4928\) minutes. The probability that less than \(15\) minutes elapse between any two defects is \(P(X < 15) = 1 - e^{-0.069(15)} = 0.6448\).
lambda_20 <- 1.38
mu_intervals <- 1 / lambda_20
mean_minutes <- mu_intervals * 20
rate_per_min <- 1 / mean_minutes
prob_lt_15 <- pexp(q = 15, rate = rate_per_min, lower.tail = TRUE)
prob_lt_15_formula <- 1 - exp(-rate_per_min * 15)
prob_ge_15_formula <- exp(-rate_per_min * 15)
print(sprintf("Demo 6.8 -> Mean interval: %.4f min | Rate: %.4f/min | P(X < 15): %.4f (formula: %.4f) | P(X >= 15): %.4f",
mean_minutes, rate_per_min, prob_lt_15, prob_lt_15_formula, prob_ge_15_formula))## [1] "Demo 6.8 -> Mean interval: 14.4928 min | Rate: 0.0690/min | P(X < 15): 0.6448 (formula: 0.6448) | P(X >= 15): 0.3552"
x_exp <- seq(0, 60, length.out = 400)
exp_df <- data.frame(x = x_exp, y = dexp(x_exp, rate = rate_per_min))
ggplot(exp_df, aes(x = x, y = y)) +
geom_area(data = subset(exp_df, x <= 15), fill = "darkorange", alpha = 0.45) +
geom_line(color = "saddlebrown", linewidth = 1) +
labs(title = "Exponential Distribution (Mean = 14.49 min, Rate = 0.069/min)",
subtitle = "Shaded Area: P(X < 15 minutes) = 0.6448",
x = "Time Between Defects (minutes)",
y = "Density f(x)") +
theme_minimal()Rand Wilcox (Basic Statistics, Section 4.7) classifies distributions along two dimensions—symmetry and outlier frequency—warning that classical normal-based inferences break down quickly under subtle, visually undetectable departures from normality.
A mixed (contaminated) normal distribution arises when two normal populations with different variances (or means) are combined.
set.seed(123)
is_outlier_group <- rbinom(100000, size = 1, prob = 0.10)
mixed_sample <- ifelse(is_outlier_group == 1,
rnorm(100000, mean = 0, sd = 10),
rnorm(100000, mean = 0, sd = 1))
mixed_sd <- sd(mixed_sample)
within_1sd <- mean(abs(mixed_sample - mean(mixed_sample)) <= mixed_sd)
print(sprintf("Wilcox Mixed Normal -> Variance: %.2f | P(|X - mu| <= sigma): %.3f (vs 0.683 for Normal)",
var(mixed_sample), within_1sd))## [1] "Wilcox Mixed Normal -> Variance: 10.84 | P(|X - mu| <= sigma): 0.925 (vs 0.683 for Normal)"
wilcox_vec <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 200, 500)
back_transformed <- 10^(mean(log10(wilcox_vec)))
print(sprintf("Original Mean: %.2f | Original Median: %.2f | Back-Transformed Log Mean: %.2f",
mean(wilcox_vec), median(wilcox_vec), back_transformed))## [1] "Original Mean: 62.92 | Original Median: 6.50 | Back-Transformed Log Mean: 9.19"
x_grid <- seq(-5, 5, length.out = 500)
compare_df <- data.frame(
x = rep(x_grid, 2),
density = c(
dnorm(x_grid, 0, 1),
0.9 * dnorm(x_grid, 0, 1) + 0.1 * dnorm(x_grid, 0, 10)
),
Distribution = rep(c("Standard Normal N(0, 1)", "Wilcox Mixed Normal (var = 10.9)"), each = length(x_grid))
)
ggplot(compare_df, aes(x = x, y = density, color = Distribution, linetype = Distribution)) +
geom_line(linewidth = 1.1) +
labs(title = "Bell-Shaped Does Not Guarantee Normality (Wilcox Sec. 4.7)",
x = "Value (x)",
y = "Density") +
theme_minimal()R provides sample() and sample.int() for
random sampling, governed by the 626-element RNG state vector
.Random.seed. Calling set.seed() ensures exact
reproducibility. When sampling rows from a data frame like
iris, pass row indices (1:nrow(iris)) to
sample(), or use dplyr::slice_sample() /
sample_n() (including grouped stratified sampling) versus
base R split() + lapply() +
do.call(rbind, ...).
our_vector <- rnorm(n = 1000, mean = 0, sd = 1)
set.seed(999)
sample_a <- sample(x = our_vector, size = 5, replace = FALSE)
set.seed(999)
sample_b <- sample(x = our_vector, size = 5, replace = FALSE)
print(sprintf("Reproducible sample match: %s", identical(sample_a, sample_b)))## [1] "Reproducible sample match: TRUE"
data(iris)
set.seed(8888)
iris_idx <- sample.int(n = nrow(iris), size = 6, replace = FALSE)
print(iris[iris_idx, c("Species", "Sepal.Length", "Petal.Length")])## Species Sepal.Length Petal.Length
## 119 virginica 7.7 6.9
## 95 versicolor 5.6 4.2
## 60 versicolor 5.2 3.9
## 132 virginica 7.9 6.4
## 64 versicolor 6.1 4.7
## 67 versicolor 5.6 4.5
set.seed(777)
strat_dplyr <- iris %>%
group_by(Species) %>%
slice_sample(n = 3, replace = FALSE)
print(table(strat_dplyr$Species))##
## setosa versicolor virginica
## 3 3 3
set.seed(777)
split_iris <- split(x = iris, f = iris$Species)
iris_samples <- lapply(X = split_iris, function(df_sub) {
df_sub[sample(x = 1:nrow(df_sub), size = 3, replace = FALSE), ]
})
strat_base <- do.call(rbind, iris_samples)
print(table(strat_base$Species))##
## setosa versicolor virginica
## 3 3 3
The sampling distribution of \(\bar{x}\) is the probability distribution of all possible sample means computed from samples of size \(n\).
Below we compute \(P(\bar{x} > 53)\) for a population with \(\mu = 50, \sigma = 12, n = 36\), and simulate \(2{,}000\) sample means drawn from a flat \(\text{Uniform}(0, 1)\) population at \(n = 2\), \(n = 10\), and \(n = 30\) to illustrate how the sampling distribution converges to a Normal bell curve with shrinking standard error \(\sigma / \sqrt{n}\).
mu_pop <- 50
sigma_pop <- 12
n_samp <- 36
se_xbar <- sigma_pop / sqrt(n_samp)
z_xbar <- (53 - mu_pop) / se_xbar
prob_xbar <- pnorm(z_xbar, mean = 0, sd = 1, lower.tail = FALSE)
se_fpc <- (12 / sqrt(50)) * sqrt((500 - 50) / (500 - 1))
print(sprintf("Sampling Dist z = %.2f | P(x_bar > 53): %.4f (SE = %.2f) | FPC SE (N=500, n=50): %.4f",
z_xbar, prob_xbar, se_xbar, se_fpc))## [1] "Sampling Dist z = 1.50 | P(x_bar > 53): 0.0668 (SE = 2.00) | FPC SE (N=500, n=50): 1.6116"
set.seed(2026)
reps <- 2000
sample_sizes <- c(2, 10, 30)
clt_list <- lapply(sample_sizes, function(sz) {
means <- replicate(reps, mean(runif(sz, min = 0, max = 1)))
data.frame(sample_mean = means, n_label = factor(paste("n =", sz), levels = paste("n =", sample_sizes)))
})
clt_df <- do.call(rbind, clt_list)
ggplot(clt_df, aes(x = sample_mean)) +
geom_histogram(aes(y = after_stat(density)), bins = 30, fill = "steelblue", color = "white", alpha = 0.8) +
facet_wrap(~ n_label, scales = "free_y") +
labs(title = "Central Limit Theorem: Means of Uniform(0, 1) Samples",
x = "Sample Mean (x_bar)",
y = "Density") +
theme_minimal()For a sample proportion \(\hat{p} = \frac{x}{n}\), when \(n p \ge 5\) and \(n q \ge 5\) (where \(q = 1 - p\)), the sampling distribution of \(\hat{p}\) is approximately Normal:
p_pop <- 0.60
n_prop <- 300
se_phat <- sqrt(p_pop * (1 - p_pop) / n_prop)
z_phat <- (0.53 - p_pop) / se_phat
prob_phat <- pnorm(z_phat, mean = 0, sd = 1, lower.tail = TRUE)
print(sprintf("Sampling Dist of p_hat (p = 0.60, n = 300) -> SE: %.4f | z = %.4f | P(p_hat <= 0.53): %.4f",
se_phat, z_phat, prob_phat))## [1] "Sampling Dist of p_hat (p = 0.60, n = 300) -> SE: 0.0283 | z = -2.4749 | P(p_hat <= 0.53): 0.0067"
| Distribution / Concept | Density / Statistic Formula | Mean (\(\mu\)) & Std. Dev. (\(\sigma\)) | R Functions & Key Conditions |
|---|---|---|---|
| Continuous Uniform | \(f(x) = \frac{1}{b - a}\) (\(a \le x \le b\)) | \(\mu = \frac{a+b}{2}\), \(\sigma = \frac{b-a}{\sqrt{12}}\) | dunif(), punif(),
qunif(), runif() |
| Normal / Standard Normal | \(z = \frac{x - \mu}{\sigma}\) | \(\mu\), \(\sigma\) (for \(Z\): \(0, 1\)) | dnorm(), pnorm(),
qnorm(), rnorm(); \(68\text{--}95\text{--}99.7\) fails under
heavy tails |
| Binomial Normal Approx. | \(z = \frac{(x \pm 0.5) - np}{\sqrt{npq}}\) | \(\mu = np\), \(\sigma = \sqrt{npq}\) | Valid when \(np \ge 5\) and \(nq \ge 5\); apply \(\pm 0.5\) continuity correction |
| Exponential | \(f(x) = \lambda e^{-\lambda x}\), \(P(X \ge x) = e^{-\lambda x}\) | \(\mu = \frac{1}{\lambda}\), \(\sigma = \frac{1}{\lambda}\) | dexp(), pexp(),
qexp(); right-skewed, left-bound at \(0\) |
| Sampling Dist. of \(\bar{x}\) | \(z = \frac{\bar{x} - \mu}{\sigma / \sqrt{n}}\) | \(\mu_{\bar{x}} = \mu\), \(\sigma_{\bar{x}} = \frac{\sigma}{\sqrt{n}}\) | Normal if pop. is normal or \(n \ge 30\) (CLT); use FPC if \(n > 0.05N\) |
| Sampling Dist. of \(\hat{p}\) | \(z = \frac{\hat{p} - p}{\sqrt{pq/n}}\) | \(\mu_{\hat{p}} = p\), \(\sigma_{\hat{p}} = \sqrt{\frac{pq}{n}}\) | Valid when \(np \ge 5\) and \(nq \ge 5\) |