For the bias to be between -0.05 and 0.05 from the actual bias, one should look into the following probability
\(P( - 0.05 < \theta < 0.05) = 0.99\)
As in the exercise, it is given that the probability shall be at least 0.99. Then, one would need the estimator's expected value and the estimator's standard deviation. Instead, take that the sample size is large and use the simulated sample standard deviation as an estimate (note here one should use the sample standard deviation of the n generated sample medians) and set the mean to be equal to zero. Then,
\(\begin{aligned}{}P( - 0.05 < \theta < 0.05) = P\left( {\frac{{ - 0.05 - 0}}{{\sqrt {4.25/n} }} < \frac{{\theta - 0}}{{\sqrt {4.25/n} }} < \frac{{0.05 - 0}}{{\sqrt {4.25/n} }}} \right)\\\\ = P\left( {\frac{{ - 0.05 - 0}}{{\sqrt {4.25/n} }} < Z < \frac{{0.05 - 0}}{{\sqrt {4.25/n} }}} \right)\\\\ = 0.99,\end{aligned}\)
or equally, because P(Z<2.576) =0.995 (standard normal is symmetric), it is true that
\(\frac{{0.05}}{{\sqrt {4.25/n} }} = 2.576\)
which leads to
\(n = {\left( {\frac{{4.25}}{{0.04}} \times 2.576} \right)^2} = 39096\)
Instead of using the initial n=25000, use \(n \ge 39096\) it to obtain the desired result. By rerunning the code with a changed value of n, the standard error of the simulation will be close to 0.021<0.05. The Estimate of the bias is close to -1.679.
#The library for built-in bootstrap functions
library(boot)
#read data
Users
Exercise5.txt",
#a column instead of a list
#a column instead of a list
\(Sulfur Dioxide = matrix (unlist (data (1) ))\)
#a way to find the sample median
Original Sample median = median (Sulfur Dioxide)
#the number of bootstrap samples
\(n = 39096\)
\(Xstarimedian = numeric \left( n \right)\)
\(SampleBias = numeric(n)\)
#Generate sample \({X^{ \wedge *}}i\)
and the biases
for \(\left( { i in \left( {1: n} \right)} \right)\){
#generate the bootstrap sample with replacement
\(Xstari = sample(SulfurDioxide,length(SulfurDioxide),replace = T)\)
#median of the bootstrap sample
\(XstariMedian(i) = median(Xstari)\)
#bias
\(SampleBias \left( i \right) = XstariMedian\left( i \right) - OriginalSampleMedian\)
}
#average the differences
Bootstrap Estimate median = mean (Sample Bias)
#the second part
Bootstrap Estimate SD Median = \(sd (SampleBias)/sqrt (n)\)
#the Estimate of the standard deviation of the n sample medians
\(\begin{aligned}{{}{}}{BootstrapEstimateSD = sd \left( {Xstarimedian } \right)}\\{}\end{aligned}\)
\(BootstrapEstimateMean = mean \left( {XstariMedian} \right)\)
\(n = {( qnorm (0.995,0,1)* BootstrapEstimate SD /0.05)^ \wedge }2\)