楼主: ywh19860616
19226 58

抽样问题 [推广有奖]

21
ywh19860616 发表于 2010-10-19 22:38:07
#epoh ,谢谢,和你学到抽样的很多知识
呵呵,那数据是我假设的,经过您的提醒,大致知道怎么选择block-length。
您看我的想法是否正确?
假设我有20个个体,6年的数据。
我按照R中面板数据格式排列为:
id  year        y
1   1991    0.1
1   1992    0.2
1   1993    0.3
1   1994    0.4
1   1995    0.5
1   1996   0.6
...............
20   1991
20
20
20
20
20   1996
那么我这T的6,如果我选择block-length=3,那么K=2。这样的意思就是在每个个体1991-1996年分为2块,
再在每块中抽样,是这样吗?

22
epoh 发表于 2010-10-20 08:19:29
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
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
ywh19860616 + 1 + 1 + 1 谢谢您这些天以来的热心指导,我将认真看下您推荐的文献

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

23
ywh19860616 发表于 2010-10-20 11:58:58
#epoh ,谢谢您一直以来的热心指导,非常感谢

我仔细运行了程序中每一句命令,发现对于抽样过程还是未很好掌握,以下以例子说明:
假如现我有2个地区,6年数据的:
year=c(1991,1992,1993,1994,1995,1996,1991,1992,1993,1994,1995,1996)
x1=c(10,20,30,40,50,60,70,80,90,100,110,120)
x2=c(101,201,301,401,501,601,701,801,901,1001,1101,1201)
x=cbind(year,x1,x2)
#x
> x
      year  x1   x2
[1,] 1991  10  101
[2,] 1992  20  201
[3,] 1993  30  301
[4,] 1994  40  401
[5,] 1995  50  501
[6,] 1996  60  601
[7,] 1991  70  701
[8,] 1992  80  801
[9,] 1993  90  901
[10,] 1994 100 1001
[11,] 1995 110 1101
[12,] 1996 120 1201

#这种数据排列,按照R中对面板数据排列要求排列的。共有N=12个样本,其中n=2(个体),T=6(年份),N=n*T


#以下是您给出的,对应一个个体,6年的数据的抽样过程:
n=6   

p=2
b=1000   #Number of bootstrap samples
boot_bhat=matrix(NA,b, p)
block_length = 3     

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)     
xsim = x[Ind_sim,1:dim(x)[2]]      #Construct the x data
xsim    #
抽出的新样本

#回归
#
将估计出的系数放在 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    #
抽出的新样本
#回归
#
将估计出的系数放在 matrix boot_bhat















24
ywh19860616 发表于 2010-10-21 11:16:21
#epoh,您能帮我看下,上面怎么理解吗

25
epoh 发表于 2010-10-21 11:19:05
哈哈!刚发短信息答覆.
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
ywh19860616 + 1 + 1 + 1 谢谢,您能针对这个例子给我讲解一下吗 year=c(1991,1992,199

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

26
ywh19860616 发表于 2010-10-21 11:24:20
#epoh,谢谢
针对这个数据
year=c(1991,1992,1993,1994,1995,1996,1991,1992,1993,1994,1995,1996)
x1=c(10,20,30,40,50,60,70,80,90,100,110,120)
x2=c(101,201,301,401,501,601,701,801,901,1001,1101,1201)
x=cbind(year,x1,x2)

您给出的程序抽样过程,我不理解
23楼红色部分:
分为1991,1992,1993,1994/////1995,1996,1991,1992/////1993,1994,1995,1996分为3块。这样好像没有按年份分了?因为1995,1996,1991,1992分在了一块,这个怎么理解?

27
epoh 发表于 2010-10-21 11:45:13
哈哈!答非所问
原来你内容有更改
晚点给你答覆.

28
ywh19860616 发表于 2010-10-21 11:47:33
#epoh ,好的,谢谢您
那个问题我也不懂,并非答非所问,谢谢

29
zhangtao 发表于 2010-10-21 16:15:50
非常非常精彩,对R有了更深刻的认识

30
ywh19860616 发表于 2010-10-21 19:31:52
呵呵,都是在向epoh请教

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-25 23:37