楼主: ywh19860616
19223 58

抽样问题 [推广有奖]

41
epoh 发表于 2010-10-22 18:53:29
楼主会想用Quantile Regression
一定有你的理由
楼主应多试试改变条件
w;taus;lambda
以配合你的数据测试.

panel function
就是将给的数据 x,y,s
依w,taus,lambda
转换为D,y,a
再呼叫rq.fit.sfn(D,y,rhs=a)
估算系数
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
ywh19860616 + 1 + 1 + 1 epoh,是的,这原理我明白 我只是想要block bootstrap产生标准

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

42
ywh19860616 发表于 2010-10-22 19:04:25
#epoh,非常感谢您一直的帮忙
这个我知道
哈哈,我只是看到您操作plm例子时,先转换数据,再bootstrap,效果很好
而作quantile regression 时,确没有先转换,哈哈,效果差了点
不明白其中原因

43
epoh 发表于 2010-10-22 21:44:55
panel data:
  package "Ecdat"
  Produc Us States Production
  a panel of 48 observations from 1970 to 1986
  number of observations : 816
##############
library(SparseM)
library(quantreg)
library(Ecdat)
data("Produc")  
#n=48, T=17, N=816
x1=log(Produc$pcap)
x2=log(Produc$pc)
x3=log(Produc$emp)
x4=Produc$unemp
X=cbind(x1,x2,x3,x4)
y=log(Produc$gsp)
s= rep(1:48,rep(17,48))
X <- as.matrix(X)
n <- length(levels(as.factor(s)))
Z <- as.matrix.csr(model.matrix(~as.factor(s)-1))

####case 1
####use function rq.fit.panel()
w=1
xx<- cbind(as(w,"matrix.diag.csr") %x% X,w %x% Z)
rq.fit.sfn(xx,y,tau=0.5)
>$coef
[1] -0.001856897  0.227955745  0.806905899 -0.003254027  2.348518722
[6]  2.531511125  2.416402785  2.646310826  2.554288408  2.598468250
[11]  2.540988532  2.473361510  2.401692284  2.497764134  2.537963266
[16]  2.425204261  2.482897448  2.510841856  2.553142722  2.703008416
[21]  2.404225489  2.537962766  2.486090983  2.567535469  2.455404207
[26]  2.403301315  2.463135907  2.545757570  2.474922409  2.515871136
[31]  2.443668078  2.580372182  2.643673666  2.605560174  2.384878447
[36]  2.541337214  2.468143678  2.587964518  2.509402455  2.432777812
[41]  2.495204924  2.258353874  2.465798076  2.372996183  2.600392620
[46]  2.471721790  2.457974490  2.519673773  2.590197854  2.472063213
[51]  2.470425047  2.862672642

####case 2
####use function rqss()
tt=as.matrix(xx)
fit=rqss(y~tt-1)
summary(fit)
>
Formula:
y ~ tt - 1
Parametric coefficients:
      Estimate Std. Error t value Pr(>|t|)   
