Skip to main content
added tag 'time-series'
Link
javlacalle
  • 11.8k
  • 30
  • 56
added tag; formatted; light editing
Source Link
gung - Reinstate Monica
  • 147.5k
  • 89
  • 406
  • 717

Start up values for the Kalman Filterfilter


I I am trying to understand how the start up values (initialisation) are calculated in the Kalman filter. As an example, I simulated the MA(2) model below.

y

Extracted matrices needed for the Kalman Filter.
sigma2 <- fit$sigma2 T <- fit$model$T R <- c(1,fit$coef) Z <- t(fit$model$Z) I <- diag(9)

And calculated start up values for predicted state vector a_pred1 and variance P_pred1 as below,
A <- solve(I-kronecker(T, T)) vecc <- A%%vec(R%%t(R)) P_pred1 <- as.matrix(cbind(vecc[1:3],vec[4:6],vec[7:9])) a_pred1 <- c(0,0,0)

But I do not get the same start up values as produced by KalmanRun.
F <- as.numeric(Z%%P_pred1%%t(Z)) v <- as.numeric(y[i]-Z%%a_pred1) a_filt1 <- a_pred1 + P_pred1%%t(Z)*(F^-1)*v
kfrun <- KalmanRun(y, fit$model) cbind(kfrun$states[1,],a_filt1) [,1] [,2] [1,] 1.1964116 1.1964116 [2,] 0.7583928 0.6427514 [3,] 0.5353670 0.2493952

y <- arima.sim(n = 120, model = list(order = c(0,0,2), ma = c(0.6,0.4)))
fit <- arima(y, order = c(0,0,2), include.mean = FALSE)
Can any one explain what I am doing wrong in my calculations.

Extracted matrices needed for the Kalman Filter.

sigma2 <- fit$sigma2
T <- fit$model$T
R <- c(1,fit$coef)
Z <- t(fit$model$Z)
I <- diag(9)

And calculated start up values for predicted state vector a_pred1 and variance P_pred1 as below,

A <- solve(I-kronecker(T, T)) 
vecc <- A%*%vec(R%*%t(R))
P_pred1 <- as.matrix(cbind(vecc[1:3],vec[4:6],vec[7:9]))
a_pred1 <- c(0,0,0)

But I do not get the same start up values as produced by KalmanRun.

F <- as.numeric(Z%*%P_pred1%*%t(Z))
v <- as.numeric(y[i]-Z%*%a_pred1)
a_filt1 <- a_pred1 + P_pred1%*%t(Z)*(F^-1)*v   
kfrun <- KalmanRun(y, fit$model)
cbind(kfrun$states[1,],a_filt1)
          [,1]      [,2]
[1,] 1.1964116 1.1964116
[2,] 0.7583928 0.6427514
[3,] 0.5353670 0.2493952

Can any one explain what I am doing wrong in my calculations?

Start up values for the Kalman Filter


I am trying to understand how the start up values (initialisation) are calculated in the Kalman filter. As an example, I simulated the MA(2) model below.

y

Extracted matrices needed for the Kalman Filter.
sigma2 <- fit$sigma2 T <- fit$model$T R <- c(1,fit$coef) Z <- t(fit$model$Z) I <- diag(9)

And calculated start up values for predicted state vector a_pred1 and variance P_pred1 as below,
A <- solve(I-kronecker(T, T)) vecc <- A%%vec(R%%t(R)) P_pred1 <- as.matrix(cbind(vecc[1:3],vec[4:6],vec[7:9])) a_pred1 <- c(0,0,0)

But I do not get the same start up values as produced by KalmanRun.
F <- as.numeric(Z%%P_pred1%%t(Z)) v <- as.numeric(y[i]-Z%%a_pred1) a_filt1 <- a_pred1 + P_pred1%%t(Z)*(F^-1)*v
kfrun <- KalmanRun(y, fit$model) cbind(kfrun$states[1,],a_filt1) [,1] [,2] [1,] 1.1964116 1.1964116 [2,] 0.7583928 0.6427514 [3,] 0.5353670 0.2493952

Can any one explain what I am doing wrong in my calculations.

Start up values for the Kalman filter

I am trying to understand how the start up values (initialisation) are calculated in the Kalman filter. As an example, I simulated the MA(2) model below.

y <- arima.sim(n = 120, model = list(order = c(0,0,2), ma = c(0.6,0.4)))
fit <- arima(y, order = c(0,0,2), include.mean = FALSE)

Extracted matrices needed for the Kalman Filter.

sigma2 <- fit$sigma2
T <- fit$model$T
R <- c(1,fit$coef)
Z <- t(fit$model$Z)
I <- diag(9)

And calculated start up values for predicted state vector a_pred1 and variance P_pred1 as below,

A <- solve(I-kronecker(T, T)) 
vecc <- A%*%vec(R%*%t(R))
P_pred1 <- as.matrix(cbind(vecc[1:3],vec[4:6],vec[7:9]))
a_pred1 <- c(0,0,0)

But I do not get the same start up values as produced by KalmanRun.

F <- as.numeric(Z%*%P_pred1%*%t(Z))
v <- as.numeric(y[i]-Z%*%a_pred1)
a_filt1 <- a_pred1 + P_pred1%*%t(Z)*(F^-1)*v   
kfrun <- KalmanRun(y, fit$model)
cbind(kfrun$states[1,],a_filt1)
          [,1]      [,2]
[1,] 1.1964116 1.1964116
[2,] 0.7583928 0.6427514
[3,] 0.5353670 0.2493952

Can any one explain what I am doing wrong in my calculations?

Source Link
John
  • 41
  • 3

Start up values for the Kalman Filter


I am trying to understand how the start up values (initialisation) are calculated in the Kalman filter. As an example, I simulated the MA(2) model below.

y

Extracted matrices needed for the Kalman Filter.
sigma2 <- fit$sigma2 T <- fit$model$T R <- c(1,fit$coef) Z <- t(fit$model$Z) I <- diag(9)

And calculated start up values for predicted state vector a_pred1 and variance P_pred1 as below,
A <- solve(I-kronecker(T, T)) vecc <- A%%vec(R%%t(R)) P_pred1 <- as.matrix(cbind(vecc[1:3],vec[4:6],vec[7:9])) a_pred1 <- c(0,0,0)

But I do not get the same start up values as produced by KalmanRun.
F <- as.numeric(Z%%P_pred1%%t(Z)) v <- as.numeric(y[i]-Z%%a_pred1) a_filt1 <- a_pred1 + P_pred1%%t(Z)*(F^-1)*v
kfrun <- KalmanRun(y, fit$model) cbind(kfrun$states[1,],a_filt1) [,1] [,2] [1,] 1.1964116 1.1964116 [2,] 0.7583928 0.6427514 [3,] 0.5353670 0.2493952

Can any one explain what I am doing wrong in my calculations.