Data analysis and graphics with R - SECOND EDITION
ROBERT I. KABACOFF
ISBN: 9781617291388
//## bootstrap分析数据,package = "boot">library(boot) ## city在boot里面
> city
u x
11381432931043616941792605487563763> women
height weight
158115259117360120461123562126>library(boot)> beta <-function(formula, data, indices){+ d <- data[indices,]+ fit <-lm(formula, data = d)+return(fit$coef) ## 若将fit$coef改为fit$coef[2],则不会出现stu,原因不详
+}> result <-boot(data = women,
statistic = beta,
R =500,
formula = weight~height
)> boot.ci(result)
BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
Based on 500 bootstrap replicates
CALL :
boot.ci(boot.out = result)
Intervals :
Level Normal Basic Studentized
95%(-102.22,-71.83)(-102.38,-72.16)(-102.92,-72.65)
Level Percentile BCa
95%(-102.88,-72.65)(-102.28,-72.29)
Calculations and Intervals on Original Scale
//## function :The second will be a vector of indices, frequencies or weights which define the bootstrap sample.