Comments (6)
Yes, there are no separate intercept terms in KFAS. What you can do is to add an extra time-invariant (Q=0) state variables C and D to the state vector a, using SSMcustom
. Then C and D will be estimated "automatically" via Kalman filter.
Another option is to use bssm package which directly supports intercepts (see ?ssm_ulg
for an example).
from kfas.
"What you can do is to add an extra time-invariant (Q=0) state variables C and D to the state vector a, using SSMcustom. Then C and D will be estimated "automatically" via Kalman filter."
But in this way, C and D will be different for the two series, since there are two models.
I will try the bssm package. Thank you!
from kfas.
Ah, yes, but you can also build a bivariate model with common C, D etc and estimate that directly instead of two separate models.
from kfas.
The length of two series is different, and the Z_t is time-dependent (but is known and different for each series) in my case. Not sure whether it is possible to build one bivariate model. If I build one model, I have to assign many NA's in Z_t for the shorter series. Is it an appropriate way? Can you give some hints?
Thank you.
from kfas.
Yes if you add NA to the end of shorter y_t then the corresponding value in Z is also ignored. Here is a quick sketch:
set.seed(1)
n1 <- 50
n2 <- 30
z1 <- sin(1:n1)
z2 <- cos(1:n2)
C <- 0.6
D <- -0.4
# random walk with drift D
x1 <- cumsum(rnorm(n1) + D)
x2 <- cumsum(rnorm(n2) + D)
y1 <- rnorm(n1, z1 * x1 + C * 1)
y2 <- rnorm(n2, z2 * x2 + C * 2)
library(KFAS)
n <- max(n1, n2)
Y <- matrix(NA, n, 2)
Y[1:n1, 1] <- y1
Y[1:n2, 2] <- y2
Z <- array(0, c(2, 4, n))
Z[1, 1, 1:n1] <- z1
Z[2, 2, 1:n2] <- z2 # trailing zeros are ok, as corresponding y is NA
Z[1, 3, ] <- 1 # x = 1
Z[2, 3, ] <- 2 # x = 2
# last state is only used in state equation so zeros in Z
T <- diag(4) # a1_t for y1, a2_t for y2, C, D
T[1, 4] <- 1 # D affects a_t
T[2, 4] <- 1 # D affects a_t
Q <- diag(c(NA, NA, 0, 0))
P1inf <- diag(4)
model <- SSModel(Y ~ -1 + SSMcustom(Z = Z, T = T, Q = Q, P1inf = P1inf,
state_names = c("a1", "a2", "C", "D")), H = diag(NA, 2))
updatefn <- function(pars, model) {
model$Q[] <- diag(c(exp(pars[1]), exp(pars[1]), 0, 0))
model$H[] <- diag(exp(pars[2]), 2)
model
}
fit <- fitSSM(model, inits = rep(-1, 2), updatefn = updatefn)
fit$model$Q[1] #0.2542451
KFS(fit$model)
Smoothed values of states and standard errors at time n = 50:
Estimate Std. Error
a1 -15.27620 0.86116
a2 -12.35175 2.81083
C 0.55220 0.08223
D -0.27226 0.06152
from kfas.
I see. That is helpful!
from kfas.
Related Issues (20)
- Model non-gaussian multivariate outcome HOT 5
- Positive log likelihood for Poisson and Binomial distribution HOT 5
- How to predict more time series HOT 1
- Wrong convergence without warnings or errors HOT 15
- Requesting State Offset Term or Control Input specification HOT 2
- KFS function HOT 4
- Change .f95 suffix to .f90 HOT 1
- Exact diffuse intialisation HOT 3
- Exogenous variable
- Documentation: "more complex model" example HOT 2
- Returning Importance Samples in predict.SSModel HOT 3
- How to extract time varying coefficients and CIs corresponding to each variable in SSMregression HOT 2
- How to extract the overdispersion parameters in regression models assuming negative binomial distribution HOT 7
- Poor time variability of time-varying regression coefficients and Inconsistency of param estimates among methods in fitSSM HOT 9
- Standardized residuals HOT 6
- Difficulty with setting a1 and P1 when using SSMseasonal and reduced number of harmonics HOT 1
- Question building an Ar(2) model HOT 6
- same Log Likelihood of different SSModel HOT 6
- Kalman filter HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kfas.