【问题标题】:R simple BootstrapR 简单的引导程序
【发布时间】:2026-01-11 10:50:01
【问题描述】:

我有一个包含两列的数据框(应用程序)

Customer    Application
1           1
1           0
1           0
1           1
1           1
1           0
1           1
1           0
1           0
1           1
1           1

申请率在哪里

sum(Applications$Application)/sum(Applications$Customer).

我被要求通过运行 1000 个 1000 名客户的样本来引导此应用率,以获得应用率的分布和置信度。我尝试使用boot包如下

f2 <- function(Loan,Customer){sum(Applications$Application)/sum(Applications$Customer)}
bootapp1 <-(boot(Applications, f2, 1000))
bootapp1

ORDINARY NONPARAMETRIC BOOTSTRAP


Call:
boot(data = Bootstrap_Test, statistic = f2, R = 1000)


Bootstrap Statistics :
       original  bias    std. error
t1* 0.003052608       0           0

显然这不是我想要的,因为它没有给出任何偏差或标准错误。

谁能告诉我快速获得所需结果的方法。我想一定有一种非常简单的方法。

【问题讨论】:

    标签: r statistics-bootstrap


    【解决方案1】:

    你只需要调整你的函数,它需要两个参数。在boot 的帮助文件中,在statistic 参数下:

    一个函数,当应用于数据时返回一个包含感兴趣的统计数据的向量。当 sim = "parametric" 时,statistic 的第一个参数必须是数据。对于每个复制,将传递由 ran.gen 返回的模拟数据集。在所有其他情况下,statistic 必须至少有两个参数。传递的第一个参数将始终是原始数据。第二个是定义引导样本的索引、频率或权重向量。

    library(boot)
    x <- structure(list(Customer = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                     1L, 1L), Application = c(1L, 0L, 0L, 1L, 1L, 0L, 1L, 0L, 0L, 
                                                              1L, 1L)), .Names = c("Customer", "Application"), class = "data.frame", row.names = c(NA, 
                                                                                                                                                   -11L))
    f2 <- function(x, index){sum(x[index, "Application"])/sum(x[index, "Customer"])}
    bootapp1 <- boot(data = x, statistic = f2, R = 1000)
    > bootapp1
    
    ORDINARY NONPARAMETRIC BOOTSTRAP
    
    
    Call:
      boot(data = x, statistic = f2, R = 1000)
    
    
    Bootstrap Statistics :
      original       bias    std. error
    t1* 0.5454545 0.0005454545     0.14995
    

    【讨论】: