全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
1656 8
2018-01-06
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,具体的是想知道文中红色字体的程序表示的是什么意思。万分感谢!
附件列表

joe_02m.rar

大小:71.42 KB

 马上下载

matlab

joe_02.rar

大小:66.05 KB

 马上下载

gauss

joe_02r.rar

大小:70.88 KB

 马上下载

R

二维码

扫码加我 拉你入群

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

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

全部回复
2018-1-7 21:28:57
不像是R语言的风格,请再确认一下。
二维码

扫码加我 拉你入群

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

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

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

扫码加我 拉你入群

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

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

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的程序语句。

请认真确认。
二维码

扫码加我 拉你入群

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

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

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

扫码加我 拉你入群

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

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

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
二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群