R语言bootstrap分析(boot)

R in Action

Data analysis and graphics with R - SECOND EDITION
ROBERT I. KABACOFF
ISBN: 9781617291388

在这里插入图片描述

//## bootstrap分析数据,package = "boot"
> library(boot)  ## city在boot里面
> city
     u   x
1  138 143
2   93 104
3   61  69
4  179 260
5   48  75
6   37  63
> women
   height weight
1      58    115
2      59    117
3      60    120
4      61    123
5      62    126
> 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.
  • 8
    点赞
  • 63
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值