# How to include seasonality in a state space model?

I am working on learning state space models and am leaning heavily on this very helpful documentation. However, I’m really confused about the best way to include both a seasonal effect and dynamic regressors into the model.

Let’s further assuming that I want to use a simulation smoother to estimate the coefficients on the dynamic regressors, so I won’t be estimating the coefficients in the `model` block

My initial thought was to do something like the following (with the seasonal effect specified as dummy variables that sum to 1)

``````
y ~ normal(seasonal_effect, sigma)
y_prime = y - seasonal_effect
target += ssm_lpdf(y_prime | ...) // system matrices go here

``````

The issue that I’m having with this specification is that:

1. It doesn’t estimate any kind of seasonal effect even though my model clearly has one
2. It’s estimating the dynamic linear model and the seasonal effect separately when they should seemingly be estimated together

From the available literature it seems that I should be able to code the seasonal effect directly into the system matrices, but I have no idea how.

1. If I put the seasonal dummies into the `Z` (or `F`, depending on the literature) design matrix, they are treated as a dynamic regressor, unless…
2. I restrict the state selection covariance matrix to only allow the non-seasonal dummies to evolve over time, but then the state estimates that I get from the seasonal dummies stay fixed at the values that I pass into the simulation smoother (as `a1`)

The libraries and models that I’m working with are very very clear once you have the system matrices specified, but I am lost on how to include seasonal effects into the system matrices of the dynamic linear model

Any help would be appreciated!

1 Like

There is a state space model with seasonality here:

I typically start with that one since it’s easier for me to wrap by head around it.

Hi Ara, thank you. I also started with these models, but they estimate the time-varying regression coefficients and seasonality effects in the `model` block, which is what I’m trying to avoid. I’m trying to use the kalman filter/smoother to estimate the effects (in the `generated quantities` block, as opposed to writing the state equations as sampling statements). Thanks to the models you reference, it’s very clear how to write the seasonality component (and time-varying coefficients) directly. What I’m not clear on is how to encode the seasonality effects into the system matrices that go into the kalman filter/smoother.

1 Like