# Lifetimes in hours of a sample of n=40 # Brand A light bulbs xa <- c(64, 70, 76, 92, 150, 152, 193, 228, 335, 348, 355, 406, 423, 450, 452, 461, 592, 658, 665, 689, 704, 744, 874, 964, 985, 1053, 1153, 1223, 1352, 1359, 1386, 1395, 1621, 1845, 2142, 2152, 2451, 2780, 4479, 4992) # Compute sample mean and sample standard deviation xamean <- mean(xa) xamean xastd <- sqrt(var(xa)) xastd # Examine a histogram of the data frame( ) par(fin=c(8,8),cex=1.2) lab <- "Lifetimes (hours) of 40 Brand A Light Bulbs" hist(xa, nclass=8, main=lab) # Estimate the median lifetime xa50 <- quantile(xa, 0.5) xa50 # Obtain 1000 bootstrap replicates of the # estimate of the median from a samples of # size 40 from an exponential distribution ya <- quantile(rexp(40, 1/xamean), 0.50) for(i in 1:999) { ya <- c(ya, quantile(rexp(40, 1/xamean), 0.50) )} # Construct a histogram par(fin=c(8,8),cex=1.2) lab <- "1000 Bootstrap Median Estimates (n=40)" hist(ya, nclass=20, main=lab) # Obtain the average of the bootstrap replicates mean(ya) # Obtain the standard error of the 1000 # bootstrap replicates sqrt(var(ya)) # Obtain a 95% bootstrap confidence interval # for the median of the population quantile(ya, c(0.025, 0.975)) # Lifetimes in hours of a sample of n=40 # Brand B light bulbs xb <- c(4, 23, 44, 47, 61, 63, 70, 114, 120, 123, 192, 201, 245, 250, 258, 261, 275, 281, 307, 347, 392, 400, 412, 461, 484, 572, 605, 717, 916, 1078, 1082, 1173, 1259, 1401, 1426, 1433, 1640, 1773, 1937, 2794) # Compute sample mean and sample standard deviation xbmean <- mean(xb) xbmean xbstd <- sqrt(var(xb)) xbstd # Examine a histogram of the data frame( ) par(fin=c(8,8),cex=1.2) lab <- "Lifetimes (hours) of 40 Brand B Light Bulbs" hist(xb, nclass=8, main=lab) # Estimate the median lifetime xb50 <- quantile(xb, 0.5) xb50 # Obtain 1000 bootstrap replicates of the # estimate of the median from a samples of # size 40 from an exponential distribution yb <- quantile(rexp(40, 1/xbmean), 0.50) for(i in 1:999) { yb <- c(yb, quantile(rexp(40, 1/xbmean), 0.50) )} # Construct a histogram par(fin=c(8,8),cex=1.2) lab <- "1000 Bootstrap Median Estimates (n=40)" hist(yb, nclass=20, main=lab) # Obtain the average of the bootstrap replicates mean(yb) # Obtain the standard error of the 1000 # bootstrap replicates sqrt(var(yb)) # Obtain a 95% bootstrap confidence interval # for the median of the population quantile(yb, c(0.025, 0.975)) # Obtain a confidence interval for the difference # in the medain lifetimes for the two brands # of light bulbs. quantile(ya-yb, c(0.025, 0.975)) # Construct a histogram of the bootstrap differences # in estimates of median lifetimes par(fin=c(8,8),cex=1.2) lab <- "1000 Bootstrap Differences in Medians" hist(ya-yb, nclass=20, main=lab)