SSブログ

R: KFASによるポアソン分布の状態空間モデル [統計]

KFASパッケージで、ポアソン分布の状態空間モデルをやってみる。

data(discoveries)をつかう。

##
## KFAS
##
library(KFAS)

data(discoveries)

まずは、SSMtrendのdegree=1にて。

model <- SSModel(discoveries ~ SSMtrend(degree = 1, Q = list(matrix(NA))),
                 distribution = "poisson")
fit <- fitSSM(model, inits = c(1), method = "BFGS")
out <- KFS(fit$model, smoothing = c("signal", "invlink"), nsim = 0)
conf <- predict(fit$model, interval = "confidence", nsim = 1000)

plot(discoveries, las = 1)
lines(conf[, 1], col = 2)
lines(conf[, 2], col = 2, lty = 2)
lines(conf[, 3], col = 2, lty = 2)

結果
Rplot04.png

つづいて、SSMtrendのdegree=2にて。

##
model2 <- SSModel(discoveries ~ SSMtrend(degree = 2,
                                         Q = list(matrix(NA), matrix(NA))),
                 distribution = "poisson")
fit2 <- fitSSM(model2, inits = c(1, 1), method = "BFGS")
out2 <- KFS(fit2$model, filtering = "invlink", nsim = 0)
conf2 <- predict(fit2$model, interval = "confidence", nsim = 1000)

plot(discoveries, las = 1)
lines(conf2[, 1], col = 2)
lines(conf2[, 2], col = 2, lty = 2)
lines(conf2[, 3], col = 2, lty = 2)

結果
Rplot05.png


タグ:R
nice!(0)  コメント(0)  トラックバック(0) 
共通テーマ:日記・雑感

nice! 0

コメント 0

コメントを書く

お名前:
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

Facebook コメント

トラックバック 0