I am unable to get KFAS::fitSSM to pass an optional argument to updateFn.
Consider the following:
remotes::install_github("sbgraves237/MaddisonData")
library(MaddisonData)
GBR <- subset(MaddisonData, (ISO=='GBR') & !is.na(gdppc))
grFmla <- (log(gdppc)~ -1 +
SSMbespoke(growthModel(.04, GBR$gdppc) ))
library(KFAS)
GBR2m <-SSModel(grFmla, GBR, H=matrix(NA) )
Now call KFAS::fitSSM and pass an optional argument Time:
GBRgrFit <- fitSSM(GBR2m, inits=-6, method = "BFGS",
updatefn = growthUpdateFn, Time=GBR$year)
MaddisonData::growthUpdateFn computes Q assuming missing observations
for gaps in Time:
GBR$year[1:4]
diff(GBR$year[1:4])
grUpdtChk <- growthUpdateFn(GBRgrFit$optim.out$par, GBR2m, Time=GBR$year)
grUpdtChk$Q[,,1:3]
#, , 1000
[,1] [,2]
#[1,] 4527.86795 27.0038933
#[2,] 27.00389 0.2151705
#, , 1252
[,1] [,2]
#[1,] 4527.86795 27.0038933
#[2,] 27.00389 0.2151705
#, , 1253
[,1] [,2]
#[1,] 0.0008538511 0.0000000000
#[2,] 0.0000000000 0.0008538511
However, this is NOT what KFAS::fitSSM returned:
GBRgrFit$model$Q[,,1:3]
# grUpdtChk$Q[,, 3] == GBRgrFit$model$Q[,, 3]
# but grUpdtChk$Q[,,1:2] != GBRgrFit$model$Q[,,1:2]
#, , 1
[,1] [,2]
#[1,] 0.0008538511 0.0000000000
#[2,] 0.0000000000 0.0008538511
#, , 2
[,1] [,2]
#[1,] 0.0008538511 0.0000000000
#[2,] 0.0000000000 0.0008538511
#, , 3
[,1] [,2]
#[1,] 0.0008538511 0.0000000000
#[2,] 0.0000000000 0.0008538511
NOTE that GBRgrFit$model$Q[,,1] == GBRgrFit$model$Q[,,2]
AND unique(diff(as.numeric(dimnames(GBRgrFit$model$Q)[[3]]))) are all 1.
BUT unique(diff(as.numeric(dimnames(grUpdtChk$Q)[[3]]))) are NOT all 1.
grUpdtChk$Q[,,1:3] - GBRgrFit$model$Q[,,1:3]
# because diff(GBR$year)[1] > 0
#, , 1000
[,1] [,2]
#[1,] 4527.86710 27.0038933
#[2,] 27.00389 0.2143166
#, , 1252
[,1] [,2]
#[1,] 4527.86710 27.0038933
#[2,] 27.00389 0.2143166
#, , 1253
[,1] [,2]
#[1,] 0 0
#[2,] 0 0
A discussion of why growthUpdateFn computes Q this way is included in the documentation of that function.
HELP?
Thanks, Spencer Graves spencer.graves@effectiveDefense.org
I am unable to get
KFAS::fitSSMto pass an optional argument toupdateFn.Consider the following:
Now call
KFAS::fitSSMand pass an optional argumentTime:MaddisonData::growthUpdateFncomputes Q assuming missing observationsfor gaps in
Time:#, , 1000
[,1] [,2]
#[1,] 4527.86795 27.0038933
#[2,] 27.00389 0.2151705
#, , 1252
[,1] [,2]
#[1,] 4527.86795 27.0038933
#[2,] 27.00389 0.2151705
#, , 1253
[,1] [,2]
#[1,] 0.0008538511 0.0000000000
#[2,] 0.0000000000 0.0008538511
However, this is NOT what
KFAS::fitSSMreturned:#, , 1
[,1] [,2]
#[1,] 0.0008538511 0.0000000000
#[2,] 0.0000000000 0.0008538511
#, , 2
[,1] [,2]
#[1,] 0.0008538511 0.0000000000
#[2,] 0.0000000000 0.0008538511
#, , 3
[,1] [,2]
#[1,] 0.0008538511 0.0000000000
#[2,] 0.0000000000 0.0008538511
NOTE that
GBRgrFit$model$Q[,,1] == GBRgrFit$model$Q[,,2]AND
unique(diff(as.numeric(dimnames(GBRgrFit$model$Q)[[3]])))are all 1.BUT
unique(diff(as.numeric(dimnames(grUpdtChk$Q)[[3]])))are NOT all 1.#, , 1000
[,1] [,2]
#[1,] 4527.86710 27.0038933
#[2,] 27.00389 0.2143166
#, , 1252
[,1] [,2]
#[1,] 4527.86710 27.0038933
#[2,] 27.00389 0.2143166
#, , 1253
[,1] [,2]
#[1,] 0 0
#[2,] 0 0
A discussion of why growthUpdateFn computes Q this way is included in the documentation of that function.
HELP?
Thanks, Spencer Graves spencer.graves@effectiveDefense.org