楼主: 南冰
96468 299

急:R软件加载程序包tsDyn问题 [推广有奖]

161
雁茗轩 发表于 2012-4-14 13:35:28
epoh 发表于 2012-4-14 11:13
哈哈!参考一下28楼(data)及36楼
老师,数据和程序在160楼,麻烦您看一下我的问题在哪里,万分感谢了,着急用啊!

162
epoh 发表于 2012-4-14 14:56:40
雁茗轩 发表于 2012-4-14 11:21
老师您好,我就是按照那样估计的,可是为什么mod=lstar(x,m=2,d=1,thvar=z,thDelay=0和mod=lstar(x,m=2,d ...
library(tsDyn)
data=read.table("data.txt", header = TRUE)
x <- data$cpi
y <- data$rpi
z <- data$m2
mod=lstar(x,m=2,d=1,control=list(maxit=3000))
mod

Non linear autoregressive model

LSTAR model
Coefficients:
Low regime:
    const1     phi1.1     phi1.2
1.3866542  0.5369498 -0.4856777

High regime:
    const2     phi2.1     phi2.2
15.6621561  0.2037306 -0.5327252

Smoothing parameter: gamma = 22.35

Threshold
Variable: Z(t) = + (1) X(t) + (0) X(t-1)

Value: 6.348

mod1=lstar(x,m=3,d=1,thVar=z,control=list(maxit=3000))
mod1

Non linear autoregressive model

LSTAR model
Coefficients:
Low regime:
   const1    phi1.1    phi1.2    phi1.3
-0.739900  1.852660 -1.256096  0.731050

High regime:
    const2     phi2.1     phi2.2     phi2.3
2.7868699 -1.0567380  1.0397138 -0.8612963

Smoothing parameter: gamma = 330

Threshold
Variable: external
Value: 0.2821

mod1$model.specific$thVar
[1]  0.26524514  0.31278198  0.37310154  0.34529154  0.29467111 -0.03867458
[7]  0.34668927  0.17245702  0.14411363 -0.31433668  0.87572994  0.16337324
[13]  0.19679602  0.18161695  0.14387323  0.18886459

163
epoh 发表于 2012-4-14 15:06:54
雁茗轩 发表于 2012-4-14 13:35
老师,数据和程序在160楼,麻烦您看一下我的问题在哪里,万分感谢了,着急用啊!
library(tsDyn)
nan=read.table("cpo.txt", header = TRUE)
y=nan$CP
x=nan$Oil
mod=lstar(y,m=3,d=1,thVar=x,control=list(maxit=3000))
mod

Non linear autoregressive model

LSTAR model
Coefficients:
Low regime:
      const1       phi1.1       phi1.2       phi1.3
0.213101468  0.311218447 -0.147596767  0.003313981

High regime:
    const2     phi2.1     phi2.2     phi2.3
-0.2364208 -0.3765884  1.7958783  0.3482814

Smoothing parameter: gamma = 34

Threshold
Variable: external
Value: 93.04

mod$model.specific$thVar
  [1]  19.72  20.72  24.53  26.18  27.04  25.52  26.97  28.39  29.66  28.84

164
雁茗轩 发表于 2012-4-14 15:36:42
epoh 发表于 2012-4-14 15:06
library(tsDyn)
nan=read.table("cpo.txt", header = TRUE)
y=nan$CP
真是太感谢您了,epoh老师!!可是为什么我的就是估计不出来呢?难道是R软件中安装的有问题?还有,老师可否把程序或者估计出来的残差贴给我呢,谢谢啦!还有,我看帖子前面您和别的坛友交流时可以计算参数t值和标准差等,为什么我的也出来这些东西呢?谢谢啦!

165
epoh 发表于 2012-4-14 15:53:03
雁茗轩 发表于 2012-4-14 15:36
真是太感谢您了,epoh老师!!可是为什么我的就是估计不出来呢?难道是R软件中安装的有问题?还有,老师可 ...
最重要的是,要在你的电脑能运行,才能进行研究工作
我的版本是
R version 2.15.0
tsDyn Version: 0.8-1

你先执行看看有问题再说

166
雁茗轩 发表于 2012-4-14 15:59:50
epoh 发表于 2012-4-14 15:53
最重要的是,要在你的电脑能运行,才能进行研究工作
我的版本是
R version 2.15.0
好的,我重新安装一下试试……

167
iooo 发表于 2012-4-14 17:15:38
epoh 发表于 2010-10-1 08:54
package "tsDyn"
本身就有function lstar
可估Logistic STAR model
请教epoh,
Splus 与R包tsDyn中的LSTAR 模型估计出来的 gamma差异在哪里?
其它参数差不多,但gamma似乎算的不是一个gamma。
比如lynx数据
Splus:      STAR(log10(lynx),p=2,d=2)
R:         lstar(log10(lynx),m=2,thDelay=1)      

168
iooo 发表于 2012-4-14 17:40:56
iooo 发表于 2012-4-14 17:15
请教epoh,
Splus 与R包tsDyn中的LSTAR 模型估计出来的 gamma差异在哪里?
其它参数差不多,但gamma似乎 ...
貌似 tsDyn直接给出的是 1/(1+exp(-gamma * (z-th))) 中的gamma
Splus 给出的是 1/(1+exp(-gamma/sd(z) *(z-th))) 中的gamma

169
epoh 发表于 2012-4-14 19:22:18
iooo 发表于 2012-4-14 17:40
貌似 tsDyn直接给出的是 1/(1+exp(-gamma * (z-th))) 中的gamma
Splus 给出的是 1/(1+exp(-gamma/sd(z)  ...
呵呵,iooo兄是行家.
的确是这样.
Transition function

  R: 1/(1+exp(-gamma * (z-th)))
  Splus : 1/(1+exp(-gamma/sd(z) *(z-th)))
  Splus 多了个transition.scale  gamsc=stdev(z)

不过我个人觉得R比较正确
R是用grid search 来寻找gamma
这点可由fitted.values看得出来
个人观点仅供参考

170
epoh 发表于 2012-4-14 19:37:48
雁茗轩 发表于 2012-4-14 15:36
真是太感谢您了,epoh老师!!可是为什么我的就是估计不出来呢?难道是R软件中安装的有问题?还有,老师可 ...
library(tsDyn)
nan=read.table("cpo.txt", header = TRUE)
y=nan$CP
x=nan$Oil
mod=lstar(y,m=2,d=1,thVar=x,control=list(maxit=3000))
mod
xxL=cbind(1,mod$str$xx)
xxH=xxL
yy=mod$str$yy
z=mod$model.specific$thVar
gamma=mod$coefficients[7]
th=mod$coefficients[8]

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

#lm.fit(cbind(xxL, xxH * G(z, gamma, th)), yy)

calc.lm.t <- function(x)
{
   Qr <- x$qr
   r <- x$residuals
   p <- x$rank
   p1 <- 1L:p
   rss <- sum(r^2)

   n <- NROW(Qr$qr)
   rdf <- n - p

   resvar <- rss/rdf
   R <- chol2inv(Qr$qr[p1, p1, drop = FALSE])
   se <- sqrt(diag(R) * resvar)

   est <- x$coefficients[Qr$pivot[p1]]
   tval <- est/se

   res <- cbind(est = est, se = se, tval = tval)
   res
}
lmf <- lm.fit( cbind(xxL, xxH * G(z, gamma, th)), yy)
calc.lm.t(lmf)

#                  est            se                 tval
#           0.02619398 0.09426718  0.2778696
#V1/0   0.30976606 0.13298950  2.3292521
#V1/-1 -0.13333347 0.13577256 -0.9820355
#          0.25543047 0.12957109  1.9713539
#V1/0  -0.07042287 0.18376493 -0.3832226
#V1/-1  0.10601972 0.18798123  0.5639910

mod
Non linear autoregressive model

LSTAR model
Coefficients:
Low regime:
     const1      phi1.1      phi1.2
0.02619145  0.30976991 -0.13333290

High regime:
     const2      phi2.1      phi2.2
0.25543391 -0.07042918  0.10601783

Smoothing parameter: gamma = 12.42

Threshold
Variable: external
Value: 56.38

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

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