Comments (7)
See my reply in this issue: #20, the overdispersion parameters are part of model$u
.
from kfas.
I think I've misunderstood model$u as the offset term ( I found a non-english website falsely describing model$u as an offset term.)
Then, is there a way to add an offset term to the model?
from kfas.
Due to poor design choices model$u
corresponds to different things depending on the respective distribution, e.g. it's an offset in Poisson, a number of trials in binomial, and a dispersion parameter in negative binomial. If you want to use offset in a negative binomial case you can add log(offset) as an explanatory variable to the model, and set the corresponding initial state distribution to constant N(1, 0). So something like this:
model <- SSModel(
y ~ -1 + SSMregression(~ x + log_offset, a1 = c(0, 1), P1inf = diag(c(1, 0))),
distribution = "negative binomial")
from kfas.
Thank you very much. I'm having difficulty reconstructing my model following your instruction
In my model, I want time-varying intercepts as well as time-varying coefficients for up to 2 variables
I used models as below:
Intercept term: "-1" in your example to "SSMtrend(1, Q=NA)"
Regression term: ~x1(+x2)+log_offset, a1=c(0, (0,) 1), P1inf=diag(1, (1,) 0), Q=diag(c(NA, (NA,) 0)
update function: updatefn <- function(pars, model){
model$Q[1,1,] = exp(pars[1])
model$Q[2,2,] = exp(pars[2])
(model$Q[4,4,] = exp(pars[3]))
model$u[,] = exp(pars[4])
return(model)
}
when I run 1 or 2-variable models, I get model$u with like 10^12 order, which seems not reasonable for a dispersion parameter.
Please let me know if I'm doing something wrong here.
from kfas.
Hard to know without the actual reproducible example, but I would double-check that the elements of Q
and P1inf
match with the order of the states (e.g. by checking the state names in model$a1
). It could also be due to bad initial values for the optimization which causes the dispersion parameter to wander toward infinity.
from kfas.
Sorry that I cannot give you details about my data.
At least I confirmed that the Q and P1 inf match, and that the coefficients for the offset term are fixed to 1 (as expected).
At this point, seems like I have to find another way to do this analysis. (At least I've successfully obtained regression results of time-varying regression when using log-transformed "rates" instead of handling data as count data)
Thank you very much for your help anyway.
from kfas.
Assuming there is no errors in your code and no bugs in KFAS, then what your results mean is that essentially there is no overdispersion and you could just use Poisson distribution, as such a large dispersion parameter means that NB tends towards Poisson with mean=var. Running a Poisson version of the model should then lead to very similar results.
You could also test the bssm
package to see whether the its NB model gives similar results (it also directly supports offsets).
from kfas.
Related Issues (20)
- Handle intercepts in the model HOT 6
- Model non-gaussian multivariate outcome HOT 5
- Positive log likelihood for Poisson and Binomial distribution 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
- 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.