The ggplot2
package in R includes a dataset called diamonds
. The dataset can be accessed by loading ggplot2
like this:
library(ggplot2)
I'm using the boot
package to calculate a 95% confidence interval for the mean of the table
variable. The table
variable has 53,940 observations, and therefore when I tried to use 10,000 bootstrap replicates R crashed:
library(boot)
boot_diamonds_10000 <- boot(diamonds,function(data,indices) mean(data[indices,]$table), R=10000)
I then tried using 1000, 100 and 10 bootstrap replicates like as below. The 1000 and 100 replicates are still slow function calls, but 10 replicates is faster:
boot_diamonds_1000 <- boot(diamonds,function(data,indices) mean(data[indices,]$table), R=1000)
boot_diamonds_100 <- boot(diamonds,function(data,indices) mean(data[indices,]$table), R=100)
boot_diamonds_10 <- boot(diamonds,function(data,indices) mean(data[indices,]$table), R=10)
These all give pretty much the same 95% confidence intervals:
quantile(boot_diamonds_1000$t, c(0.025,0.975))
# 2.5% 97.5%
# 57.43890 57.47682
quantile(boot_diamonds_100$t, c(0.025,0.975))
# 2.5% 97.5%
# 57.43638 57.47438
quantile(boot_diamonds_10$t, c(0.025,0.975))
# 2.5% 97.5%
# 57.44636 57.46841
To avoid crashing R or waiting for slow functions calls, is it reasonable to use 10 bootstrap replicates when the sample size (53,940) is so high?