R语言 Bootstrapping

R语言 Bootstrapping

Bootstrapping 是推理统计中使用的一种技术,它的工作是反复建立单一数据集的随机样本。Bootstrapping允许计算诸如平均数、中位数、模式、置信区间等抽样的措施。

R – 引导法

以下是R编程语言中的自举过程。

  • 选择自举样本的数量。
  • 选择每个样本的大小。
  • 对于每个样本,如果样本的大小小于所选择的样本,那么从数据集中随机选择一个观察点并将其加入到样本中。
  • 测量样本上的统计量。
  • 测量所有计算出的样本值的平均值。

引导法的方法

有2种自举的方法。

  • 残差再抽样: 这种方法也被称为基于模型的再抽样。这种方法假定模型是正确的,误差是独立的,分布是相同的。在每次重新取样后,变量被重新定义,新的变量被用来测量新的因变量。
  • Bootstrap对: 在这种方法中,因变量和自变量一起作为对进行采样。

Bootstrapping中置信区间的类型

置信区间(CI) 是统计学中对样本数据计算的一种类型的计算值。它产生一个值的范围或一个区间,其中的真实值是肯定的。在引导中,有5种类型的置信区间,如下。

  • 基本型: 它也被称为反向百分位数区间,是使用引导数据分布的量值产生的。在数学上。

R编程中的Bootstrapping

其中,

R编程中的Bootstrapping
R编程中的Bootstrapping
R编程中的Bootstrapping

  • 正态: 正态CI在数学上是这样给出的。

R语言 Bootstrapping

其中

R语言 Bootstrapping 代表数据集 t 的一个值

b 是自举估计的偏差,即。

R语言 Bootstrapping

R语言 Bootstrapping 代表引导分布的R语言 Bootstrapping四分位数

R语言 Bootstrapping代表R语言 Bootstrapping的标准误差

  • Stud: 在studentized CI中,数据被归一化,中心为0,标准差为1,以纠正分布的偏斜。
  • Perc – 百分位数CI类似于基本CI,但公式不同。

R语言 Bootstrapping

  • BCa: 这种方法对偏差和偏度都进行了调整,但当离群值很高时可能不稳定。在数学上。

R语言 Bootstrapping

在R编程中执行bootstrapping的语法如下

语法: boot(data, statistic, R)

参数

  • data 代表数据集
  • statistic 代表要在数据集上执行的统计学函数
  • R 代表样本的数量

要了解boot()函数的更多可选参数,请使用以下命令。

help("boot")
R

例子

# Library required for boot() function
install.packages("boot")
 
# Load the library
library(boot)
 
# Creating a function to pass into boot() function
bootFunc <- function(data, i){
df <- data[i, ]
c(cor(df[, 2], df[, 3]),
    median(df[, 2]),
    mean(df[, 1])
)
}
 
b <- boot(mtcars, bootFunc, R = 100)
 
print(b)
 
# Show all CI values
boot.ci(b, index = 1)
R

输出

ORDINARY NONPARAMETRIC BOOTSTRAP
Call:
boot(data = mtcars, statistic = bootFunc, R = 100)


Bootstrap Statistics :
      original       bias    std. error
t1*  0.9020329 -0.002195625  0.02104139
t2*  6.0000000  0.340000000  0.85540468
t3* 20.0906250 -0.110812500  0.96052824


BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
Based on 100 bootstrap replicates

CALL : 
boot.ci(boot.out = b, index = 1)

Intervals : 
Level      Normal              Basic         
95%   ( 0.8592,  0.9375 )   ( 0.8612,  0.9507 )  

Level     Percentile            BCa          
95%   ( 0.8534,  0.9429 )   ( 0.8279,  0.9280 )  
Calculations and Intervals on Original Scale
Some basic intervals may be unstable
Some percentile intervals may be unstable
Warning : BCa Intervals used Extreme Quantiles
Some BCa intervals may be unstable
Warning messages:
1: In boot.ci(b, index = 1) :
  bootstrap variances needed for studentized intervals
2: In norm.inter(t, adj.alpha) :
  extreme order statistics used as endpoints
R

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

登录

注册