zoukankan      html  css  js  c++  java
  • 拔靴法--Bootstrap--R语言实现

      拔靴法属于重复抽样(resampling)方法,与Monte Carlo相比,二者真实的母体不同。它是将已有的观察值作为母体重复抽样,

    以求取原先资料不足二无法探讨的资料特性。

      举个例子,假设x1,x2,...,xn为来自同一分配的观察值,我们想了解这个分配的中位数。

    设一组有Poisson分配抽出的随机样本,6 7 7 7 7 8 ... 15 15 17 20,共30个。已知样本中位数为10。

      这里我们分别用MC方法和拔靴法模拟10000次,看中位数的分布。

    # Monte Carlo
    t1 = NULL
    for (i in 1:10000){
      x1=rpois(30,10);y1=median(x1);t1=c(t1,y1)
    }
    
    # Bootstrap
    t2 = NULL
    x0 = rpois(30,10)
    for (i in 1:10000){
      x2=sample(x0,30,T);y2=median(x2);t2=c(t2,y2)
    }
    
    par(mfrow=c(1,2))
    
    hist(t1,xlab = "Median",main = "Monte Carlo")
    hist(t2,xlab = "Median",main = "Bootstrap")
    

      输出:

      之后检验二者标准差,发现差别并不大:

  • 相关阅读:
    spring-security原理
    win10忘记密码,重置密码
    ELK环境搭建
    Centos8.2安装docker
    pgsql重启
    什么是网站跳出率
    随记
    javascript中apply、call和bind的区别
    Android与Mysql服务器通信
    CentOS 7 最小化安装之后安装Mysql
  • 原文地址:https://www.cnblogs.com/buzhizhitong/p/5951334.html
Copyright © 2011-2022 走看看