helske / KFAS

KFAS: R Package for Exponential Family State Space Models
64 stars 17 forks source link

Can't calculate multivariate time-series #43

Closed ymatsumotomatsu closed 4 years ago

ymatsumotomatsu commented 4 years ago

Hello. I've been working on estimating coordinates with kalman filter.

I can't calculate estimated values of one of multivariate time-series. Time-series have no missing value and its sizes are same.

Code: library(KFAS)

cam1 <- read.table("cam1.dat", header = T) cam2 <- read.table("cam2.dat", header = T)

x1 <- ts(cam1$x) x2 <- ts(cam2$x)

modSUTSE <- SSModel(cbind(x1,x2) ~ SSMtrend(1, Q = matrix(NA,2,2), type = "distinct"), H = matrix(NA,2,2)) fitSUTSE <- fitSSM(modSUTSE, numeric(6), method="BFGS") kfsSUTSE <- KFS(fitSUTSE$model)

afilt <- kfsSUTSE$alphahat[1:554,]

plot(x1,lty=3,xlab="フレーム",ylab="距離") lines(afilt[,1],lwd=2)

plot(x2,lty=3,xlab="フレーム",ylab="距離") lines(afilt[,2],lwd=2)

Result: Rplot02 Rplot03

And, I can't calculate if I replace x1 with x2 as well. Rplot04 Rplot05

How should I do this?

helske commented 4 years ago

Sorry, I would need reproducible example to understand what is wrong with your results. You might want to test different initial values to fitSSM to see if the results depend on those.

ymatsumotomatsu commented 4 years ago

This is data. Please rename .txt to .dat and run by code I pasted. cam1.txt cam2.txt

I tested different Q, H and found that I can't calculate when Q≪H.

helske commented 4 years ago

Different initial values help. Test for example fitSSM(modSUTSE, rep(-2,6), method="BFGS") and you get better optimum and the results look more reasonable.

helske commented 4 years ago

I guess this is solved?