# 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 ya <- bootstrap(xa, median, 1000) summary(ya) # Construct a histogram par(fin=c(8,8),cex=1.2) lab <- "1000 Bootstrap Median Estimates (n=40)" hist(ya$replicates, nclass=20, main=lab) # 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 yb <- bootstrap(xb, median, 1000) summary(yb) # Construct a histogram par(fin=c(8,8),cex=1.2) lab <- "1000 Bootstrap Median Estimates (n=40)" hist(yb$replicates, nclass=20, main=lab) # Obtain a confidence interval for the difference # in the medain lifetimes for the two brands # of light bulbs. quantile(ya$replicates-yb$replicates, 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$rep-yb$rep, nclass=20, main=lab)