I'm having a bit of trouble with my state space model fit (using KFAS package) when I include a seasonal component in the model. The computations don't seem to end when I include (what I believe is) the frequency of the seasonality in the seasonal component of the model.

So heres what my data Looks like.. The response variable is count data, basically the number of animals at a site. I have 10 of these sites, and each month from 1997-2014 I make an observation at each site and record the number of animals. So 10 observations in total for 10 sites in 1 month. So in total I have 2160 data points.

Now I want to capture the 'seasonality' in the data, because I know that I'll have higher counts during summer months than I will during the winter months. So in 1 year, I've taken 120 observations.. what i've been doing up until this post is setting the frequency of my seasonality as 120. To me it seems correct, but the computation seems to be very intensive so I have a feeling I may be wrong.

Any suggestions?

I also had another idea in mind, but im not sure if its a valid approach. Since my response is count data, it follows a poisson distribution (non-gaussian), if I were to decompose the data into trend,error and seasonal components, could I be able to model just the trend+error and assume its under a gaussian distribution? (thus completely removing the seasonality from my analysis)

Thanks for your help.

  • $\begingroup$ are you asking for how to parametrize the model to include seasonal components? Or are you asking for code help? $\endgroup$
    – Taylor
    Commented Jul 20, 2017 at 21:55
  • $\begingroup$ more so how to parametrize the model @Taylor $\endgroup$ Commented Jul 20, 2017 at 22:03
  • $\begingroup$ As currently described, you seem to neglecting the spatial correlations in you data i.e. you have 10 time series, each of them with a period of 12 months. Not 1 site with a time period of 1200. $\endgroup$
    – mkt
    Commented Jul 21, 2017 at 14:40
  • $\begingroup$ I see what you mean.. I'm essentially just trying to fit some sort of dynamic linear model such that I can include regressors of interest, determine their coefficients at each time step and plot the change. But fitting 10 different models,1 for each site, seems a little tedious. Do you suggest I model the data as a multivariate(response) state space/dynamic linear model? $\endgroup$ Commented Jul 21, 2017 at 16:52
  • $\begingroup$ And in regards to spatial correlation, I've created a new predictor variable to act as kind of a 'penalty' in a sense; using the spatial coordinates of each site and a nearest neighbours algorithm i've given a 'weight' to each site. $\endgroup$ Commented Jul 21, 2017 at 17:01

1 Answer 1


I'll use the notation from the KFAS vignette and the KFAS paper.

If you had, say, two known angular frequencies $\omega_1$ and $\omega_2$, you could set the state transition matrix to $$ T_t = T = \left[\begin{array}{ccccc} 1 & 0 & 0 & 0 & 0\\ 0 & \cos(\omega_1) & \sin(\omega_1 ) & 0 & 0 \\ 0 & -\sin(\omega_1) & \cos (\omega_1) & 0 & 0\\ 0 & 0 & 0 & \cos(\omega_2) & \sin(\omega_2) \\ 0 & 0 & 0 & -\sin(\omega_2 ) & \cos(\omega_2) \end{array}\right], $$ and, if you had a univariate response, the observation matrix to $$ Z_t = Z = [1 1 0 1 0]. $$ In the case of a multivariate response, where all the dependent variables share the same mean, you could set the observation matrix to $$ Z_t = \left[ \begin{array}{c} 1 \\ 1\\ \vdots \\ 1 \end{array}\right] [1 1 0 1 0]. $$

The first state element would represent a time-varying intercept, and the rest would represent (suitably transformed) time-varying phases and amplitudes.

For example, if you have monthly data, and you expect there is a quarterly cycle, that is once every three months, so you would set one of your angular frequencies to be $$ \omega_i = 2 \pi \frac{1}{3}. $$

More information for this type of state space model can be found in Bayesian Forecasting and Dynamic Models.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.