Skip to content

Commit

Permalink
Corrected a major bug in SSMcycle
Browse files Browse the repository at this point in the history
Basically SSMcycle gave wrong system matrix T for all models, as
nondiagonal entries contained - sign in wrong place... No idea how this
has been unnoticed for so long.
  • Loading branch information
helske committed Apr 24, 2014
1 parent a6f6063 commit 99b0dd1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Changes from Version 1.0.3 to 1.0.4:
* Corrected a bug in approximation algorithm which caused the approximation to fail for seemingly
random models.
* Fixed a bug in SSMcycle which caused error with common components.
* Fixed bug in SSMcycle which resulted erroneus system matrix T in all cases.
* Fixed a bug in SSMseasonal which caused error in SSModel when using common components.
* SSMseasonal with trigonometric seasonal now works properly when period is odd.
* Fixed a bug in coef.KFS which caused function to return smoothed states even with argument
Expand Down
6 changes: 3 additions & 3 deletions R/SSMcycle.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ SSMcycle <- function(period, type, Q, index, a1, P1, P1inf, n, ynames) {
stop("type must be 'distinct' or 'common'.")
}

if (!(length(period) == 1 & period > 1 & abs(period - round(period)) == 0))
stop("period of the cycle component must be integer larger than 1. ")
if (!(length(period) == 1 & period > 0))
stop("Period of the cycle component must be larger than 0. ")


lambda <- 2 * pi/period
m <- 2 * ((p - 1) * (type == 1) + 1)
Z <- matrix(0, p, m)
T <- matrix(0, m, m)
Z_univariate <- matrix(c(1,0), 1, 2)
T_univariate <- matrix(c(cos(lambda), sin(lambda), -sin(lambda), cos(lambda)), 2, 2)
T_univariate <- matrix(c(cos(lambda), -sin(lambda), sin(lambda), cos(lambda)), 2, 2)
if (type != 2) {
for (i in 1:p) {
Z[i, ((i - 1) * 2 + 1):(i * 2)] <- Z_univariate
Expand Down
5 changes: 3 additions & 2 deletions R/predict.SSModel.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ predict.SSModel <- function(object, newdata, n.ahead, interval = c("none", "conf
}

} else {
if(!is.null(n.ahead) || !missing(n.ahead)){
if(!missing(n.ahead) && !is.null(n.ahead)){

tv <- logical(5)
tv[1] <- dim(object$Z)[3] > 1
Expand Down Expand Up @@ -203,7 +203,8 @@ predict.SSModel <- function(object, newdata, n.ahead, interval = c("none", "conf
}
out <- KFS(model = object, smoothing = "signal",maxiter=maxiter)
for (i in 1:p) {
pred[[i]] <- cbind(fit=out$thetahat[timespan, i]+(if(object$distribution[i]=="poisson") log(object$u[timespan, i]) else 0),
pred[[i]] <- cbind(fit=out$thetahat[timespan, i]+
(if(object$distribution[i]=="poisson") log(object$u[timespan, i]) else 0),
switch(interval, none = NULL, out$thetahat[timespan, i] +
(if(object$distribution[i]=="poisson") log(object$u[timespan, i]) else 0) +
qnorm((1 - level)/2) * sqrt(out$V_theta[i, i, timespan]) %o% c(1, -1)),
Expand Down

0 comments on commit 99b0dd1

Please sign in to comment.