拔靴法屬於重復抽樣(resampling)方法,與Monte Carlo相比,二者真實的母體不同。它是將已有的觀察值作為母體重復抽樣,
以求取原先資料不足二無法探討的資料特性。
舉個例子,假設x1,x2,...,xn為來自同一分配的觀察值,我們想了解這個分配的中位數。
設一組有Poisson分配抽出的隨機樣本,6 7 7 7 7 8 ... 15 15 17 20,共30個。已知樣本中位數為10。
這里我們分別用MC方法和拔靴法模擬10000次,看中位數的分布。
# Monte Carlo t1 = NULL for (i in 1:10000){ x1=rpois(30,10);y1=median(x1);t1=c(t1,y1) } # Bootstrap t2 = NULL x0 = rpois(30,10) for (i in 1:10000){ x2=sample(x0,30,T);y2=median(x2);t2=c(t2,y2) } par(mfrow=c(1,2)) hist(t1,xlab = "Median",main = "Monte Carlo") hist(t2,xlab = "Median",main = "Bootstrap")
輸出:
之后檢驗二者標准差,發現差別並不大: