UCM with damped trend

Use this forum for posting example programs or short bits of sample code.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

UCM with damped trend

Unread post by TomDoan »

This is an example of the estimation (by maximum likelihood and by MCMC) of a state-space UCM model with a damped trend. Rather than the standard UCM assumption of a trend rate that's a random walk, this has a "trend stationary" trend rate, with an AR that shrinks back to a mean (where the target mean growth is also a free parameter).
dampedtrend.gif
dampedtrend.gif (1.69 KiB) Viewed 4337 times
As with pretty much any model of this type, three unconstrained shocks is too many. The maximum likelihood estimates are done with the constraint that all three variances be positive, and the epsilon ends up being zero. Note that that means the smoothed estimate of the trend is equal to the data itself which isn't likely to be what is desired. However, the likelihood is quite flat among all relatively small values for the eta and eps variances, which is clear when you estimate the model using MCMC.
dampedtrend.rpf
Program file
(7.55 KiB) Downloaded 811 times
de data.xls
Data file
(38 KiB) Downloaded 648 times
Note that the MCMC part uses some features added with RATS v9.1.

dec hash[hash[real]] sigparms
compute sigparms("eta")("var")=0.04,sigparms("eta")("df")=1.0
compute sigparms("eps")("var")=0.04,sigparms("eps")("df")=1.0
compute sigparms("xi")("var") =0.04,sigparms("xi")("df")=1.0

organizes the priors for the three variances using HASHes. That allows the use of a single function for doing the posterior draws:

function InvChisqrPost datass datadf prior
type real datass datadf
type hash[real] prior
*
compute InvChisqrPost=(datass+prior("var")*prior("df"))/%ranchisqr(datadf+prior("df"))
end

by just passing through the outer HASH:

compute sigsqxi=InvChisqrPost(sumsqxi,%nobs,sigparms("xi"))

The only parameter that doesn't have a straightforward sampler is the damping factor delta. That requires a Metropolis-Hastings sampler since, although the trend rate generated by conditional simulation can be treated as data, the unconditional likelihood for an AR(1) on it isn't a standard distribution.
Post Reply