1. 程式人生 > >R語言bootstrap分析(boot)

R語言bootstrap分析(boot)

//## bootstrap分析資料,package = "boot"
> library(boot)
> city
     u   x
1  138 143
2   93 104
3   61  69
4  179 260
5   48  75
6   37  63
7   29  50
8   23  48
9   30 111
10   2  50
> library(boot)
> beta < -function(formula,data,indices){
+     d < -data[indices,]
+     fit < -lm(formula,
data=d) + return(fit$coef) ## 將coef[2]改為coef,會出現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.