The Week 5 readings cover Chapter 8 (Statistical Inference: Estimation for Single Populations) from Ken Black’s Business Statistics alongside Chapter 6 (Section 6.5: Modern Advances and Insights) from Rand Wilcox’s Basic Statistics, as well as R implementations from Davies (Chapter 17) and Stowell (Chapters 5–6). By the end of this module, you should be able to:
prop.test(), and
Wilcox’s recommended Agresti-Coull adjustment) and for a
population variance (\(\sigma^2\)) and standard deviation (\(\sigma\)) (\(\chi^2\)-interval).Statistical estimation uses sample statistics to infer unknown population parameters. A single number computed from a sample (such as \(\bar{x}\), \(\hat{p}\), or \(s^2\)) is a point estimate, whereas a range of plausible values around that statistic is an interval estimate (confidence interval). Every symmetric confidence interval takes the general form:
\[\text{Point Estimate} \pm (\text{Critical Value}) \times (\text{Standard Error}) = \text{Point Estimate} \pm \text{Margin of Error } (E)\]
Because R functions such as t.test() and
prop.test() are designed to accept raw sample vectors or
success counts, summary-level textbook problems (given \(\bar{x}\), \(s\), or \(\hat{p}\)) are implemented directly from
the analytical formulas using R’s quantile functions
(qnorm(), qt(), qchisq()).
Valid when the population is normally distributed or when the sample size is large (\(n \ge 30\)) via the Central Limit Theorem:
\[\bar{x} \pm z_{\alpha/2} \left(\frac{\sigma}{\sqrt{n}}\right)\]
When sampling without replacement from a finite population of size \(N\) where the sampling fraction exceeds \(5\%\) (\(n > 0.05N\)), apply the Finite Population Correction (FPC) factor:
\[\bar{x} \pm z_{\alpha/2} \left(\frac{\sigma}{\sqrt{n}}\right)\sqrt{\frac{N - n}{N - 1}}\]
qnorm(1 - alpha / 2).A survey of \(n = 44\) U.S. companies trading with firms in India yields a sample mean of \(\bar{x} = 10.455\) years. Assuming a known population standard deviation of \(\sigma = 7.7\) years, construct a \(90\%\) confidence interval for the population mean duration \(\mu\).
n <- 44
x_bar <- 10.455
pop_sd <- 7.7
alpha <- 1 - 0.90
crit_z <- qnorm(p = 1 - (alpha / 2), mean = 0, sd = 1, lower.tail = TRUE)
se_z <- pop_sd / sqrt(n)
me_z <- crit_z * se_z
ci_z <- c(x_bar - me_z, x_bar + me_z)
print(sprintf("Critical z (90%% CI): %.4f | Standard Error: %.4f | Margin of Error: %.4f",
crit_z, se_z, me_z))## [1] "Critical z (90% CI): 1.6449 | Standard Error: 1.1608 | Margin of Error: 1.9094"
## [1] "90% z-CI for mu: [8.5456, 12.3644]"
N_fpc <- 400
n_fpc <- 63
xbar_fpc <- 211
sd_fpc <- 48
fpc_factor <- sqrt((N_fpc - n_fpc) / (N_fpc - 1))
se_fpc <- (sd_fpc / sqrt(n_fpc)) * fpc_factor
ci_fpc <- xbar_fpc + c(-1, 1) * qnorm(0.975) * se_fpc
print(sprintf("FPC Example (n=%d, N=%d) -> FPC = %.4f | 95%% z-CI: [%.2f, %.2f]",
n_fpc, N_fpc, fpc_factor, ci_fpc[1], ci_fpc[2]))## [1] "FPC Example (n=63, N=400) -> FPC = 0.9190 | 95% z-CI: [200.11, 221.89]"
In most business applications, \(\sigma\) is unknown and must be estimated by the sample standard deviation \(s\). Under normality (or large \(n\)), the standardized quantity \(\frac{\bar{x} - \mu}{s / \sqrt{n}}\) follows Student’s \(t\)-distribution (developed by William S. Gosset) with \(df = n - 1\) degrees of freedom:
\[\bar{x} \pm t_{\alpha/2,\, n-1} \left(\frac{s}{\sqrt{n}}\right)\]
qt(1 - alpha / 2, df = n - 1).qt(1 - alpha, df = n - 1)):
alternative = "less" in t.test()): \(\left(-\infty, \; \bar{x} + t_{\alpha,\,
n-1}\frac{s}{\sqrt{n}}\right]\)alternative = "greater" in t.test()): \(\left[\bar{x} - t_{\alpha,\,
n-1}\frac{s}{\sqrt{n}}, \; +\infty\right)\)z_grid <- seq(-4, 4, length.out = 500)
t_compare <- data.frame(
x = rep(z_grid, 4),
density = c(
dt(z_grid, df = 2),
dt(z_grid, df = 5),
dt(z_grid, df = 15),
dnorm(z_grid, mean = 0, sd = 1)
),
Distribution = factor(
rep(c("t (df = 2)", "t (df = 5)", "t (df = 15)", "Standard Normal Z"), each = length(z_grid)),
levels = c("t (df = 2)", "t (df = 5)", "t (df = 15)", "Standard Normal Z")
)
)
ggplot(t_compare, aes(x = x, y = density, color = Distribution, linetype = Distribution)) +
geom_line(linewidth = 1) +
labs(title = "Student's t-Distribution Converges Toward Standard Normal Z as df Increases",
x = "Standardized Value",
y = "Density") +
theme_minimal()hot_dogs.csv)In Demonstration Problem 8.3 (p. 244), an equipment
rental company samples \(n = 14\)
rental invoices for ditchdiggers (assuming normally distributed rental
durations) and constructs a \(99\%\)
confidence interval using both manual \(t\)-formulas and t.test(). We
then inspect calorie distributions in hot_dogs.csv using
horizontal boxplots and compute two-sided \(95\%\) and one-sided \(99\%\) confidence intervals by hot dog
type.
rental_days <- c(3, 1, 3, 2, 5, 1, 2, 1, 4, 2, 1, 3, 1, 1)
n_rent <- length(rental_days)
xbar_rent <- mean(rental_days)
s_rent <- sd(rental_days)
alpha_rent <- 1 - 0.99
crit_t <- qt(p = 1 - (alpha_rent / 2), df = n_rent - 1, lower.tail = TRUE)
ci_rent_manual <- c(xbar_rent - crit_t * (s_rent / sqrt(n_rent)),
xbar_rent + crit_t * (s_rent / sqrt(n_rent)))
ci_rent_ttest <- t.test(x = rental_days, conf.level = 0.99)
print(sprintf("Demo 8.3 -> n = %d | Mean = %.4f | SD = %.4f | Critical t = %.4f",
n_rent, xbar_rent, s_rent, crit_t))## [1] "Demo 8.3 -> n = 14 | Mean = 2.1429 | SD = 1.2924 | Critical t = 3.0123"
print(sprintf("99%% Manual t-CI: [%.4f, %.4f] | t.test() CI: [%.4f, %.4f]",
ci_rent_manual[1], ci_rent_manual[2],
ci_rent_ttest$conf.int[1], ci_rent_ttest$conf.int[2]))## [1] "99% Manual t-CI: [1.1024, 3.1833] | t.test() CI: [1.1024, 3.1833]"
hotdogs <- read.csv("https://raw.githubusercontent.com/telpirion/CumulativeStudyGuide/refs/heads/main/data/hot_dogs.csv")
boxplot(Calories ~ Type, data = hotdogs, horizontal = TRUE,
col = c("salmon", "tan", "lightblue"),
main = "Hot Dog Calories by Type",
xlab = "Calories per Hot Dog", ylab = "Type")hd_types <- levels(factor(hotdogs$Type))
hd_ci_table <- do.call(rbind, lapply(hd_types, function(tp) {
vals <- subset(hotdogs, Type == tp)$Calories
ci95 <- t.test(vals, conf.level = 0.95)$conf.int
ci99_upper <- t.test(vals, alternative = "less", conf.level = 0.99)$conf.int
ci99_lower <- t.test(vals, alternative = "greater", conf.level = 0.99)$conf.int
data.frame(
Type = tp,
n = length(vals),
Mean = round(mean(vals), 2),
SD = round(sd(vals), 2),
CI95_Lower = round(ci95[1], 2),
CI95_Upper = round(ci95[2], 2),
OneSided99_UpperBound = round(ci99_upper[2], 2),
OneSided99_LowerBound = round(ci99_lower[1], 2)
)
}))
kable(hd_ci_table, caption = "95% Two-Sided and 99% One-Sided Mean Calorie CIs by Hot Dog Type")| Type | n | Mean | SD | CI95_Lower | CI95_Upper | OneSided99_UpperBound | OneSided99_LowerBound |
|---|---|---|---|---|---|---|---|
| Beef | 20 | 156.85 | 22.64 | 146.25 | 167.45 | 169.71 | 143.99 |
| Meat | 17 | 158.71 | 25.24 | 145.73 | 171.68 | 174.52 | 142.89 |
| Poultry | 17 | 118.76 | 22.55 | 107.17 | 130.36 | 132.90 | 104.63 |
When the large-sample normal approximation conditions hold—\(n\hat{p} \ge 5\) and \(n(1 - \hat{p}) \ge 5\), where \(\hat{p} = \frac{x}{n}\) and \(\hat{q} = 1 - \hat{p}\)—the classical Wald \(z\)-interval for a population proportion \(p\) is:
\[\hat{p} \pm z_{\alpha/2} \sqrt{\frac{\hat{p}(1 - \hat{p})}{n}}\]
prop.test(x, n, conf.level = 1 - alpha, correct = FALSE)
(or correct = TRUE with Yates’ continuity correction).In Demonstration Problem 8.4 (p. 249), Coopers & Lybrand surveyed \(n = 210\) chief executives of fast-growing small companies and found \(\hat{p} = 0.51\) had a management succession plan. Below we compute the \(92\%\) Wald CI and compare Wald, Agresti-Coull, and Wilson Score intervals on Wilcox Problem 31 (\(x = 180, n = 1000\)) and a small-sample case (\(x = 2, n = 20\)).
sample_p <- 0.51
q_hat <- 1 - sample_p
n_prop <- 210
alpha_prop <- 1 - 0.92
crit_z_prop <- qnorm(p = 1 - (alpha_prop / 2), mean = 0, sd = 1, lower.tail = TRUE)
se_prop <- sqrt(sample_p * q_hat / n_prop)
ci_prop_92 <- c(sample_p - crit_z_prop * se_prop, sample_p + crit_z_prop * se_prop)
print(sprintf("Demo 8.4 -> Critical z (92%% CI): %.4f | 92%% Wald CI: [%.4f, %.4f]",
crit_z_prop, ci_prop_92[1], ci_prop_92[2]))## [1] "Demo 8.4 -> Critical z (92% CI): 1.7507 | 92% Wald CI: [0.4496, 0.5704]"
compare_prop_ci <- function(x, n, conf_level = 0.95) {
z <- qnorm(1 - (1 - conf_level) / 2)
p_hat <- x / n
wald <- p_hat + c(-1, 1) * z * sqrt(p_hat * (1 - p_hat) / n)
n_tilde <- n + z^2
p_tilde <- (x + z^2 / 2) / n_tilde
agresti_coull <- p_tilde + c(-1, 1) * z * sqrt(p_tilde * (1 - p_tilde) / n_tilde)
wilson_no_cc <- as.numeric(prop.test(x = x, n = n, conf.level = conf_level, correct = FALSE)$conf.int)
wilson_cc <- as.numeric(prop.test(x = x, n = n, conf.level = conf_level, correct = TRUE)$conf.int)
data.frame(
Method = c("Wald (Classical)", "Agresti-Coull", "Wilson Score (prop.test)", "Wilson + Yates CC"),
Lower = round(c(wald[1], agresti_coull[1], wilson_no_cc[1], wilson_cc[1]), 4),
Upper = round(c(wald[2], agresti_coull[2], wilson_no_cc[2], wilson_cc[2]), 4)
)
}
kable(compare_prop_ci(x = 180, n = 1000),
caption = "95% Proportion CIs for Large Sample (x = 180, n = 1000)")| Method | Lower | Upper |
|---|---|---|
| Wald (Classical) | 0.1562 | 0.2038 |
| Agresti-Coull | 0.1574 | 0.2051 |
| Wilson Score (prop.test) | 0.1574 | 0.2050 |
| Wilson + Yates CC | 0.1570 | 0.2055 |
kable(compare_prop_ci(x = 2, n = 20),
caption = "95% Proportion CIs for Small Sample (x = 2, n = 20): Wald Undercovers Near 0")| Method | Lower | Upper |
|---|---|---|
| Wald (Classical) | -0.0315 | 0.2315 |
| Agresti-Coull | 0.0157 | 0.3132 |
| Wilson Score (prop.test) | 0.0279 | 0.3010 |
| Wilson + Yates CC | 0.0175 | 0.3313 |
Assuming the underlying population is strictly normally distributed, the pivot \(\frac{(n - 1)s^2}{\sigma^2}\) follows a Chi-Square (\(\chi^2\)) distribution with \(df = n - 1\) degrees of freedom. Because the \(\chi^2\) distribution is non-negative and right-skewed (asymmetric), the confidence interval is not symmetric around \(s^2\):
\[\frac{(n - 1)s^2}{\chi^2_{\alpha/2,\, n-1}} \le \sigma^2 \le \frac{(n - 1)s^2}{\chi^2_{1 - \alpha/2,\, n-1}}\]
Taking the square root of both bounds gives the \((1 - \alpha)\) confidence interval for the population standard deviation \(\sigma\).
qchisq(1 - alpha / 2, df = n - 1)), placed in the
denominator of the lower CI bound.qchisq(alpha / 2, df = n - 1)),
placed in the denominator of the upper CI bound.In Demonstration Problem 8.6 (p. 253), \(n = 25\) production workers in manufacturing across Greece yield a sample standard deviation of \(s = \$1.12\) (assuming hourly wages are normally distributed). Construct a \(95\%\) confidence interval for \(\sigma^2\) and \(\sigma\), and visualize the two asymmetric \(\chi^2_{24}\) critical cutoffs.
var_conf_int_summary <- function(s, n, conf_level = 0.95) {
df <- n - 1
alpha <- 1 - conf_level
chi_upper <- qchisq(p = 1 - alpha / 2, df = df, lower.tail = TRUE)
chi_lower <- qchisq(p = alpha / 2, df = df, lower.tail = TRUE)
s2 <- s^2
ci_var <- c(df * s2 / chi_upper, df * s2 / chi_lower)
list(s2 = s2, chi_lower = chi_lower, chi_upper = chi_upper,
ci_var = ci_var, ci_sd = sqrt(ci_var))
}
greece_res <- var_conf_int_summary(s = 1.12, n = 25, conf_level = 0.95)
print(sprintf("Sample Variance s^2 = %.4f | chi^2 cutoffs (df = 24): [%.4f, %.4f]",
greece_res$s2, greece_res$chi_lower, greece_res$chi_upper))## [1] "Sample Variance s^2 = 1.2544 | chi^2 cutoffs (df = 24): [12.4012, 39.3641]"
print(sprintf("95%% CI for sigma^2: [%.4f, %.4f] | 95%% CI for sigma: [%.4f, %.4f]",
greece_res$ci_var[1], greece_res$ci_var[2],
greece_res$ci_sd[1], greece_res$ci_sd[2]))## [1] "95% CI for sigma^2: [0.7648, 2.4276] | 95% CI for sigma: [0.8745, 1.5581]"
chi_grid <- seq(4, 52, length.out = 500)
chi_df <- data.frame(x = chi_grid, y = dchisq(chi_grid, df = 24))
ggplot(chi_df, aes(x = x, y = y)) +
geom_area(data = subset(chi_df, x <= greece_res$chi_lower), fill = "firebrick", alpha = 0.4) +
geom_area(data = subset(chi_df, x >= greece_res$chi_upper), fill = "firebrick", alpha = 0.4) +
geom_line(color = "navy", linewidth = 1) +
geom_vline(xintercept = c(greece_res$chi_lower, greece_res$chi_upper), linetype = "dashed") +
labs(title = "Asymmetric Chi-Square Distribution (df = 24) with 95% CI Critical Values",
subtitle = sprintf("Lower cutoff = %.2f (alpha/2 = 0.025) | Upper cutoff = %.2f (1 - alpha/2 = 0.975)",
greece_res$chi_lower, greece_res$chi_upper),
x = expression(chi^2),
y = "Density") +
theme_minimal()Before collecting data, analysts determine the minimum sample size
\(n\) required so that the margin of
error does not exceed a target bound \(E\) at confidence level \(1 - \alpha\) (note: if a problem specifies
total interval width \(W\), then \(E = W / 2\)). Always round \(n\) up to the next integer using
ceiling() so the margin-of-error guarantee is met.
E_mean <- 1
alpha_mean <- 1 - 0.95
sd_est <- (20 - 0) / 4
crit_z_mean <- qnorm(p = 1 - alpha_mean / 2, mean = 0, sd = 1)
n_mean_raw <- (crit_z_mean * sd_est / E_mean)^2
E_prop <- 0.05
alpha_prop_n <- 1 - 0.99
p_worst <- 0.50
crit_z_prop_n <- qnorm(p = 1 - alpha_prop_n / 2, mean = 0, sd = 1)
n_prop_raw <- crit_z_prop_n^2 * p_worst * (1 - p_worst) / E_prop^2
print(sprintf("Demo 8.7 (Mean Sample Size) -> Exact: %.4f | Rounded Up: %d",
n_mean_raw, ceiling(n_mean_raw)))## [1] "Demo 8.7 (Mean Sample Size) -> Exact: 96.0365 | Rounded Up: 97"
print(sprintf("Demo 8.9 (Prop Sample Size) -> Exact: %.4f | Rounded Up: %d",
n_prop_raw, ceiling(n_prop_raw)))## [1] "Demo 8.9 (Prop Sample Size) -> Exact: 663.4897 | Rounded Up: 664"
Rand Wilcox (Basic Statistics, Section 6.5) examines probability coverage—the actual proportion of confidence intervals across repeated studies that successfully trap the true population parameter—and demonstrates when classical Student’s \(t\) intervals break down.
Consider the studentized statistic \(T = \frac{\bar{X} - \mu}{s / \sqrt{n}}\). Under exact normality, \(T\) follows Student’s \(t\)-distribution with \(df = n - 1\). However, simulation studies reveal serious flaws when sampling from non-normal populations:
| Underlying Distribution | Probability Coverage (\(1 - \alpha\)) | Confidence Interval Length | Recommended Strategy |
|---|---|---|---|
| Symmetric, Light-Tailed (Normal) | Accurate (\(\approx 1 - \alpha\)) | Optimal (Shortest) | Standard Student’s \(t\) |
| Symmetric, Heavy-Tailed (Outliers Common) | Conservative (\(\ge 1 - \alpha\)) | Very Wide (Inefficient) | 20% Trimmed Mean or Median |
| Asymmetric (Skewed), Outliers Rare | Poor unless \(n \ge 200\) | Competitive | 20% Trimmed Mean / Bootstrap-\(t\) |
| Asymmetric (Skewed), Outliers Common | Poor unless \(n \ge 300+\) | Wide & Inaccurate | 20% Trimmed Mean + Percentile Bootstrap |
Trimming \(20\%\) from each tail removes extreme outliers while retaining high statistical efficiency under normality. To compute a \(1 - \alpha\) confidence interval for the population \(20\%\) trimmed mean (\(\mu_t\)):
\[\left( \bar{X}_t - c \frac{s_w}{0.6\sqrt{n}}, \quad \bar{X}_t + c \frac{s_w}{0.6\sqrt{n}} \right)\]
qt(1 - alpha / 2, df = h - 1)), with standard error \(SE_t = \frac{s_w}{(1 -
2\gamma)\sqrt{n}}\).(In Wilcox’s self-awareness study, Table 6.3, using the 20% trimmed mean cuts the standard error by a factor of \(2.4\), from \(136.0\) down to \(56.1\)).
Instead of relying on theoretical normal assumptions, bootstrap methods treat the observed sample \(X_1, \dots, X_n\) as an empirical population and draw \(B\) (e.g., \(B = 1,000+\)) bootstrap samples of size \(n\) with replacement:
Below we simulate \(5,000\) samples of size \(n = 40\) from a right-skewed Lognormal\((0, 1)\) population (whose true mean is \(\mu = e^{0.5} \approx 1.6487\)) to verify Wilcox’s finding: even at \(n = 40\), the distribution of \(T = \frac{\bar{X} - \mu}{s / \sqrt{n}}\) is noticeably skewed and its empirical \(0.025\) and \(0.975\) quantiles diverge from \(\pm t_{0.975,\, 39} = \pm 2.0227\).
set.seed(2026)
mu_lnorm <- exp(0.5)
t_sim <- replicate(5000, {
samp <- rlnorm(n = 40, meanlog = 0, sdlog = 1)
(mean(samp) - mu_lnorm) / (sd(samp) / sqrt(40))
})
emp_q <- quantile(t_sim, probs = c(0.025, 0.975))
theo_q <- qt(c(0.025, 0.975), df = 39)
coverage_t <- mean(t_sim >= theo_q[1] & t_sim <= theo_q[2])
print(sprintf("Theoretical 95%% t-cutoffs (df = 39): [%.4f, %.4f]", theo_q[1], theo_q[2]))## [1] "Theoretical 95% t-cutoffs (df = 39): [-2.0227, 2.0227]"
print(sprintf("Empirical 95%% T-quantiles (n = 40 Lognormal): [%.4f, %.4f] | Actual Coverage: %.3f",
emp_q[1], emp_q[2], coverage_t))## [1] "Empirical 95% T-quantiles (n = 40 Lognormal): [-3.5492, 1.4957] | Actual Coverage: 0.890"
t_grid <- seq(-5, 4, length.out = 400)
ggplot(data.frame(T_val = t_sim), aes(x = T_val)) +
geom_histogram(aes(y = after_stat(density)), bins = 45, fill = "steelblue", color = "white", alpha = 0.75) +
geom_line(data = data.frame(x = t_grid, y = dt(t_grid, df = 39)),
aes(x = x, y = y), color = "firebrick", linewidth = 1.1) +
coord_cartesian(xlim = c(-5, 4)) +
labs(title = "Studentized Statistic T Under Lognormal Skewness (n = 40) vs. Theoretical t(39)",
x = "T = (x_bar - mu) / (s / sqrt(n))",
y = "Density") +
theme_minimal()Using Wilcox’s self-awareness dataset (Table 6.3), we inspect the
extreme right outliers (1310 and 2611) with a
horizontal boxplot and compare four \(95\%\) confidence intervals: Classical
Student’s \(t\), 20% Trimmed Mean
(Winsorized SE), Bootstrap-\(t\) for
\(\mu\), and Percentile Bootstrap for
the Median and 20% Trimmed Mean.
self_aware <- c(77, 87, 88, 114, 151, 210, 219, 246, 253, 262,
296, 299, 306, 376, 428, 515, 666, 1310, 2611)
boxplot(self_aware, horizontal = TRUE, col = "tan",
main = "Wilcox Table 6.3: Self-Awareness Data (Severe Right Outliers)",
xlab = "Self-Awareness Score")trim_ci <- function(x, tr = 0.20, alpha = 0.05) {
x_sorted <- sort(x)
n <- length(x)
g <- floor(tr * n)
h <- n - 2 * g
x_bar_t <- mean(x_sorted[(g + 1):(n - g)])
x_win <- x_sorted
x_win[1:g] <- x_sorted[g + 1]
x_win[(n - g + 1):n] <- x_sorted[n - g]
s_w <- sd(x_win)
se_trim <- s_w / ((1 - 2 * tr) * sqrt(n))
c_crit <- qt(1 - alpha / 2, df = h - 1)
c(Lower = x_bar_t - c_crit * se_trim,
Estimate = x_bar_t,
Upper = x_bar_t + c_crit * se_trim,
SE = se_trim)
}
boot_t_ci <- function(x, B = 2000, alpha = 0.05) {
n <- length(x)
x_bar <- mean(x)
se_x <- sd(x) / sqrt(n)
t_star <- replicate(B, {
b <- sample(x, size = n, replace = TRUE)
s_b <- sd(b)
if (s_b == 0) NA else (mean(b) - x_bar) / (s_b / sqrt(n))
})
t_star <- t_star[!is.na(t_star)]
q_star <- quantile(t_star, probs = c(alpha / 2, 1 - alpha / 2))
c(Lower = x_bar - q_star[2] * se_x,
Estimate = x_bar,
Upper = x_bar - q_star[1] * se_x)
}
set.seed(101)
t_res <- t.test(self_aware)$conf.int
trim_res <- trim_ci(self_aware)
bt_res <- boot_t_ci(self_aware, B = 2000)
boot_medians <- replicate(2000, median(sample(self_aware, replace = TRUE)))
pct_med_ci <- quantile(boot_medians, probs = c(0.025, 0.975))
boot_trims <- replicate(2000, mean(sample(self_aware, replace = TRUE), trim = 0.20))
pct_trim_ci <- quantile(boot_trims, probs = c(0.025, 0.975))
print(sprintf("Standard SE = %.1f vs. 20%% Trimmed SE = %.1f (Reduction factor: %.2fx)",
sd(self_aware) / sqrt(length(self_aware)), trim_res["SE"],
(sd(self_aware) / sqrt(length(self_aware))) / trim_res["SE"]))## [1] "Standard SE = 136.4 vs. 20% Trimmed SE = 56.1 (Reduction factor: 2.43x)"
ci_summary <- data.frame(
Method = c("Student's t (Mean)", "Bootstrap-t (Mean)",
"20% Trimmed Mean (Winsorized SE)", "Percentile Bootstrap (20% Trim)",
"Percentile Bootstrap (Median)"),
Estimate = round(c(mean(self_aware), bt_res["Estimate"], trim_res["Estimate"],
mean(self_aware, trim = 0.20), median(self_aware)), 1),
Lower_95 = round(c(t_res[1], bt_res["Lower"], trim_res["Lower"], pct_trim_ci[1], pct_med_ci[1]), 1),
Upper_95 = round(c(t_res[2], bt_res["Upper"], trim_res["Upper"], pct_trim_ci[2], pct_med_ci[2]), 1)
)
ci_summary$Width <- round(ci_summary$Upper_95 - ci_summary$Lower_95, 1)
kable(ci_summary, caption = "Comparison of 95% Confidence Intervals on Skewed Self-Awareness Data")| Method | Estimate | Lower_95 | Upper_95 | Width |
|---|---|---|---|---|
| Student’s t (Mean) | 448.1 | 161.5 | 734.7 | 573.2 |
| Bootstrap-t (Mean) | 448.1 | NA | NA | NA |
| 20% Trimmed Mean (Winsorized SE) | 282.7 | 160.4 | 405.0 | 244.6 |
| Percentile Bootstrap (20% Trim) | 282.7 | 203.0 | 485.5 | 282.5 |
| Percentile Bootstrap (Median) | 262.0 | 210.0 | 376.0 | 166.0 |
| Parameter / Method | Confidence Interval / Formula | Degrees of Freedom / Notes | Primary R Functions |
|---|---|---|---|
| Mean (\(\sigma\) known) | \(\bar{x} \pm z_{\alpha/2} \left(\dfrac{\sigma}{\sqrt{n}}\right)\) | Normal pop. or \(n \ge 30\); multiply SE by \(\sqrt{\frac{N-n}{N-1}}\) if \(n > 0.05N\) | qnorm() |
| Mean (\(\sigma\) unknown) | \(\bar{x} \pm t_{\alpha/2,\, n-1} \left(\dfrac{s}{\sqrt{n}}\right)\) | \(df = n - 1\); sensitive to skewness & heavy tails | qt(), t.test() |
| Proportion (\(p\)) | \(\hat{p} \pm z_{\alpha/2} \sqrt{\dfrac{\hat{p}(1 - \hat{p})}{n}}\) | \(n\hat{p} \ge 5, \; n(1-\hat{p}) \ge 5\) (Agresti-Coull / Wilson preferred) | qnorm(), prop.test() |
| Variance (\(\sigma^2\)) | \(\left[ \dfrac{(n - 1)s^2}{\chi^2_{\alpha/2,\, n-1}}, \; \dfrac{(n - 1)s^2}{\chi^2_{1 - \alpha/2,\, n-1}} \right]\) | \(df = n - 1\); requires strictly normal population | qchisq() |
| Sample Size (\(n\)) | \(n_{\mu} = \left(\dfrac{z_{\alpha/2}\sigma}{E}\right)^2\), \(\quad n_{p} = \dfrac{z_{\alpha/2}^2 p(1-p)}{E^2}\) | Always round up (ceiling()); use \(p = 0.50\) if unknown |
qnorm(), ceiling() |
| 20% Trimmed Mean (Wilcox) | \(\bar{X}_t \pm t_{1 - \alpha/2,\, h-1} \left(\dfrac{s_w}{0.6\sqrt{n}}\right)\) | \(h = n - 2\lfloor 0.2n \rfloor\), \(df = h - 1\); robust to outliers | mean(..., trim = 0.2),
qt() |
| Bootstrap-\(t\) / Percentile | Empirical quantiles of \(T_b^*\) or \(\hat{\theta}_b^*\) | Nonparametric resampling with replacement (\(B \ge 1,000\)) | sample(..., replace = TRUE),
replicate(), quantile() |