tt1  -0.001857   0.040474  -0.046   0.9634   
tt2   0.227956   0.033949   6.715 3.68e-11 ***
tt3   0.806906   0.041542  19.424  < 2e-16 ***
tt4  -0.003254   0.001402  -2.321   0.0205 *  
tt5   2.348519   0.227838  10.308  < 2e-16 ***
tt6   2.531511   0.226443  11.179  < 2e-16 ***
tt7   2.416403   0.216806  11.145  < 2e-16 ***
tt8   2.646311   0.254619  10.393  < 2e-16 ***
tt9   2.554288   0.222018  11.505  < 2e-16 ***
tt10  2.598468   0.220106  11.806  < 2e-16 ***
tt11  2.540989   0.210428  12.075  < 2e-16 ***
tt12  2.473362   0.234957  10.527  < 2e-16 ***
tt13  2.401692   0.226512  10.603  < 2e-16 ***
tt14  2.497764   0.208589  11.975  < 2e-16 ***
tt15  2.537963   0.241893  10.492  < 2e-16 ***
tt16  2.425204   0.227976  10.638  < 2e-16 ***
tt17  2.482897   0.232136  10.696  < 2e-16 ***
tt18  2.510842   0.231957  10.825  < 2e-16 ***
tt19  2.553143   0.231057  11.050  < 2e-16 ***
tt20  2.703008   0.244407  11.059  < 2e-16 ***
tt21  2.404225   0.201550  11.929  < 2e-16 ***
tt22  2.537963   0.228998  11.083  < 2e-16 ***
tt23  2.486091   0.220021  11.299  < 2e-16 ***
tt24  2.567535   0.239121  10.737  < 2e-16 ***
tt25  2.455404   0.235207  10.439  < 2e-16 ***
tt26  2.403301   0.223782  10.739  < 2e-16 ***
tt27  2.463136   0.226028  10.897  < 2e-16 ***
tt28  2.545758   0.227966  11.167  < 2e-16 ***
tt29  2.474922   0.232918  10.626  < 2e-16 ***
tt30  2.515871   0.211395  11.901  < 2e-16 ***
tt31  2.443668   0.201243  12.143  < 2e-16 ***
tt32  2.580372   0.224698  11.484  < 2e-16 ***
tt33  2.643674   0.222489  11.882  < 2e-16 ***
tt34  2.605560   0.253096  10.295  < 2e-16 ***
tt35  2.384878   0.221027  10.790  < 2e-16 ***
tt36  2.541337   0.225034  11.293  < 2e-16 ***
tt37  2.468144   0.238798  10.336  < 2e-16 ***
tt38  2.587965   0.227848  11.358  < 2e-16 ***
tt39  2.509402   0.221705  11.319  < 2e-16 ***
tt40  2.432778   0.239579  10.154  < 2e-16 ***
tt41  2.495205   0.191899  13.003  < 2e-16 ***
tt42  2.258354   0.211827  10.661  < 2e-16 ***
tt43  2.465798   0.222536  11.080  < 2e-16 ***
tt44  2.372996   0.232450  10.209  < 2e-16 ***
tt45  2.600393   0.251702  10.331  < 2e-16 ***
tt46  2.471722   0.214506  11.523  < 2e-16 ***
tt47  2.457974   0.199837  12.300  < 2e-16 ***
tt48  2.519674   0.226890  11.105  < 2e-16 ***
tt49  2.590198   0.241976  10.704  < 2e-16 ***
tt50  2.472063   0.224931  10.990  < 2e-16 ***
tt51  2.470425   0.229340  10.772  < 2e-16 ***
tt52  2.862673   0.230734  12.407  < 2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

  Quantile Fidelity at tau = 0.5  is      10.8697
  Effective Degrees of Freedom = 52        Sample Size = 816
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
ywh19860616 + 1 + 1 + 1 epoh,太感谢了,我试试效果,应该会好点 您能帮我看看,在这基础上,40楼的

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

44
ywh19860616 发表于 2010-10-22 21:54:25
epoh,谢谢,我感觉这样把时间相关考虑进去会好点
我试试效果,非常感谢

45
zhangtao 发表于 2010-10-23 12:23:56
epoh老师,能不能把您的这个工作做成完整的文件,作为附件
发上来,让我们初学者好好学学?包括数据和各种包的调用。
近期我也在学习bootstrap抽样,书是能基本看懂,就是用软件操作不会。
非常非常感谢!

46
ljq91888 发表于 2010-12-19 11:08:06
同意zhangtao想法,epoh老师上面点评很精彩,是平时课堂上学不到的东西,难得讲义呀。

47
ywh19860616 发表于 2013-1-13 09:36:39
paneldata1.rar (22.02 KB) 本附件包括:
  • paneldata1.csv




一份耕耘,一份收获。

48
epoh 发表于 2013-1-13 14:49:16
ywh19860616 发表于 2013-1-13 09:36
> sfit1

Call: rqpd(formula = y ~ x | s1, panel = panel(taus = c(0.1, 0.25,
    0.5, 0.75, 0.9), tauw = rep(1/5, 5), lambda = 1), data = data1)

taus: [1] 0.10 0.25 0.50 0.75 0.90

tau weights: [1] 0.2 0.2 0.2 0.2 0.2

Coefficients:
                  Value     Std. Error t value   Pr(>|t|)
(Intercept)[0.1]    4.33797   3.95823    1.09594   0.27356
x1[0.1]           -22.89356   8.79802   -2.60212   0.00950
x2[0.1]            -0.00016   0.00012   -1.40792   0.15969
x3[0.1]            -0.17156   0.80597   -0.21286   0.83151
x4[0.1]             0.01788   0.04518    0.39561   0.69254
x5[0.1]            -0.00807   0.05704   -0.14153   0.88750
(Intercept)[0.25]   7.01849   4.55759    1.53996   0.12412
x1[0.25]          -31.63536  10.89619   -2.90334   0.00383
x2[0.25]           -0.00021   0.00015   -1.41683   0.15707
x3[0.25]            0.43922   1.09672    0.40049   0.68895
x4[0.25]           -0.00933   0.05668   -0.16461   0.86931
x5[0.25]           -0.02297   0.06510   -0.35293   0.72427
(Intercept)[0.5]    8.79186   6.65358    1.32137   0.18690
x1[0.5]           -33.13955  12.11413   -2.73561   0.00642
x2[0.5]            -0.00023   0.00021   -1.07795   0.28151
x3[0.5]             0.81523   1.35506    0.60162   0.54766
x4[0.5]            -0.00316   0.08573   -0.03688   0.97060
x5[0.5]            -0.03796   0.09206   -0.41233   0.68025
(Intercept)[0.75]   9.12721   6.84795    1.33284   0.18311
x1[0.75]          -42.40238  11.49644   -3.68831   0.00025
x2[0.75]           -0.00024   0.00019   -1.29779   0.19488
x3[0.75]           -0.35265   1.50398   -0.23448   0.81469
x4[0.75]            0.02920   0.08561    0.34112   0.73314
x5[0.75]           -0.00020   0.09149   -0.00219   0.99825
(Intercept)[0.9]   15.48845   6.30238    2.45756   0.01428
x1[0.9]           -40.19373  10.93352   -3.67619   0.00026
x2[0.9]            -0.00021   0.00015   -1.37395   0.16999
x3[0.9]            -1.11463   1.19046   -0.93630   0.34951
x4[0.9]            -0.01422   0.08619   -0.16502   0.86899
x5[0.9]            -0.05623   0.08618   -0.65251   0.51433

