Description Usage Arguments Details Value Author(s) See Also Examples
Does Kalman filtering followed by smoothing using
KFS for gaussian state
space models otherwise by use of logLik.SSModel.
1 |
ss |
object of class |
tvar |
vector with four elements indicating the dynamic nature of
matrices in the object |
offset |
vector of length equal to length of observations. |
The Kalman filter and smoother in KFAS provides faster computations than kfilter and smoother, however requires alternative specification of the state space model. This function transform the object SSon which Kalman filtering followed by smoothing using KFS may be performed.
List with two objects. The first object, kfas, is the output
from KFS. The second object, ss, of class SS with updated m, C and loglik.
Anette Luther Christensen and Claus Dethlefsen.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | ## Gaussian model to simulate observations from
m1 <- SS( Fmat = function(tt, x, phi) {
Fmat <- matrix(NA, nrow=3, ncol=1)
Fmat[1,1] <- 1
Fmat[2,1] <- cos(2*pi*tt/12)
Fmat[3,1] <- sin(2*pi*tt/12)
return(Fmat)
},
Gmat = function(tt, x, phi) {
matrix(c(1,0,0,0,1,0,0,0,1), nrow=3)
},
Wmat = function(tt, x, phi) {
matrix(c(0.01,0,0,0,0.1,0,0,0,0.1), nrow=3)},
Vmat = function(tt, x, phi) {matrix(1)},
m0 = matrix(c(0,0,0), nrow=1),
C0 = matrix(c(1,0,0,0,0.001,0,0,0,0.001), nrow=3, ncol=3)
)
## Simulates 100 observation from m1
m1 <- recursion(m1, 100)
## Formulates model og class ssm
ssm1 <- ssm(m1$y ~ -1 + tvar(polytime(1:m1$n),1)
+ tvar(polytrig(1:m1$n, 1)),
family="gaussian", fit=FALSE)
#smoothed <- Fkfs(ssm1$ss, tvar=c(m1$n, 1, 1, 1))
smoothed <- kfs(ssm1$ss, tvar=c(m1$n, 1, 1, 1))
## Non Gaussian model
phi.start <- StructTS(log10(UKgas),type="BSM")$coef[c(4,1,2,3)]
gasmodel <- ssm( log10(UKgas) ~ -1+ tvar(polytime(time,1))+
tvar(sumseason(time,4)), phi=phi.start, fit=FALSE)
#smoothed <- Fkfs(gasmodel$ss,tvar=c(1,1,1,1))
smoothed <- kfs(gasmodel$ss,tvar=c(1,1,1,1))
## Trend plot
## Trend plot
#ts.plot( smoothed$kfas$alphahat[1,] )
## Season plot
#ts.plot( smoothed$kfas$alphahat[3,] )
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.