全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
2011-5-22 15:27:08
我把exponential function修改为
s-plus 公式(18.22) ,加入g.scale
感觉比较稳定.
跑出的结果,几乎跟s-plus相同

gamma = 1.013 , s-plus 1.013556
th=-2.775 , s-plus -2.774638


##########################

source("estar_gscale.R")
ndx <- read.table("ndx.rvol.txt");
ndx=ndx[,1]
mod.estar <- estar(log(ndx), m=2,  control=list(maxit=3000))
mod.estar

ESTAR model
Coefficients:
Low regime:
     phi1.0      phi1.1      phi1.2
-0.02512237  0.82408380  0.19486576

High regime:
     phi2.0      phi2.1      phi2.2
-2.14572870 -0.74500270  0.05390954

Smoothing parameter: gamma = 1.013
Threshold
Variable: Z(t) = + (1) X(t) + (0) X(t-1)

Value: -2.775

estar_gscale
estar_gscale.rar
大小:(3.36 KB)

 马上下载

本附件包括:

  • estar_gscale.R

二维码

扫码加我 拉你入群

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

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

2011-5-22 20:42:15
Q2:
external threshold variable
程序会重第一个算起
若要改变可以自己指定thVar=z[4:19]
ndx.estar <- estar(x, m=3,d=1, thVar=z[4:19],control=list(maxit=3000));
ndx.estar$model.specific$thVar

Q3:
新数据的问题来自你的 x
x当external threshold variable是否合适??
> y
[1]  4.678046 25.864895 26.321201 21.249118 15.900649 18.735037
> x
[1]  0.4563057 -5.0720827 -5.3484693  2.8343885 16.1039869 -9.4525352

补充:
希望你上传的数据,
不是你要研究的数据,
因为都无法拒绝Linearity Tests


source("isLinear.R")
########data lynx
mod.lstar <- lstar(log10(lynx), m=2, mTh=c(0,1), control=list(maxit=3000))
isLinear(mod.lstar)   #reject
#Using default threshold variable: thDelay=0
#firstOrderTest thirdOrderTest fifthOrderTest
#   0.000365692    0.001858152    0.020038384

##########s-plus data
ndx <- read.table("ndx.rvol.txt");
ndx=ndx[,1]
mod.ndx <- lstar(log10(ndx), m=2,  control=list(maxit=3000))
isLinear(mod.ndx)     #reject
#Using default threshold variable: thDelay=0
#firstOrderTest thirdOrderTest fifthOrderTest
#   0.037127869    0.001443528    0.001939517

########data cpi
svpdx <- read.table("data.txt", header = TRUE);
x <- svpdx$cpi    #19
y<-svpdx$rpi
z<-svpdx$m2

ndx.lstar <- lstar(x, m=2,d=1, thVar=z[4:19],control=list(maxit=3000));
isLinear(ndx.lstar)
#Using default threshold variable: thDelay=0
#firstOrderTest thirdOrderTest fifthOrderTest
#    0.38286906     0.40174922     0.08667536

######## data m2 & dm
svpdx1 =read.table("m.txt", header = TRUE);
y=svpdx1$m2
y
svpdx2 =read.table("mzh.txt", header = TRUE);
x=svpdx2$dm
x
mod2=lstar(y,m=2,d=1,thVar=x,trace=TRUE,control=list(3000))
isLinear(mod2)
#Using default threshold variable: thDelay=0
#firstOrderTest thirdOrderTest fifthOrderTest
#     0.5099226      0.9538843      0.8437448

二维码

扫码加我 拉你入群

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

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

