Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Estimating the dispersion parameter for the negative binomial #20

Closed
andrewbcooper opened this issue Mar 30, 2017 · 3 comments
Closed

Comments

@andrewbcooper
Copy link

Hello! I've been exploring KFAS for a few days now, and it's simply amazing! Thank you for creating it! One thing I have yet to figure out how to do is estimate the dispersion parameter for the negative binomial. u(t) appears to be set to 1 when I fit the model with fitSSM. For now, I have:

model2 <- SSModel(TERMS_ts ~ SSMseasonal(period=12,Q=NA,sea.type = c("dummy")) + SSMtrend(degree=2,Q = list(matrix(NA), matrix(NA))),distribution="negative binomial")

fit_silly2 <- fitSSM(model2,inits=c(rep(0,13)))

When I extract fit_silly2$model$u, it's just a time-series of 1s.

Is there a way to have the model estimate the dispersion parameter as well? My understanding is that I need this in order to estimate a function (e.g., sum of the observations from the most recent 4 time points) of the prediction values (e.g., apply the negative binomial observation model to the signals produced from the importanceSSM())

Thank you for your help!

@helske
Copy link
Owner

helske commented Apr 3, 2017

By default, the fitSSM function estimates only unknown parameters in Q and H (in Gaussian case), and in general you need to provide your own function which updates the model given the parameters. So something like this:

updatefn <- function(parameters, model) {
  model$Q[1,1,1] <- exp(parameters[1])
  model$Q[2,2,1] <- exp(parameters[2])
  model$Q[3,3,1] <- exp(parameters[3])
  model$u[] <- exp(parameters[4])
  model
}
fit <- fitSSM(model, updatefn=update, inits=c(0,0,0,0))

@andrewbcooper
Copy link
Author

Thank you so much! I think the difference between a "state" (e.g., level, slope, 11 seasonal dummy variables) and a "parameter" was confusing me. Thanks again!

@helske
Copy link
Owner

helske commented Apr 7, 2017

Yeah, the states are estimated automatically by Kalman filter and smoother, whereas you need to use numerical optimization for the parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants