statespace {viking} | R Documentation |
Design a State-Space Model
Description
The function statespace
builds a state-space model, with known or unknown variances.
By default, this function builds a state-space model in the static setting, with a constant
state (zero state noise covariance matrix) and constant observation noise variance.
Usage
statespace(X, y, kalman_params = NULL, viking_params = NULL, ...)
Arguments
X |
design matrix. |
y |
variable of interest. |
kalman_params |
(default |
viking_params |
(default |
... |
additional parameters |
Value
a statespace object.
Examples
set.seed(1)
### Simulate data
n <- 1000
d <- 5
Q <- diag(c(0,0,0.25,0.25,0.25))
sig <- 1
X <- cbind(matrix(rnorm((d-1)*n,sd=1),n,d-1),1)
theta <- matrix(rnorm(d), d, 1)
theta_arr <- matrix(0, n, d)
for (t in 1:n) {
theta_arr[t,] <- theta
theta <- theta + matrix(mvtnorm::rmvnorm(1,matrix(0,d,1),Q),d,1)
}
y <- rowSums(X * theta_arr) + rnorm(n, sd=sig)
####################
### Kalman Filter
# Default Static Setting
ssm <- viking::statespace(X, y)
plot(ssm)
# Known variances
ssm <- viking::statespace(X, y, kalman_params = list(Q=Q, sig=sig))
plot(ssm)
[Package viking version 1.0.2 Index]