2011-5-23 18:27:08
好的,万分感谢啊,不过这个模型还是可以做LSTAR模型的,isLinear检验的仅仅是
“Using default threshold variable: thDelay=0”
> library(tsDyn)
> svpdx1 =read.table("m.txt", header = TRUE);
> y=svpdx1$m2
> y
[1]  4.678046 25.864895 26.321201 21.249118 15.900649 18.735037 34.839024
[8] 25.386489 29.219643 22.849062 22.379741 18.316832 27.974895 26.528477
[15] 31.276486 37.312023 34.529817 29.466797 25.257197 19.580787 14.840376
[22] 14.736983 12.269493 13.579229 19.856236 19.634701 15.500372 17.570000
[29] 16.950000 16.700000 17.820000 27.700000
> svpdx2 =read.table("mzh.txt", header = TRUE);
> x=svpdx2$dm
> x
[1]  0.4563057 -5.0720827 -5.3484693  2.8343885 16.1039869 -9.4525352
[7]  3.8331535 -6.3705804 -0.4693215 -4.0629090  9.6580637 -1.4464183
[13]  4.7480087  6.0355369 -2.7822062 -5.0630191 -4.2096000 -5.6764102
[19] -4.7404113 -0.1033927 -2.4674896  1.3097354  6.2770067 -0.2215349
[25] -4.1343289  2.0696282 -0.6200000 -0.2500000  1.1200000  9.8800000
> mod=star(y, m=2, d=1,thVar=x, trace=TRUE, control=list(3000))
Testing linearity...   p-Value =  7.035431e-15
The series is nonlinear. Incremental building procedure:
Building a 2 regime STAR.
Performing grid search for starting values...
Starting values fixed: gamma =  40 , th =  2.836254 ; SSE =  171.8763
Optimization algorithm converged
Optimized values fixed for regime 2  : gamma =  40.0004 , th =  2.842359
Testing for addition of regime 3.
  Estimating gradient matrix...
  Done. Computing the test statistic...
  Done. Regime 3 is needed (p-Value =  3.669726e-08 ).
Adding regime  3 .
Fixing good starting values for regime  3 ...
Reordering regimes...
Estimating parameters of regime 3 ...
Optimized values fixed for regime  3 : gamma =  41.76118 , th =  6.513988
Optimization algorithm converged
Optimized linear values:
3.220247 0.832652 -0.1018466
0.5934429 0.4479709 -0.1300669
-96.12018 6.00583 -0.3571657
Ok.
Testing for addition of regime  4 .
  Estimating gradient matrix...
  Computing the test statistic...
Regime  4  is needed (p-Value =  1.668348e-25 ).
Adding regime  4 .
Fixing good starting values for regime  4 ...
Reordering regimes...
Estimating parameters of regime 4 ...
Optimized values fixed for regime  4 : gamma =  45.94539 , th =  10.64555
Optimization algorithm converged
Optimized linear values:
-1223.773 0.9989231 0.001131645
2450.004 0.002154858 -0.002266246
-0.000291771 1.323034e-05 5.945269e-06
8.071782e-07 1.512423e-05 1.283766e-05
Ok.
Testing for addition of regime  5 .
  Estimating gradient matrix...
  Computing the test statistic...
Regime  5  is needed (p-Value =  7.299121e-05 ).
Adding regime  5 .
Fixing good starting values for regime  5 ...
Reordering regimes...
Estimating parameters of regime 5 ...
Optimized values fixed for regime  5 : gamma =  40.19385 , th =  12.99012
Optimization algorithm converged
Optimized linear values:
-87770.04 0.9999943 -1.059852e-06
175536.9 1.140156e-05 2.120564e-06
8.209452e-06 4.957738e-06 -6.154125e-06
-1.467837e-06 -5.366139e-06 6.189698e-06
-3.195256e-07 -6.826985e-06 8.100021e-06
Ok.
Testing for addition of regime  6 .
  Estimating gradient matrix...
  Computing the test statistic...
Regime  6  is NOT accepted (p-Value =  0.9999734 ).
Finished building a MRSTAR with  5  regimes
>


92# epoh
二维码

扫码加我 拉你入群

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

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

