GithubHelp home page GithubHelp logo

Comments (7)

helske avatar helske commented on July 19, 2024

See my reply in this issue: #20, the overdispersion parameters are part of model$u.

from kfas.

 avatar commented on July 19, 2024

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.

helske avatar helske commented on July 19, 2024

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.

 avatar commented on July 19, 2024

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.

helske avatar helske commented on July 19, 2024

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.

 avatar commented on July 19, 2024

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.

helske avatar helske commented on July 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.