# Parametric bootstrapping for a binomial distribution # We have data from a binomial(8,theta) distribution with theta unkwnow. # We find a bootstrap confidence interval for theta #Size of binomial binomSize = 8 #Data x = c(6, 5, 5, 5, 7, 4) n = length(x) # Estimate of theta from the data (This is the MLE) thetahat = mean(x)/binomSize # 1. Draw 100 parametric samles using thetahat as the parameter # 2. Compute thetastar and deltastar (dstar) for each one. Store dstar in a list nboot = 100 dstar.list = rep(0,nboot) for (j in 1:nboot) { xstar = rbinom(n,binomSize,thetahat) thetastar = mean(xstar)/binomSize dstar.list[j] = thetastar - thetahat } # Compute the alpha/2 and 1-alpha/2 quantiles and make the confidence interval alpha = .2 dstar_alpha2 = quantile(dstar.list, alpha/2, names=FALSE) dstar_1minusalpha2 = quantile(dstar.list, 1-alpha/2, names=FALSE) CI = thetahat - c(dstar_1minusalpha2, dstar_alpha2) # Display the results print(CI)