2011-5-23 20:38:17
前辈您好!我还想做出两个负的冲击下的的impulse response function图(这个是不是只需将“shock_m=2; #Double Magnitude Positive Shock”改为shock_m=-2; #Double Magnitude negative Shock”就可以了呢?)和两个正的冲击与两个负的冲击之和的impulse response function图(想衡量非对称的脉冲响应Measuring asymmetric impulse response,见帖子中26楼的paper“Smooth Transition Autoregressive Models -A Survey of Recent Developments”page28),麻烦您帮我下编程序,谢谢您了!
81# epoh
二维码

扫码加我 拉你入群

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

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

2011-5-24 11:41:28
estar transition functions
依 s-plus 公式(18.22)加入g.scale
感觉比较稳定
跑出的结果,几乎跟s-plus相同.
程序我放91楼.

######################
asymmetric impulse response
麻烦你告知要用的数据及mode,以方便编程
因为tsDyn_0.7-60还是有些改变,
这次shock_m我会改为,一次完成
shock_m=c(-2,-1,0,1,2);
当然你也可以改为跟文献一样
shock_m=seq(-3,3,0.1)

#####################
m,mzh的数据OK,是我忘了加thVar=x
svpdx1 =read.table("m.txt", header = TRUE);
y=svpdx1$m2
svpdx2 =read.table("mzh.txt", header = TRUE);
x=svpdx2$dm
mod2=lstar(y,m=2,d=1,thVar=x,trace=TRUE,control=list(3000))
isLinear(mod2,thVar=x)    #reject
firstOrderTest thirdOrderTest fifthOrderTest
2.041730e-211  3.925313e-155  3.347176e-101
二维码

扫码加我 拉你入群

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

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

2011-5-24 13:05:48
非常感谢!数据和模型都和您在81楼的相同,只是用现在的tsDyn_0.7-60估计出来的结果变了,我还是想用以前的这个模型和结果(如下所示)做asymmetric impulse response function。谢谢您了!
library(tsDyn)
svpdx <- read.table("quartc.txt", header = TRUE);
x <- svpdx$qcpi
mod<- star(x, m=5,d=1,thDelay=1,noRegimes=3, control=list(maxit=3000))
Testing linearity...   p-Value =  0.002852162
The series is nonlinear. Incremental building procedure:
Building a 2 regime STAR.
Performing grid search for starting values...
Starting values fixed: gamma =  24 , th =  14.00072 ; SSE =  88.80465
Optimization algorithm converged
Optimized values fixed for regime 2  : gamma =  23.99999 , th =  13.99887
Testing for addition of regime 3.
  Estimating gradient matrix...
  Done. Computing the test statistic...
  Done. Regime 3 is needed (p-Value =  0.01449991 ).
Adding regime  3 .
Fixing good starting values for regime 3 ...
Reordering regimes...
Estimating parameters of regime 3 ...
Optimized values fixed for regime  3 : gamma =  42.27714 , th =  13.93399
Optimization algorithm converged
Optimized linear values:
0.2997076 1.056419 0.06167327 0.04290917 -0.5146651 0.2624537
1.415723 1.049638 -1.271572 -0.5466812 0.785233 -0.1815548
12.89779 -1.462572 1.594120 0.3835062 -1.037747 -0.005988798
Ok.
Testing for addition of regime  4 .
  Estimating gradient matrix...
  Computing the test statistic...
Regime  4  is NOT accepted (p-Value =  0.1873368 ).
Finished building a MRSTAR with  3  regimes
> mod
Non linear autoregressive model
Multiple regime STAR model
Regime  1 :
    Linear parameters: 0.2997076, 1.0564187, 0.0616733, 0.0429092, -0.5146651, 0.2624537
Regime  2 :
    Linear parameters: 1.4157232, 1.0496377, -1.2715717, -0.5466812, 0.785233, -0.1815548
    Non-linear parameters:
35.0696739, 5.2725434
Regime  3 :
    Linear parameters: 12.8977894, -1.4625725, 1.5941205, 0.3835062, -1.0377474, -0.0059888
    Non-linear parameters:
42.2771382, 13.9339929
95# epoh
二维码

扫码加我 拉你入群

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

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

2011-5-24 16:24:18
library(tsDyn)
svpdx =read.table("quartc.txt", header = TRUE);
x =svpdx$qcpi
mod =star(x, m=5,d=1,thDelay=1,noRegimes=3,control=list(maxit=3000))
phi1=mod$model.specific$phi1
phi2=mod$model.specific$phi2
res=mod$residuals;
sd_res=sd(res)
std_res=res/sd_res;
hist_m=cbind(1,mod$str$xx,mod$str$yy,mod$model.specific$thVar)
colnames(hist_m)=c("Const","V1/0","V1/-1","V1/-2","V1/-3",",V1/-4","y","thVar")
hist_m[1:3,]         #"histories"
noh=dim(hist_m)[1]   # 83 "histories"
#Transition function
   G <- function(y, g, th)  plogis(y, th, 1/g)
N=60       #the maximum horizon
R=1000     #the number of replications
shock_m=c(-2,-1,0,1,2);
nosh=length(shock_m)
realvb=NA*seq(1:(N+1));
realzb=NA*seq(1:(N+1));
GI=matrix(data = NA,noh,N+1);
GIRF= array(0, dim = c(noh,N+1, nosh))
#generate standardized shocks from lstar model
st_shock_idx=sample(seq(1:length(std_res)),R*(N+1),replace = TRUE)   
length(st_shock_idx)
st_shock=matrix(std_res[st_shock_idx],R,N+1)
dim(st_shock)
st_shock[1:2,]
for(s in 1:nosh){
shockz=st_shock*sd_res
###
for(i in 1:noh){
hist=hist_m[i,];
# benchmark profile
histz=matrix(rep(hist,R),R,dim(hist_m)[2], byrow =TRUE);
dim(histz)
histz[1:3,]
for(j in 1:(N+1)){
y=histz[,1:6]%*%phi1[1,] + histz[,1:6]%*%phi1[2,]*G(histz[,8],phi2[1,1],phi2[1,2]) +
  histz[,1:6]%*%phi1[3,]*G(histz[,8], phi2[2,1],phi2[2,2])+shockz[,j]
######compute "new" histories
histz=cbind(1,y,histz[,2:5],y,histz[,3])
realzb[j]=mean(histz[,7]);
}#end j benchmark profile

#shock profile
shockv=matrix(rep(shock_m*sd_res,R),R,1)
histv=matrix(rep(hist,R),R,dim(hist_m)[2], byrow =TRUE)
k=1
y=histz[,1:6]%*%phi1[1,] + histz[,1:6]%*%phi1[2,]*G(histz[,8],phi2[1,1],phi2[1,2]) +
  histz[,1:6]%*%phi1[3,]*G(histz[,8], phi2[2,1],phi2[2,2])+shockv
######compute "new" histories
histv=cbind(1,y,histv[,2:5],y,histv[,3])
realvb[k]=mean(histv[,7]);
for(k in 2:(N+1)){
........
........
}  #end k shock profile
GI[i,]=realvb-realzb;
}# end i numbers of histories
GIRF[,,s]=GI
} #end s
girf1=apply( GIRF[,,1],2,mean)
girf2=apply( GIRF[,,2],2,mean)
girf3=apply( GIRF[,,3],2,mean)
girf4=apply( GIRF[,,4],2,mean)
girf5=apply( GIRF[,,5],2,mean)
par(mfrow = c(2, 2))

##P shock
plot(girf4, ylab = expression(GIRF(h,delta,W(t-1))), xlab = 'Time Horizon')
title("Generalized impulse response functions (P shock)")
legend("bottomright", " Positive Shock",text.col=4)
lines(girf4,col='red')

##PP shock
plot(girf5, ylab = expression(GIRF(h,delta,W(t-1))), xlab = 'Time Horizon')
title("Generalized impulse response functions (PP shock)")
legend("bottomright", "Double Magnitude Positive Shock",text.col=4)
lines(girf5,col='red')

##N shock
plot(girf2, ylab = expression(GIRF(h,delta,W(t-1))), xlab = 'Time Horizon')
title("Generalized impulse response functions (N shock)")
legend("bottomright", " Negative Shock",text.col=4)
lines(girf2,col='red')

##NN shock
plot(girf1, ylab = expression(GIRF(h,delta,W(t-1))), xlab = 'Time Horizon')
title("Generalized impulse response functions (NN shock)")
legend("bottomright", "Double Magnitude Negative Shock",text.col=4)
lines(girf1,col='red')


girf.jpeg

####Measure of asymmetry.
x11()
asym=girf1+girf5  #NN + PP
plot(asym, ylab = expression(ASYM(h,delta,W(t-1))), xlab = 'Time Horizon')
title("Measure of asymmetry")
legend("bottomright", "Double Magnitude Positive Negative Shock",text.col=4)
lines(asym,col='red')

asym.jpeg
二维码

扫码加我 拉你入群

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

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

2011-5-24 18:13:17
前辈您好!我观察了脉冲响应函数图,有一点不是很明白。就是给系统一个正的冲击的脉冲响应函数图和给系统一个负的冲击的脉冲响应函数图在零时刻时应该大小相同正负相反,以后的时刻可以不对称(也正是体现了不对称性),但是图中的情况并不是这样,希望前辈解答,谢谢!paper“Smooth Transition Autoregressive Models -A Survey of Recent Developments”page55)中的图我贴在了98楼已作对照!
97# epoh
附件列表
未命名.jpg

