Comments (5)
It seems that the Gaussian approximation fails silently with exact diffuse initialization (using P1inf
) combined with your model structure. First of all, if you switch away from the exact diffuse initialization you get negative likelihood:
P1 <- matrix(0, ncol = 9, nrow = 9)
diag(P1)[1:3] <- 10000
m2<- SSModel(y ~ -1+SSMcustom(Z = Zt, T = Tt, R = Rt, Q = Qt, a1 = a1, P1 = P1), data = dat, distribution = 'binomial', u=u)
logLik(m2) # -12.7887
Let's simplify your model a bit by removing the constant states and reducing number of observations:
Tt <- diag(c(0.4434,0.9962,0.9996))
Qt <- diag(rep(3.3576,3))
P1inf <- matrix(0, ncol = 3, nrow = 3)
diag(P1inf)[1:3] <- 1
Zt <- matrix(c(1.2670, 1.2729, 0.5930), nrow = 1)
Rt <- diag(3)
a1 <- matrix(c(0, 0, 0), ncol = 1)
dat <- data.frame(y = c(0, 1, 1, 0))
u <- matrix(1, nrow = NROW(dat), ncol = 1)
m3 <- SSModel(y ~ -1+SSMcustom(Z = Zt, T = Tt, R = Rt, Q = Qt, a1 = a1, P1inf = P1inf), data = dat, distribution = 'binomial', u=u)
logLik(m3) # 42.27624
Still failing. Checking at the Gaussian approximation shows "convergence" to some extreme case:
> c(approxSSM(m3,tol=1e-16)$H)
[1] 7.954668e+16 7.319107e+25 1.705125e+16 3.266442e+16
> c(approxSSM(m3,tol=1e-16)$y)
[1] -39.91512 0.00000 42.00000 -39.02506
So essentially the Gaussian approximation suggests zero signal-to-noise ratio.
Without exact initialization things look quite different:
> m4 <- m3
> m4$P1inf[]<-0
> m4$P1[]<-diag(1e5, 3)
> c(approxSSM(m4)$H)
[1] 12.906387 7.094437 7.710829 5.496582
> c(approxSSM(m4)$y)
[1] -3.473307 2.791681 2.891019 -2.471853
So the diffuse initialization causes the Gaussian approximation to fail here. Even this simplified model is borderline nonidentifiable though given that the linear predictor Zalpha_t is a linear combination of multiple AR(1) processes, and second and third states are both almost random walks, and the observations are just ones and zeros, so essentially there isn't much information to be gained from the series compared to the very flexible three-state model without any knowledge of their initial values (i.e. diffuse initialization).
from kfas.
Thank you!
When I tried to use optim
to maximize the likelihood, then sometimes I will get these wired parameter that provide large (but wrong) likelihood.
Then my question is:
- Is there a way to determine whether the approximation fails or not? Since the
logLik
function does not give any warnings in this case. Maybe thatapproxSSM(model)$H
is too large indicates the failure? - If I want to estimate some parameters using
optim(fn=-logLik)
, are there any suggestions to make it get the right result? I tried different initial values (which provide correct and good likelihood) but it will stop at positive likelihood.
Thank you!
from kfas.
Yeah you probably need to check if the values of approxSSM(model)$H are very large. My initial though was to just check min(approxSSM(model)$H)
but that doesn't seem to work as some of the variances at the beginning are still ok in your example. Not sure if the maximum is too strict, probably not.
So, I would probably make a custom objective function for optim
, where you have something like
# create model
model <- ...
if(max(approxSSM(model)$H) > 1e100) {
Inf
} else {
-logLik
}
And yes you typically need to start with multiple initial values and pick the best, as the likelihood surface often contains multiple local optimums.
from kfas.
I now added an additional parameter for logLik
etc called H_tol
, which can be used to automatically detect overly large values of H
of the approximating model. If the largest variance of the model is bigger than the tolerance, logLik
returns -.Machine$double.xmax^0.75
. The updated version can be installed from the GitHub, and later this month from CRAN.
from kfas.
That works for me!! Thank you
from kfas.
Related Issues (20)
- Handle intercepts in the model HOT 6
- Model non-gaussian multivariate outcome HOT 5
- How to predict more time series HOT 1
- Wrong convergence without warnings or errors HOT 15
- Requesting State Offset Term or Control Input specification HOT 2
- KFS function HOT 4
- Change .f95 suffix to .f90 HOT 1
- Exact diffuse intialisation HOT 3
- Exogenous variable
- Documentation: "more complex model" example HOT 2
- Returning Importance Samples in predict.SSModel HOT 3
- How to extract time varying coefficients and CIs corresponding to each variable in SSMregression HOT 2
- How to extract the overdispersion parameters in regression models assuming negative binomial distribution HOT 7
- Poor time variability of time-varying regression coefficients and Inconsistency of param estimates among methods in fitSSM HOT 9
- Standardized residuals HOT 6
- Difficulty with setting a1 and P1 when using SSMseasonal and reduced number of harmonics HOT 1
- Question building an Ar(2) model HOT 6
- same Log Likelihood of different SSModel HOT 6
- Kalman filter HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kfas.