|
b.start是根据文献
Automatic Block-Length Selection for the "Dependent Bootstrap"
很容易的可以由范例"dependent data"的模拟程序,看出结果
##> b.star(x)
## BstarSB BstarCB
##[1,] 50.39272 57.68526
##[2,] 251.62894 288.04323
x1=arima.sim(n =100000, list(ar=c(.5,.0),ma=c(0,0)),sd=1)
x2=arima.sim(n =100000, list(ar=c(.5,.4),ma=c(0,0)),sd=1) #more persistent
至于panel data抽样过程如下:
year=c(1991,1992,1993,1994,1995,1996)
x1=c(10,20,30,40,50,60)
x2=c(100,200,300,400,500,600)
x=cbind(year,x1,x2)
x
# year x1 x2
#[1,] 1991 10 100
#[2,] 1992 20 200
#[3,] 1993 30 300
#[4,] 1994 40 400
#[5,] 1995 50 500
#[6,] 1996 60 600
n=6
p=2
b=1000 #Number of bootstrap samples
boot_bhat=matrix(NA,b, p)
block_length = 3 #请自行更改为block_length=2,block_length=1
#会对抽样过程更清晰理解
num_blocks = n/block_length #n/block_length #2
Indices = seq(1:n) # All of the indices from 1 to n
Indices = matrix(Indices,block_length,num_blocks)
#第一次抽样
randblock =sample(seq(1:num_blocks),num_blocks,replace = TRUE) # Choose which blocks to use
Ind_sim = Indices[,randblock] #Find which data are in each block
Ind_sim = c(Ind_sim)
Ind_sim #[1] 1 2 3 1 2 3
xsim = x[Ind_sim,1:dim(x)[2]] #Construct the x data
xsim #抽出的新样本
# year x1 x2
#[1,] 1991 10 100
#[2,] 1992 20 200
#[3,] 1993 30 300
#[4,] 1991 10 100
#[5,] 1992 20 200
#[6,] 1993 30 300
#回归
#将估计出的系数放在 matrix boot_bhat
#第二次抽样
randblock =sample(seq(1:num_blocks),num_blocks,replace = TRUE) # Choose which blocks to use
Ind_sim = Indices[,randblock] #Find which data are in each block
Ind_sim = c(Ind_sim)
Ind_sim #[1] 4 5 6 1 2 3
xsim = x[Ind_sim,1:dim(x)[2]] #Construct the x data
xsim #抽出的新样本
# year x1 x2
#[1,] 1994 40 400
#[2,] 1995 50 500
#[3,] 1996 60 600
#[4,] 1991 10 100
#[5,] 1992 20 200
#[6,] 1993 30 300
#回归
#将估计出的系数放在 matrix boot_bhat
.......
#如此抽样回归一千次.
最后楼主可以采Jackknife-after-bootstrap method
The jackknife after bootstrap is used to estimate standard errors for
the bootstrap estimate of standard error, and the
influence of each observation on these estimates.
详细请参阅s-plus statman2.pdf page 515/576
|