原图尺寸 51.4 KB

未命名.jpg

二维码

扫码加我 拉你入群

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

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

2011-5-24 20:08:58
这两种图形是不一样的
附图是highest density regions using density quantile method

要分清楚当然是依
recession and expansion分别画出

由于你是分三区:
   high  :9

  middle : 15

   low   : 59

  high regime几乎不受正负冲击影响
  为何会这样?这要依据你的数据了

我画出middle regime 给你参考

middle regime.jpeg
二维码

扫码加我 拉你入群

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

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

2011-5-24 20:27:23
前辈您好!十分感谢您一直以来对我的帮助,您可以再把高区制及低区制的impulse response function也帖出来吗?另外把三个区制的impulse response function的code也发给我好吗?我想再看些文献分析下,谢谢您了!
99# epoh
二维码

扫码加我 拉你入群

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

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

2011-5-25 10:03:50
我还是以data lynx来做图形
正负冲击对比鲜明,
这样比较贴近你的想法.
###########PP shock
gi_pphigh=GIRF[,,5][which(hist_m[,4]>th),]    #34
gi_pplow =GIRF[,,5][which(hist_m[,4]<th),]    #78

##high pp shock
high_regime5=apply(gi_pphigh ,2,mean)
##low pp shock
low_regime5=apply(gi_pplow ,2,mean)

