雁茗轩 发表于 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