Appendix A. The forward filtering backward smoothing algorithm.

1) Forward filtering algorithm: The posterior and one-step forecast distribution in the NDLM can be calculated as follows:

a) Posterior at time

t- 1: for some meanm_{t-1}and varianceC_{t-1},x_{t-1}|D_{t-1}N[m_{t-1},C_{t-1}].b) Prior at time

t:x_{t}|D_{t-1}N[a_{t},R_{t}], wherea_{t}=gm_{t-1}andR_{t}=g^{2}C_{t-1}+W.c) One-step forecast:

y_{t}|D_{t-1}N[s_{t},Q_{t}], wheres_{t}=fa_{t}andQ_{t}=f^{2}R_{t}=V.d) Posterior at time

t:x_{t}|D_{t}N[m_{t},C_{t}], withm_{t}=a_{t}+A_{t}e_{t}andC_{t}=R_{t}-A^{2}_{t}Q_{t}, whereA_{t}=R_{t}F/Q_{t}ande_{t}=y_{t}-s_{t}.

2) Backward smoothing algorithm:
Given that *p*(*x*_{t}|*D*_{t})
*N*[*m*_{t}, *C*_{t}],
for all *k* such that 1 *k*
*t*, the filtering marginal distributions are

*x*_{t-k}|*D*_{t}
*N*[*a*_{t}(-*k*),
*R*_{t}(-*k*)]

where *B*_{t}
= *C*_{t}*gR*^{-1}_{t+1}, *a*_{t}(-*k*)
= *m*_{t-k} + *B*_{t-k}[*a*_{t}(-*k*
+ 1) - *a*_{t-k+1}], and *R*_{t}(-*k*)
= *C*_{t-k}+*B*_{t-k}[*R*_{t}(-*k*+1)
- *R*_{t-k+1}]*B*'_{t-k}

with starting values *a*_{t}(0)
= *m*_{t} and *R*_{t}(0) = *C*_{t},
and where *a*_{t-k}(1) = *a*_{t-k+1}
and *R*_{t-k}(1) = *R*_{t-k+1}.