####plot PP shock on different regime
par(mfrow = c(2,1))
plot(seq(1,61),high_regime5, type="l", col = 2, ylab = expression(GIRF(h,delta,W(t-1))), xlab = 'Time Horizon')
lines(seq(1,61),low_regime5,col = 3, lty = 2)
title("PP shock on different regimes")
legend("bottomright", c("High Regime","Low Regime"), lty=1:2, col=2:3,    adj = c(0, .6))

###############
###########NN shock
gi_nnhigh=GIRF[,,1][which(hist_m[,4]>th),]    #34
gi_nnlow =GIRF[,,1][which(hist_m[,4]<th),]    #78

##low NN shock
##high nn shock
high_regime1=apply(gi_nnhigh ,2,mean)
##low nn shock
low_regime1=apply(gi_nnlow ,2,mean)

####plot NN shock on different regimes
plot(seq(1,61),high_regime1, type="l", col = 2,ylab = expression(GIRF(h,delta,W(t-1))), xlab = 'Time Horizon')
lines(seq(1,61),low_regime1,col = 3, lty = 2)
title("NN shock on different regimes")
legend("bottomright", c("High Regime","Low Regime"), lty=1:2, col=2:3,    adj = c(0, .6))

lynx_different regime.jpeg

###############plot PP &NN Shock on high regime
x11()
par(mfrow = c(2,1))
plot(seq(1,61),high_regime5, type="l", col = 2,ylim=c(-0.6,0.6),
   ylab = expression(GIRF(h,delta,W(t-1))), xlab = 'Time Horizon')
lines(seq(1,61),high_regime1,col = 3, lty = 2)
title("PP & NN shock on high regime")
legend("bottomright", c("PP Shock","NN Shock"), lty=1:2, col=2:3,    adj = c(0, .6))

###############plot PP &NN Shock on low regime
plot(seq(1,61),low_regime5, type="l", col = 2,  ylim=c(-0.55,0.55),
    ylab = expression(GIRF(h,delta,W(t-1))), xlab = 'Time Horizon')
lines(seq(1,61),low_regime1,col = 3, lty = 2)
title("PP & NN shock on low regime")
legend("bottomright", c("PP Shock","NN Shock"), lty=1:2, col=2:3,    adj = c(0, .6))


lynx_ same regime.jpeg


ps:你的数据三区的话
gi_pphigh=GIRF[,,5][which(hist_m[,7]>phi2[2,2]),]                    #9
gi_ppmiddle=GIRF[,,5][which(hist_m[,7]<phi2[2,2] & hist_m[,7]>phi2[1,2]),]  #15
gi_pplow=GIRF[,,5][which(hist_m[,7]<phi2[1,2]),]   

二维码

扫码加我 拉你入群

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

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

2011-5-25 13:45:41
前辈您好!可以把你的例子数据data lynx传给我吗?谢谢您了!101# epoh
二维码

扫码加我 拉你入群

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

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

2011-5-25 14:04:22
抱歉没说清楚
这是延续79楼
data(lynx)就是package范例
我把程序贴上好了.

##################
library(tsDyn)
mod <- lstar(log10(lynx), m=2, mTh=c(0,1), control=list(maxit=3000))

phi1=mod$model.specific$coefficients[1:3]
phi1

phi2=mod$model.specific$coefficients[4:6]
phi2

