Bootstrap方法(参数和非参数Bootstrap方法)、Matlab算例

非参数Bootstrap方法

  • 设总体的分布F F F未知,但按放回抽样的方法抽取了一个容量为n n n的样本,称为Bootstrap样本或称为自助样本。独立地取多个Bootstrap样本,利用这些样本信息对总体F F F进行推断,这种方法称为非参数Bootstrap方法,又称为自助法。 这一方法可用于对总体知之甚少地情况
  • 优点:不需要对总体分布有任何假设,而且可以使用于小样本,且能用于各种统计量。

估计量的标准误差的Bootstrap估计

  • 在估计总体位置参数θ \theta θ时,不仅要给出θ \theta θ的估计θ ^ \hat\theta θ^,还需要这一估计的标准误差,常用σ θ ^ = D ( θ ^ ) \sigma_{\hat{\theta}}=\sqrt{D(\hat\theta)}σθ^​=D (θ^)​度量。

步骤

  1. 相继、独立地从已知的容量为n n n的样本中抽出B ( B ≥ 1000 ) B(B\ge1000)B (B ≥1 0 0 0 )个容量为n n n的Bootstrap样本

x 1 ∗ i , x 2 ∗ i , . . . , x n ∗ i , i = 1 , 2 , . . . , B x_1^{i},x_2^{i},…,x_n^{*i},i=1,2,…,B x 1 ∗i ​,x 2 ∗i ​,…,x n ∗i ​,i =1 ,2 ,…,B

  1. 计算

σ ^ θ ^ = 1 B − 1 ∑ i = 1 B ( θ ^ i ∗ − θ ˉ ∗ ) 2 \hat\sigma_{\hat\theta}=\sqrt{\frac{1}{B-1}\sum_{i=1}^B{(\hat\theta_i^}-\bar\theta^)^2}σ^θ^​=B −1 1 ​i =1 ∑B ​(θ^i ∗​−θˉ∗)2 ​
式中: θ ^ i ∗ = θ ^ ( x 1 ∗ i , x 2 ∗ i , . . . , x n ∗ i ) , i = 1 , 2 , . . . , B θ ˉ ∗ = 1 B ∑ i = 1 B θ ^ i ∗ \hat\theta_i^=\hat\theta (x_1^{i},x_2^{i},…,x_n^{i}),i=1,2,…,B \quad \bar\theta^=\frac{1}{B}\sum_{i=1}^B{\hat\theta_i^}θ^i ∗​=θ^(x 1 ∗i ​,x 2 ∗i ​,…,x n ∗i ​),i =1 ,2 ,…,B θˉ∗=B 1 ​∑i =1 B ​θ^i ∗​

估计量的均方误差的Bootstrap估计

例1

  • 有30窝仔猪出生时各窝猪的存活只数为

9 8 10 12 11 12 7 9 11 8 9 7 7 8 9 7 9 9 10 9 9 9 12 10 10 9 13 11 13 9
(1)试求中位数估计M M M的标准误差的Bootstrap估计。
(2)求均方误差M S E = E [ ( M − θ ) 2 ] MSE=E[(M-\theta)^2]M S E =E [(M −θ)2 ]的估计。

data=[9  8  10  12  11  12  7  9  11  8  9  7  7  8  9  7  9  9  10  9  9  9  12  10  10  9  13  11  13  9];
b=bootstrp(1000,@(x)quantile(x,0.5),data);%1000组样本,@(x)quantile(x,0.5)求中位数的函数,data原始数据
b_std=std(b);%计算b的标准差
b_var=mean((b-quantile(data,0.5)).^2);%求均方误差

b1=bootstrp(1000,@mean,data);%平均数
b1_mean=std(b1);

Bootstrap置信区间

  • 设X = ( X 1 , X 2 , . . . . , X n ) X=(X_1,X_2,….,X_n)X =(X 1 ​,X 2 ​,….,X n ​)是来自总体F F F容量为n n n的样本,x = ( x 1 , x 2 , . . . , x n ) x=(x_1,x_2,…,x_n)x =(x 1 ​,x 2 ​,…,x n ​)是一个已知的样本值。F F F中含有位置参数θ \theta θ,θ ^ = θ ^ ( X 1 , X 2 , . . . , X n ) \hat\theta=\hat\theta (X_1,X_2,…,X_n)θ^=θ^(X 1 ​,X 2 ​,…,X n ​)是θ \theta θ的估计量。现在求θ \theta θ的置信水平为1 − α 1-\alpha 1 −α的置信区间。