> sfit2

Call: rqpd(formula = y ~ x | s2, panel = panel(taus = c(0.1, 0.25,
    0.5, 0.75, 0.9), tauw = rep(1/5, 5), lambda = 1), data = data1,
    control = list(tmpmax = tmpmax))

taus: [1] 0.10 0.25 0.50 0.75 0.90

tau weights: [1] 0.2 0.2 0.2 0.2 0.2

Coefficients:
                  Value     Std. Error t value   Pr(>|t|)
(Intercept)[0.1]   17.63073   2.17831    8.09376   0.00000
x1[0.1]            -2.66352   2.39167   -1.11366   0.26591
x2[0.1]            -0.00013   0.00007   -1.90210   0.05768
x3[0.1]             0.84435   0.53529    1.57737   0.11528
x4[0.1]            -0.11371   0.02784   -4.08413   0.00005
x5[0.1]            -0.19204   0.04452   -4.31341   0.00002
(Intercept)[0.25]  17.57215   1.42378   12.34191   0.00000
x1[0.25]           -4.21867   2.14175   -1.96973   0.04937
x2[0.25]           -0.00013   0.00006   -2.08870   0.03719
x3[0.25]            0.73098   0.53819    1.35822   0.17495
x4[0.25]           -0.10731   0.02137   -5.02111   0.00000
x5[0.25]           -0.18630   0.02378   -7.83368   0.00000
(Intercept)[0.5]   18.45369   1.69426   10.89188   0.00000
x1[0.5]            -6.88755   2.39927   -2.87068   0.00425
x2[0.5]            -0.00010   0.00006   -1.88500   0.05996
x3[0.5]             0.74744   0.57665    1.29617   0.19546
x4[0.5]            -0.10565   0.02298   -4.59793   0.00001
x5[0.5]            -0.19990   0.02611   -7.65732   0.00000
(Intercept)[0.75]  18.57295   2.21500    8.38506   0.00000
x1[0.75]           -8.83605   4.02327   -2.19624   0.02849
x2[0.75]           -0.00011   0.00007   -1.66999   0.09549
x3[0.75]            0.45603   0.89127    0.51166   0.60909
x4[0.75]           -0.09109   0.02891   -3.15108   0.00171
x5[0.75]           -0.19819   0.03687   -5.37542   0.00000
(Intercept)[0.9]   18.05875   3.30046    5.47159   0.00000
x1[0.9]           -10.09126   7.19705   -1.40214   0.16144
x2[0.9]            -0.00013   0.00009   -1.48869   0.13714
x3[0.9]            -0.25719   1.54033   -0.16697   0.86746
x4[0.9]            -0.05353   0.03915   -1.36737   0.17206
x5[0.9]            -0.18616   0.05278   -3.52723   0.00045
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
ywh19860616 + 5 + 5 + 5 十分感谢epoh老师解答

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

49
ywh19860616 发表于 2013-1-13 21:04:57
epoh 发表于 2013-1-13 14:49
> sfit1

Call: rqpd(formula = y ~ x | s1, panel = panel(taus = c(0.1, 0.25,
谢谢epoh老师的精彩解答。
还有一个问题就是s1和s2的结果不一致,不清楚哪个为正确的。
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
epoh + 5 + 5 + 5 有深度问题

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

一份耕耘,一份收获。

50
epoh 发表于 2013-1-13 21:49:48
epoh 发表于 2013-1-13 14:49
> sfit1

Call: rqpd(formula = y ~ x | s1, panel = panel(taus = c(0.1, 0.25,
应该是s2比较正确吧
看一下自带数据bwd,也是如此
# A CRE model
data(bwd)

cre.form <- dbirwt ~ smoke + dmage + agesq +
   novisit + pretri2 + pretri3 | momid3 | smoke +
   dmage + agesq

明日我拆一下差异点
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
ywh19860616 + 5 + 5 + 5 谢谢您的热心

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

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

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