gamma=mod$model.specific$coefficients[7]
th=mod$model.specific$coefficients[8]
res=mod$residuals;
sd_res=sd(res)
std_res=res/sd_res;

hist_m=cbind(1,mod$str$xx,mod$str$yy,mod$model.specific$thVar)
colnames(hist_m)=c("Const","V1/0","V1/-1","y","thVar")
hist_m[1:3,]   #"histories"
noh=dim(hist_m)[1]

#Transition function
   G <- function(y, g, th)  plogis(y, th, 1/g)

N=60       #the maximum horizon
R=1000     #the number of replications
shock_m=c(-2,-1,0,1,2);
nosh=length(shock_m)
realvb=NA*seq(1:(N+1));
realzb=NA*seq(1:(N+1));
GI=matrix(data = NA,noh,N+1);
GIRF= array(0, dim = c(noh,N+1, nosh))

#generate standardized shocks from lstar model
st_shock_idx=sample(seq(1:length(std_res)),R*(N+1),replace = TRUE)   
length(st_shock_idx)
st_shock=matrix(std_res[st_shock_idx],R,N+1)
dim(st_shock)
st_shock[1:2,]

for(s in 1:nosh){
shockz=st_shock*sd_res
###
for(i in 1:noh){
hist=hist_m[i,];

# benchmark profile
histz=matrix(rep(hist,R),R,dim(hist_m)[2], byrow =TRUE);
dim(histz)
histz[1:3,]

for(j in 1:(N+1)){
y=histz[,1:3]%*%phi1 + histz[,1:3]%*%phi2*G(histz[,5], gamma,th) + shockz[,j]
######compute "new" histories
histz=cbind(1,y,histz[,2],y,histz[,2])
realzb[j]=mean(histz[,4]);
}#end j benchmark profile


#shock profile
shockv=matrix(rep(shock_m*sd_res,R),R,1)
histv=matrix(rep(hist,R),R,dim(hist_m)[2], byrow =TRUE)
k=1
y=histv[,1:3]%*%phi1 + histv[,1:3]%*%phi2*G(histv[,5], gamma,th) + shockv
######compute "new" histories
histv=cbind(1,y,histv[,2],y,histv[,2])
realvb[k]=mean(histv[,4]);
for(k in 2:(N+1)){
........
........
}  #end k shock profile
GI[i,]=realvb-realzb;

}# end i numbers of histories
GIRF[,,s]=GI
} #end s

续接101楼
二维码

扫码加我 拉你入群

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

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

2011-5-26 19:14:07
前辈您好!我现在安装的是R 2.13.0,直接估计下面方程会得到如下结果:
> svpdx =read.table("quartc.txt", header = TRUE);
> x =svpdx$qcpi
> mod =star(x, m=5,d=1,thDelay=1,noRegimes=3,control=list(maxit=3000))
Testing linearity...   p-Value =  0.002852162
The series is nonlinear. Incremental building procedure:
Building a 2 regime STAR.
Performing grid search for starting values...
Starting values fixed: gamma =  24 , th =  14.00072 ; SSE =  88.80465
Optimization algorithm converged
Optimized values fixed for regime 2  : gamma =  23.99999 , th =  13.99876
Testing for addition of regime 3.
  Estimating gradient matrix...
  Done. Computing the test statistic...
  Done. Regime 3 is NOT accepted (p-Value =  0.06172199 ).
Finished building a MRSTAR with  2  regimes
> phi1=mod$model.specific$phi1
> phi1
           [,1]       [,2]       [,3]        [,4]       [,5]        [,6]
[1,]  0.1883403  1.4341040 -0.3197945 -0.13549328 -0.1913063  0.16429109
[2,] 14.4249331 -0.7906222  0.7040176  0.01522778 -0.5758736 -0.08938245
但是我还是想用R 2.12.2估计模型以得到下面的结果,
library(tsDyn)
svpdx <- read.table("quartc.txt", header = TRUE);
x <- svpdx$qcpi
mod<- star(x, m=5,d=1,thDelay=1,noRegimes=3, control=list(maxit=3000))
Testing linearity...   p-Value =  0.002852162
The series is nonlinear. Incremental building procedure:
Building a 2 regime STAR.
Performing grid search for starting values...
Starting values fixed: gamma =  24 , th =  14.00072 ; SSE =  88.80465
Optimization algorithm converged
Optimized values fixed for regime 2  : gamma =  23.99999 , th =  13.99887
Testing for addition of regime 3.
  Estimating gradient matrix...
  Done. Computing the test statistic...
  Done. Regime 3 is needed (p-Value =  0.01449991 ).
