楼主: yaolin0522
1726 8

[问答] 有大牛解读一下这几行R代码吗? [推广有奖]

  • 0关注
  • 0粉丝

已卖:565份资源

本科生

98%

还不是VIP/贵宾

-

威望
0
论坛币
3454 个
通用积分
1.2000
学术水平
3 点
热心指数
3 点
信用等级
2 点
经验
2213 点
帖子
56
精华
0
在线时间
136 小时
注册时间
2008-9-3
最后登录
2024-10-27

楼主
yaolin0522 发表于 2018-1-6 21:51:59 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
TAR_CI.R
##  To estimate and test a threshold bi-variate VECM
##
##  written by:
##  
##  Bruce E. Hansen
##  Department of Economics
##  Social Science Building
##  University of Wisconsin
##  Madison, WI 53706-1393
##  behansen@wisc.edu
##  http://www.ssc.wisc.edu/~bhansen/
##  
##  and
##  
##  Byeongseon Seo
##  Department of Economics
##  Soongsil University
##  Seoul, 156-743
##  Korea
##  seo@saint.soongsil.ac.kr
##  
##  
##  This R program estimates a bi-variate VECM, a threshold bi-variate VECM, and
##  tests for the presence of a threshold.  The methods are those described in
##  "Testing for Threshold Cointegration" by Bruce E. Hansen and Byeongseon Seo.
##  
##  The program is set up to replicate the empirical application to the 3-month
##  and 6-month interest rates series.  For your own application, load your data
##  into the matrix "dat", and change the controls listed below
##  
###########################################################################

# Controls #

k <- 1              # Lags in VAR beyond EC
gn <- 300              # number of gridpoints for gamma
bn <- 300                # number of gridpoints for beta      
trim <- .05                # trimming percentage for threshold
boot <- 5000        # number of bootstrap replications
                      # set equal to zero to not do testing  
coint <- 1                # set to 1 to estimate cointegrating vector
                        # set to 0 to fix cointegrating vector at _cvalue
cvalue <- 1                # cointegrating vector, if coint=0
cov <- 1                # covariance matrix estimation method
                      # set to 1 for Eicker-White
                      # set to 0 for conventional homoskedastic estimator
p_ests <- 1       # set to 1 to print estimates, else 0
graph <- 1        # set to 1 to generate graph of nonlinear ECM, else 0
graph_rotate <- 0        # set to 1 to generate rotated graphs
                      # (useful for some print jobs, but ackward for screen viewing)

# Load your own data into matrix "dat" #
# Here we load in the 3-month and 6-month T-Bill series #

dat <- read.table("zeroyld.dat")
dat <- dat[1:nrow(dat),(7:62)]
rs <- rbind(as.matrix(seq(0,18,1)),21,24,30,as.matrix(seq(36,(36+7*12),12)))
short <- 12
long <- 120
short_i <- which.max(rs==short)
long_i <- which.max(rs==long)
dat <- dat[,cbind(long_i,short_i)]   


来自于Hansen and seo(2002),此程序用来做门槛检验,原程序及数据见附件3,具体的是想知道文中红色字体的程序表示的是什么意思。万分感谢!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:R代码 Hansen Short long Temp 门槛协整检验

joe_02m.rar
下载链接: https://bbs.pinggu.org/a-2393953.html

71.42 KB

matlab

joe_02.rar

66.05 KB

gauss

joe_02r.rar

70.88 KB

R

回帖推荐

zhouhao211314 发表于5楼  查看完整内容

这里源文件的R代码不过是读取数据集,然后从数据集中去了两列数据而已。你把自己的short rate和long rate的两列数据存到dat中就可以了。

沙发
cheetahfly 在职认证  发表于 2018-1-7 21:28:57
不像是R语言的风格,请再确认一下。

藤椅
yaolin0522 发表于 2018-1-8 10:08:43
cheetahfly 发表于 2018-1-7 21:28
不像是R语言的风格,请再确认一下。
确实是R语言的,附件3名称joe02r是作者的源代码,我已经在r软件中运行过,没有问题。只是不清楚代码的具体意思,没法把我自己的数据用稍微改动过的代码进行运算,所以请大牛解读一下。你可以下载下来运行一下。里面数据和代码都有。

板凳
cheetahfly 在职认证  发表于 2018-1-8 10:28:31
yaolin0522 发表于 2018-1-8 10:08
确实是R语言的,附件3名称joe02r是作者的源代码,我已经在r软件中运行过,没有问题。只是不清楚代码的具 ...
我在附件3中的tar_ci.R里看到了以下代码,应该是对应的意思,

dat <- read.table("zeroyld.dat")
dat <- dat[1:nrow(dat),(7:62)]
rs <- rbind(as.matrix(seq(0,18,1)),21,24,30,as.matrix(seq(36,(36+7*12),12)))
short <- 12
long <- 120
short_i <- which.max(rs==short)
long_i <- which.max(rs==long)
dat <- dat[,cbind(long_i,short_i)]  

这个才是R语言的风格。

另外,看你另外几个附件,发现代码是来自附件一"joe_02m.rar"中的"tar_ci.m",而你标注这个附件为“matlab”,不知意思是不是matlab的程序语句。

请认真确认。

报纸
zhouhao211314 发表于 2018-1-8 11:33:01
这里源文件的R代码不过是读取数据集,然后从数据集中去了两列数据而已。你把自己的short rate和long rate的两列数据存到dat中就可以了。
已有 1 人评分经验 热心指数 收起 理由
cheetahfly + 20 + 1 热心帮助其他会员

总评分: 经验 + 20  热心指数 + 1   查看全部评分

地板
yaolin0522 发表于 2018-1-8 14:12:49
cheetahfly 发表于 2018-1-8 10:28
我在附件3中的tar_ci.R里看到了以下代码,应该是对应的意思,

dat
不好意思,拷贝错了,问题描述的不是R的代码,是MATlab的数据。r软件的数据附件应当是来自joe-02r.rar中的tar_ci.R

7
yaolin0522 发表于 2018-1-8 14:14:47
cheetahfly 发表于 2018-1-8 10:28
我在附件3中的tar_ci.R里看到了以下代码,应该是对应的意思,

dat
已经修改过来了,文中标红的是R的代码。

8
yaolin0522 发表于 2018-1-8 15:37:54
非常感谢!!!!我按照你说的一改就成功了。

9
yaolin0522 发表于 2018-1-8 15:39:16
zhouhao211314 发表于 2018-1-8 11:33
这里源文件的R代码不过是读取数据集,然后从数据集中去了两列数据而已。你把自己的short rate和long rate的 ...
非常感谢!!!!我按照你说的一改就成功了。谢谢啦!祝2018一切顺利如意!

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-9 18:40