Bootstrap本意是拎着靴带让自己跳起来,在统计学中是一种重采样的方法,通常在样本量小的时候,可以从中不断再次抽样。
1. Bootstrap 简单应用
Bootstrap bias偏差 &variance 方差
library(bootstrap)
bslogc<-function(x,B){
n<-length(x)
thetastar<-replicate(B,{
xstar<-sample(x,n,replace = T)
median(xstar)} )
thetastar
}
x <- diabetes$logCpeptide
hist(x, freq = FALSE, main = "Histogram of diabetes data")
median(x)
bscpep<-bslogc(x,1000)
hist(bscpep,freq = FALSE, breaks = 7,main = "Histogram of bootstrap diabetes medians")
var(bscpep)
bias<-mean(bscpep)-median(x)
Bootstrap correlation
samplecorr <- function(data, B) {
n <- nrow(data)
res <- numeric(B)
for(i in 1:B) {
ind <- sample(n, n, replace = TRUE)
bs_data <- data[ind, ]
res[i] <-<