楼主: jiezichen
6034 22

[问答] 在线等帮我翻译下以下代码啊 谢谢 看不懂什么意思 [推广有奖]

11
jiezichen 发表于 2011-11-2 12:10:46
epoh 发表于 2011-11-2 11:56
[1] "short_i"
[1] 4
[1] "long_i"
改了数据 刚才还能运行的,重新关了 现在运行到
Number of Bootstrap Replications     5000
Number of Gridpoints for threshold   300
Estimated Cointegrating Vector
Number of Gridpoints for ci vector  300


错误于cat("Long Rate  (month):     ", long, "\n") : 找不到对象'long'
>
就没了 晕

12
epoh 发表于 2011-11-2 12:25:20

你把数据传上来看看

不方便的话,数据可以随意改.

已有 1 人评分学术水平 热心指数 信用等级 收起 理由
ywh19860616 + 1 + 1 + 1

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

13
epoh 发表于 2011-11-2 14:22:58

package "tsDyn"

自带的data zeroyld就是2 variables.

跟你的相同

所以我就依此,修改程序,供你参考

仅改四行.

# Data loaded into matrix "dat" #

#dat <- read.table("zeroyld.dat")

#datstore <- 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)))

data(zeroyld)

datstore<-zeroyld

rs=c(1,2)

rates_i <- matrix(c(1,2),1,2)

rates_i

#     [,1] [,2]

#[1,]    1    2

   zeroyld.rar (2.64 KB) 本附件包括:

  • zeroyld.R

已有 1 人评分学术水平 热心指数 信用等级 收起 理由
zhangtao + 5 + 5 + 5 精彩帖子

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

14
jiezichen 发表于 2011-11-2 15:41:28
epoh 发表于 2011-11-2 12:25
你把数据传上来看看不方便的话,数据可以随意改.
7.6        41024
7.91        42361
5.26        43752
9.02        45295
10.9        46436
15.17        48197
13.47        49872.7
8.86        51282
11.57        52783
11.27        54334
4.07        55329
3.83        64749
9.2        65491
14.2        66152
14        66808
13.1        67455
10.93        68065
10        68950
9.3        69820
7.8        70637
7.6        71394
8.4        72085
8.31        73025
9.1        73740
10        74432
10.1        75200
10.4        75825
11.61        76400
13.2        76990
9.55        77480
8.74        77995

15
jiezichen 发表于 2011-11-2 15:42:33
epoh 发表于 2011-11-2 12:25
你把数据传上来看看不方便的话,数据可以随意改.
谢谢老师的指导 我一共就这些数据 不知道该怎么输入 和改哪里 求指教 谢谢

16
zhangtao 发表于 2011-11-2 15:54:17
> VECM(zeroyld, lag,r=1, include = c( "const", "trend","none", "both"),beta=NULL, estim=c("2OLS", "ML"),LRinclude=c("none", "const", "trend","both"))
错误于1:p : NA/NaN参数
epoh老师,您好!
     以上代码错在什么地方?
数学好就是要天天学

17
epoh 发表于 2011-11-2 16:33:15

先改一个tar_rate.R

供你参考.

jiezi.txt

   jiezi.txt (586 Bytes)

tar_rate.R

   tar_rate.rar (4.49 KB) 本附件包括:

  • tar_rate.R

请自行参照更改tar_ci.R,ur_rate.R

不过你的数据有问题

是否需经处理,或数据不合适

请自行斟酌.

*************************

Number of Bootstrap Replications     50
Number of Gridpoints for threshold   30
Cointegrating Vector fixed at       1


     V2   V1
1 41024 7.60
2 42361 7.91
3 43752 5.26
**********************************************************

Long Rate  (month):      2
Short Rate (month):      1
Number of VAR lags:      1

Linear VECM Estimates

Cointegrating Vector  1
Negative Log-Like     233.6749
AIC                   249.6749
BIC                   245.3741

  Equation 1
  -5.056e-02    1.926e-02
   4.562e+03    1.474e+03
  -7.860e-02    4.837e-02
  -2.956e+02    2.060e+02

  Equation 2
   1.235e-05    4.758e-05
  -1.486e+00    3.387e+00
   5.732e-04    1.000e-04
   1.286e-01    1.740e-01


Threshold VECM Estimates

Threshold Estimate             54322.73
Cointegrating Vector Estimate  1
Negative Log-Like              215.1869
AIC                            247.1869
BIC                            238.5852

First Regime
Percentage of Obs 0.3103448

  Equation 1
  -7.861e-03    2.143e-02
   2.325e+03    9.345e+02
  -3.437e-01    4.255e-01
   9.098e+00    2.091e+01

  Equation 2
  -2.559e-04    3.294e-04
   2.715e+01    1.588e+01
  -1.031e-02    2.823e-03
   4.183e-02    2.810e-01