Adding regime  3 .
Fixing good starting values for regime 3 ...
Reordering regimes...
Estimating parameters of regime 3 ...
Optimized values fixed for regime  3 : gamma =  42.27714 , th =  13.93399
Optimization algorithm converged
Optimized linear values:
0.2997076 1.056419 0.06167327 0.04290917 -0.5146651 0.2624537
1.415723 1.049638 -1.271572 -0.5466812 0.785233 -0.1815548
12.89779 -1.462572 1.594120 0.3835062 -1.037747 -0.005988798
Ok.
Testing for addition of regime  4 .
  Estimating gradient matrix...
  Computing the test statistic...
Regime  4  is NOT accepted (p-Value =  0.1873368 ).
Finished building a MRSTAR with  3  regimes
但是我在R 2.12.2中选择在线安装的话还是得到第一种结果,如果选择本地安装tsDyn_0.7-40.zip,但是估计时出现了下面的问题:
> utils:::menuInstallLocal()
程序包'tsDyn'打开成功,MD5和检查也通过
> library(tsDyn)
错误: 程辑包'tsDyn'没有安装在'arch=i386'中
>  svpdx <- read.table("quartc.txt", header = TRUE);
>  x <- svpdx$qcpi
>  mod2 <- star(x, m=5,d=1,thDelay=1,noRegimes=3,control=list(maxit=3000))
错误: 没有"star"这个函数
>
现在我还是想估计得到第二种结果,该怎么办呢?谢谢您了!
103# epoh
二维码

扫码加我 拉你入群

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

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

2011-5-26 20:26:57
安装 2.13.0 也是OK
我就是安装2.13.0
你把现有的R移除乾净(package)
然后安装2.13.0
由本机安装03.23我上传的版本
载入tsDyn,他会告诉你缺甚么,
你就安装什么.
如此就OK了.


#################

你想画highest density regions for generalized impulse responses
可以安装Package "hdrcde"
Author 就是Rob J Hyndman
底下就是我用data(lynx)画的

HDR_lynx.jpeg
二维码

扫码加我 拉你入群

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

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

2011-5-27 09:02:58
epoh真是好老师,向您学习!
二维码

扫码加我 拉你入群

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

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

2011-5-28 09:47:13
前辈您好!可以把您做的highest density regions for generalized impulse responses的程序贴上来吗?谢谢您了啊!
105# epoh
二维码

扫码加我 拉你入群

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

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

2011-6-2 08:38:10
hdr.boxplot_modify.R

hdr.boxplot_modify.rar
大小:(1.75 KB)

 马上下载

本附件包括:

  • hdr.boxplot_modify.R

二维码

扫码加我 拉你入群

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

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

2011-6-3 13:20:04
epoh您好,我在使用tsDyn程序包里面的TVAR.LRtest做两个还是三个门限检测的时候出现了问题说错误于object$CriticalValBoot[1, ] : 量度数目不对,能否麻烦您帮我看一下怎么回事啊,谢谢了啊!
> data(zeroyld)
> data<-zeroyld
> test<-TVAR.LRtest(data,lag=2,mTh=1,thDelay=1:2,nboot=3,plot=FALSE,trim=0.1,test="2vs3")
Warning: the thDelay values do not correspond to the univariate implementation in tsdyn
> summary(test)
Test of linear AR against TAR(1) and TAR(2)

LR test:
          [,1]
Test  12.69123
P-Val  1.00000
Bootstrap critical values for test 1 vs 2 regimes
错误于object$CriticalValBoot[1, ] : 量度数目不对
二维码

扫码加我 拉你入群

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

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

2011-6-3 13:25:32
epoh您好,tsDyn里面有没有对TVECM是2个门限和3个门限检验的检验程序啊?如果我想使用Ming Chien Lo和Eric Zivot(2001)的方法进行2VS3的门限检验,请问怎么可以得到检验量近视分布的统计量和P值啊?多谢多谢!
二维码

扫码加我 拉你入群

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

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

2011-6-3 13:52:46
epoh 发表于 2010-10-1 10:35
楼主也可参考
modeling financial time series with s-plus
CHAP 18 Nonlinear Time Series Models

