#
# DCM Lite Code
#
SSinnov <- function(F. = NULL, G = NULL, H = NULL, K = NULL, z0 = NULL, input.names = NULL, output.names = NULL,...) UseMethod("SSinnov")
SSinnov.matrix <- function(F. = NULL, G = NULL, H = NULL, K = NULL, z0 = NULL, input.names = NULL, output.names = NULL,...) {
require(matlab)
if (is.null(F.) )
stop("System Matrix F must be specified as a matrix.")
m <- ncol(G)
n <- nrow(F.)
p <- nrow(H)
if (n != ncol(F.))
stop("Model F matrix must be square.")
if (is.null(H)) H <- eye(n-1,n)
if (n != ncol(H))
stop("Model H matrix have second dimension consistent with matrix F.")
if (is.null(K)) K <- F.[,1:(n-1),drop=FALSE]
model <- list(F = F., G = G, H = H, K = K,
z0 = z0, P0 = NULL, rootP0 = NULL, constants = NULL,
description = "SS innovation model")
class(model) <- c("innov", "SS", "TSmodel")
return(model)
}
SSnonInnov <- function(F. = NULL, G = NULL, H = NULL, Q = NULL,
R = NULL, z0 = NULL, input.names = NULL, output.names = NULL,...) UseMethod("SSnonInnov")
SSnonInnov.matrix <- function(F. = NULL, G = NULL, H = NULL, R = NULL, Q = NULL, z0 = NULL, input.names = NULL,
output.names = NULL,...) {
require(matlab)
if (is.null(F.) )
stop("System Matrix F must be specified.")
m <- ncol(G)
n <- nrow(F.)
p <- nrow(H)
if (n != ncol(F.))
stop("Model F matrix must be square.")
if (is.null(H)) H <- eye(n-1,n) # Assumes constant in F
if (n != ncol(H))
stop("Model H matrix have second dimension consistent with matrix F.")
if (is.null(Q)) Q <- eye(n,n-1)
if (is.null(R)) R <- eye(n-1,n-1)
if (nrow(Q)!=n || ncol(Q)!=(n-1)) stop("Model Q matrix dimensions inconsistent with matrix F.")
if (nrow(R)!=(n-1) || ncol(R)!=(n-1)) stop("Model R matrix dimensions inconsistent with matrix F.")
model <- list(F = F., G = G, H = H, R=R, Q=Q,
z0 = z0, P0 = NULL, rootP0 = NULL, constants = NULL,
description = "SS nonInnov Model")
class(model) <- c("nonInnov", "SS", "TSmodel")
return(model)
}