Second Regime
Percentage of Obs 0.6896552

  Equation 1
  -2.213e-01    6.572e-02
   1.694e+04    4.810e+03
  -2.023e-01    6.630e-02
  -3.508e+02    1.030e+02

  Equation 2
  -5.581e-05    8.362e-05
   3.503e+00    6.025e+00
   5.955e-04    7.335e-05
   2.891e-01    1.862e-01

Wald Test for Equality of Dynamic Coefs  30.75156   3.440211e-06
Wald Test for Equality of ECM Coef       11.80651   0.002730549

***************************

错误在solve.default(v)

此外: Warning message:

In sqrt(hp) : 产生了 NaNs

18
epoh 发表于 2011-11-2 16:35:17

zhangtao兄

library(tsDyn)
data(zeroyld)
data<-zeroyld
#Fit a VECM with Johansen MLE estimator:
vecm.jo<-VECM(zeroyld, lag=2, r=1,include = "both",estim="ML")
vecm.jo
                                      ECT    Intercept         Trend
Equation short.run -0.02173938  0.039680380 -4.899791e-05
Equation long.run   0.07724847 -0.008724736 -1.692648e-04
                              short.run -1 long.run -1 short.run -2 long.run -2
Equation short.run   0.03615135  0.02135291  -0.04326987 -0.02589591
Equation long.run    0.30255266  0.06757760  -0.03446417 -0.07055439

已有 1 人评分学术水平 热心指数 信用等级 收起 理由
zhangtao + 5 + 5 + 5 非常感谢epoh大师!

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

19
jiezichen 发表于 2011-11-2 17:10:42
epoh 发表于 2011-11-2 16:33
先改一个tar_rate.R供你参考.jiezi.txt  tar_rate.R  请自行参照更改tar_ci.R,ur_rate.R不过你的数据有问题 ...
epoh 老师你好
我按你说的方法 里面完全复制你里面的 tar_rate.rar

  tar_ci.R 里改成
#dat <- read.table("zeroyld.dat")
#datstore <- 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)))
#data(zeroyld)
#datstore<-zeroyld
datstore=read.table("jiezi.txt")
rs=c(1,2)
rates_i <- matrix(c(1,2),1,2)
rates_i

上面的control改成
gn <- 30              # number of gridpoints for gamma
bn <- 30                # number of gridpoints for beta  

ur_rate.R也做了类似改动

然后先运行tar_ci.R
出来
**********************************************************

Number of Bootstrap Replications     5000
Number of Gridpoints for threshold   30
Estimated Cointegrating Vector
Number of Gridpoints for ci vector  30


错误于cat("Long Rate  (month):     ", long, "\n") : 找不到对象'long'

再运行tar_rate.R
出来
**********************************************************

Number of Bootstrap Replications     5000
Number of Gridpoints for threshold   300
Cointegrating Vector fixed at       1


**********************************************************

Long Rate  (month):      2
Short Rate (month):      1
Number of VAR lags:      1

Linear VECM Estimates

Cointegrating Vector  1
Negative Log-Like     -19.11605
AIC                   -3.116053
BIC                   -7.416869

  Equation 1
  -0.5267066    0.1586
   3.5619265    1.0860
   0.3454491    0.1908
  -1.0579601    1.0998

  Equation 2
   0.0431858    0.0162
  -0.2902415    0.1348
  -0.0004176    0.0176
   0.6190880    0.1442



错误于if (min(rbind(n1, (t - n1)))/t > trim) { :
  需要TRUE/FALSE值的地方不可以用缺少值

再运行ur_rate.R
出来
**********************************************************

Number of Bootstrap Replications     5000


**********************************************************

Long Rate  (month):      2
Short Rate (month):      1
Number of VAR lags:      1

ADF test                 -3.935788

Estimated CI vector      12.50954 -0.8366052
Engle-Granger test       -3.964176

错误于t(x1) %*% sim1 : 非整合参数

这样之后在运行tar_ci.R
就完全出来了 效果和原程序一样
不知道为什么 不过已经能全出来了

很感谢您!!!

20
zhangtao 发表于 2011-11-2 20:40:59
data(zeroyld)
data<-zeroyld
epoh老师,以上两行是什么意思?
为什么下面的程序也能执行出结果?
> library(tsDyn)
> data(zeroyld)
> data<-zeroyld
> #Fit a VECM with Johansen MLE estimator:
> vecm.jo<-VECM(data, lag=2, r=1,include = "both",estim="ML")
> vecm.jo
                           ECT    Intercept         Trend short.run -1 long.run -1 short.run -2
Equation short.run -0.02173938  0.039680380 -4.899791e-05   0.03615135  0.02135291  -0.04326987
Equation long.run   0.07724847 -0.008724736 -1.692648e-04   0.30255266  0.06757760  -0.03446417
                   long.run -2
Equation short.run -0.02589591
Equation long.run  -0.07055439
>


数学好就是要天天学

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

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