18.4.1
对于Logistic and Exponential STAR Models
有更加详细的叙述.
S-PLUS function STAR 目前只有一种type="LSTAR"
若要用 ESTAR model,page 684有说明
先写出function ESTAR.res
再用nlregb估计模型参数
呵呵不错!
二维码

扫码加我 拉你入群

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

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

2011-6-4 16:25:41
回覆hellovb
第一个问题:
作者summary()主要是针对test="1vs",
若用test="2vs3",就会出错
不过还是可以由
test$CriticalValBoot  得到
#     90%      95%    97.5%      99%
#27.74475 27.85584 27.91139 27.94472

或者小修source code得到
summary(test)
Test of linear AR against TAR(1) and TAR(2)
LR test:
          [,1]
Test  12.69123
P-Val  1.00000

Bootstrap critical values for test 2 vs 3
     90%      95%    97.5%      99%
27.74475 27.85584 27.91139 27.94472


第二个问题:
tsDyn里面目前没有对TVECM是2个门限和3个门限检验的检验程序,
如果想使用Ming Chien Lo和Eric Zivot(2001)的方法
进行2VS3的门限检验,这要花些你的时间,
参考TVAR.LRtest 自行修改.
二维码

扫码加我 拉你入群

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

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

2011-6-4 16:45:11
epoh您好,非常感谢您的回答,由于我对R语言不是很熟练,肯请您能否帮忙修正一下TVAR.LRtest的程序啊? 非常感谢!#112楼
二维码

扫码加我 拉你入群

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

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

2011-6-4 19:05:11
抱歉!我并没在这方面研究,
编程可就要靠你自己来了.
二维码

扫码加我 拉你入群

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

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

2011-6-4 21:34:03
好的,eoph,多谢了啊
二维码

扫码加我 拉你入群

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

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

2011-6-14 15:32:42
很详细的回答,需要认真的看完,好好学习下
二维码

扫码加我 拉你入群

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

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

2011-7-20 23:01:25
epoh您好,下载了您在108楼的修改后的程序,具体怎么用呢?能否说一下啊?谢谢 另外能否把函数里面的参数都表示什么意思解释一下啊?多谢多谢 我用lynx运行你修改的这个程序老是出错。
二维码

扫码加我 拉你入群

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

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

2011-8-8 19:30:10
epoh老师你好。我想问一下为什么用tsDyn包建立setar模型时,老是出错啊,比如说选择setar(x,m=2,d=2,steps=2,thDelay=1),无论模型参数怎么改,老是显示 错误于rep(NA, length(x) - length(reg)) : 'times'参数不对  ,请问错在哪里呢?数据x就是一个普通的数据序列,可以看成是1到100的正整数
二维码

扫码加我 拉你入群

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

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

2011-8-8 20:38:59

如果你的数据是data.frame就会产生这样的错误

错误于rep(NA, length(x) - length(reg)) : 'times'参数不对

#######
example:
x=sample(seq(1:100),100,replace=T)
setar(x, m=2, d=2,steps=2,thDelay=1)

Non linear autoregressive model

SETAR model ( 2 regimes)
Coefficients:
Low regime:
   phiL.1    phiL.2   const L
-0.164985  1.479546 31.203849

High regime:
     phiH.1      phiH.2     const H
-0.05299776  0.41172242 24.76056691

Threshold:
-Variable: Z(t) = + (0) X(t)+ (1)X(t-1)
-Value: 32
Proportion of points in low regime: 35.42%       High regime: 64.58%
Warning message:
Possible unit root in the low  regime. Roots are: 0.8798 0.7683

##########data.frame
y=as.data.frame(x)
class(y) #[1] "data.frame"
setar(y, m=2, d=2,steps=2,thDelay=1)

错误于rep(NA, length(x) - length(reg)) : 'times'参数不对

二维码

扫码加我 拉你入群

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

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

2011-8-9 20:55:55
epoh老师你好,看了你的回复我把程序改成
> setwd("d:/data")
> x<-scan("y.txt",what=list(0))
Read 1105 records
> setar(x,m=2,d=2,steps=2,thDelay=0)
但是出现了错误于nlar.struct(x = x, m = m, d = d, steps = steps, series = series) :
time series too small to handle these embedding parameters
我到底该这么样读入数据才能建立setar模型呢?附件里是我的数据
附件列表

y.txt

大小:14.38 KB

 马上下载

二维码

扫码加我 拉你入群

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

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

栏目导航
热门文章
推荐文章

分享

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