步骤及原理

  1. 独立从样本x x x中抽出B B B个容量为n n n的Bootstrap样本,对于每个Bootstrap样本求出θ \theta θ的Bootstrap估计:θ ^ 1 ∗ , θ ^ 2 ∗ , . . . , θ ^ B ∗ \hat\theta_1^,\hat\theta_2^,…,\hat\theta_B^*θ^1 ∗​,θ^2 ∗​,…,θ^B ∗​。
  2. 将估计从小到大排序:θ ^ ( 1 ) ∗ , θ ^ ( 2 ) ∗ , . . . , θ ^ ( B ) ∗ \hat\theta_{(1)}^,\hat\theta_{(2)}^,…,\hat\theta_{(B)}^*θ^(1 )∗​,θ^(2 )∗​,…,θ^(B )∗​。
  3. 求出近似分位数θ ^ α / 2 ∗ , θ ^ 1 − α / 2 ∗ \hat\theta_{\alpha/2}^,\hat\theta_{1-\alpha/2}^θ^α/2 ∗​,θ^1 −α/2 ∗​使得
    P { θ ^ α / 2 ∗ < θ ^ ∗ < θ ^ 1 − α / 2 ∗ } = 1 − α P{\hat\theta_{\alpha/2}^
    于是近似的有
    P { θ ^ α / 2 ∗ < θ ^ < θ ^ 1 − α / 2 ∗ } = 1 − α P{\hat\theta_{\alpha/2}^
  4. 记k 1 = [ B × α 2 ] , k 2 = [ B × ( 1 − α 2 ) ] k_1=[B\times \frac{\alpha}{2}],k_2=[B\times(1-\frac{\alpha}{2})]k 1 ​=[B ×2 α​],k 2 ​=[B ×(1 −2 α​)],以θ ^ ( k 1 ) ∗ \hat\theta_{(k_1)}^θ^(k 1 ​)∗​和θ ^ ( k 2 ) ∗ \hat\theta_{(k_2)}^θ^(k 2 ​)∗​分别作为分位数θ ^ α / 2 ∗ , θ ^ 1 − α / 2 ∗ \hat\theta_{\alpha/2}^,\hat\theta_{1-\alpha/2}^θ^α/2 ∗​,θ^1 −α/2 ∗​的估计,得到近似等式
    P { θ ^ ( k 1 ) ∗ < θ ^ < θ ^ ( k 2 ) ∗ } = 1 − α P{\hat\theta_{(k_1)}^
    得到θ \theta θ的置信水平为1 − α 1-\alpha 1 −α的Bootstrap置信区间为( θ ^ ( k 1 ) ∗ , θ ^ ( k 1 ) ∗ ) (\hat\theta_{(k_1)}^
    ,\hat\theta_{(k_1)}^*)(θ^(k 1 ​)∗​,θ^(k 1 ​)∗​),这种方法称为分位数法。

续例1

  • 以样本均值x ˉ \bar x x ˉ作为总体均值μ \mu μ的估计,以标准差s s s作为总体标准差σ \sigma σ的估计,按分位数法求μ , σ \mu,\sigma μ,σ的置信水平为0.90的Bootstrap置信区间。
b=bootci(1000,{@(x)[mean(x),std(x)],data},'alpha',0.1)%bootci得到Bootstrap置信区间

结果:第一列是均值的置信区间,第二列是标准差的置信区间
b =
    9.0667    1.4368
   10.0667    2.0609

参数Bootstrap方法

  • 假设所研究的总体的分布函数F = ( x ; β ) F=(x;\beta)F =(x ;β)的形式已知,但其中高喊未知参数β \beta β。现在已知有一个来自总体的样本X 1 , X 2 , . . . , X n X_1,X_2,…,X_n X 1 ​,X 2 ​,…,X n ​。

步骤

  1. 由该样本得到β \beta β的极大似然估计β ^ \hat\beta β^​。
  2. 在总体分布为F ( x ; β ^ ) F(x;\hat\beta)F (x ;β^​)中产生B ( B ≥ 1000 ) B(B\ge1000)B (B ≥1 0 0 0 )个容量为n n n的样本
    X 1 ∗ , X 2 ∗ , . . . , X n ∗ ∼ F ( x ; β ^ ) X_1^,X_2^,…,X_n^*\sim F(x;\hat\beta)X 1 ∗​,X 2 ∗​,…,X n ∗​∼F (x ;β^​)
  3. 用非参数Bootstrap置信区间的方法得到β \beta β的Bootstrap置信区间。

例2:

  • 已知某电子原件的寿命服从威布尔分布,其分布函数如下
    F ( x ) = { 1 − e − ( x / η ) β x > 0 0 其 他 β > 0 , η > 0 F(x)=\begin{cases} 1-e^{-(x/\eta)^{\beta}}&x>0\ 0&其他 \end{cases}\quad\beta>0,\eta>0 F (x )={1 −e −(x /η)β0 ​x >0 其他​β>0 ,η>0
    已知参数β = 2 \beta=2 β=2。今有样本142.84 97.04 32.46 69.14 85.67 114.43 41.76 163.07 108.22 63.28。
    (1)确定参数η \eta η的最大似然估计。
    (2)对于时刻t 0 = 50 t_0=50 t 0 ​=5 0,求可靠性R ( 50 ) = 1 − F ( 50 ) = e − ( 50 / η ) 2 R(50)=1-F(50)=e^{-(50/\eta)^2}R (5 0 )=1 −F (5 0 )=e −(5 0 /η)2的置信水平为0.95的Bootstrap单侧置信区间。
    解:
    (1)求似然估计是概率论中的基础,不在此详细阐述,结果为η ^ = ∑ i = 1 n x i 2 n = 100.0696 \hat\eta=\sqrt{\frac{\sum_{i=1}^nx_i^2}{n}} =100.0696 η^​=n ∑i =1 n ​x i 2 ​​​=1 0 0 .0 6 9 6。
    (2)对于参数β = 2 , η = η ^ = 100.0696 \beta=2,\eta=\hat\eta=100.0696 β=2 ,η=η^​=1 0 0 .0 6 9 6,产生服从对应韦布尔分布的5000个容量为10的Bootstrap样本。
    对于每个样本计算η \eta η的Bootstrap估计η ^ i ∗ = ∑ j = 1 10 ( x j ∗ i ) 2 10 \hat\eta_i^=\sqrt{\frac{\sum_{j=1}^{10}(x_j^{i})^2}{10}}η^​i ∗​=1 0 ∑j =1 1 0 ​(x j ∗i ​)2 ​​。
    将5000个η i ∗ \eta_i^ηi ∗​自小到大排列,取坐起第250([5000×0.05]=250)位,得η ( 250 ) ∗ = 73.3758 \eta_{(250)}^=73.3758 η(2 5 0 )∗​=7 3 .3 7 5 8。
    所以置信水平位0.95得Bootstrap单侧置信下限为e − ( 50 / η ^ ( 250 ) ∗ ) 2 = 0.6286 e^{-(50/\hat\eta^*_{(250)})^2}=0.6286 e −(5 0 /η^​(2 5 0 )∗​)2 =0 .6 2 8 6。
clc,clear
a=[142.84  97.04  32.46  69.14  85.67  114.43  41.76  163.07  108.22  63.28];
eta=sqrt(mean(a.^2));
beta=2;B=5000;alpha=0.05;
b=wblrnd(eta,beta,[B,10]);%产生shape=(B,10)的韦布尔分布的随机数
etahat=sqrt(mean(b.^2,2));%计算每个样本对应的最大似然估计
seteta=sort(etahat);%把etahat从小到大排序
k=floor(B*alpha);%取整数部分
se=seteta(k);%提取相应位置的估计量
Rt0=exp(-(50/se)^2);

Original: https://blog.csdn.net/weixin_45775970/article/details/124785716
Author: weixin_961876584
Title: Bootstrap方法(参数和非参数Bootstrap方法)、Matlab算例

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/618402/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球