On Thu, 11 Feb 2021, Filipe Costa wrote:
Dear community,
I was trying to estimate state space models and I came to the point
where I have negative coefficients for standard deviation parameters.
That, in itself, is not a problem. What is identified is the variance, and
the standard deviation is just its positive square root. This means that
after estimation you just flip its sign and you're ok. However, if you
really want to constrain your parameter to be positive, there are several
ways to do so.
Eviews, for example, requires these parameters to be specified as
var=exp(c), eventually to avoid this.
Is there a very simple way in the code to avoid these negative sigmas?
The log transformation is one of the possibilities: in your script, for
example, you could maximise the log-likelihood on the log of sigma instead
of sigma itself: in this case, you'd have to change your script to
<hansl>
function void arma11_via_kalman (series y)
/* parameter initialization */
scalar phi = 0
scalar theta = 0
scalar lsigma = log(0.1)
/* state-space model setup */
matrix H = {1; theta}
matrix F = {phi, 0; 1, 0}
matrix Q = {exp(2*lsigma), 0; 0, 0}
bundle kb = ksetup(y, H, F, Q)
/* maximum likelihood estimation */
mle logl = ERR ? NA : kb.llt
kb.obsymat[2] = theta
kb.statemat[1,1] = phi
kb.statevar[1,1] = exp(2*lsigma)
ERR = kfilter(&kb)
params phi theta lsigma
end mle --hessian
end function
<hansl>
However, this may be unstable numerically in some cases. Also, if you want
the estimate of the variance you'd have to compute it "by hand" as
exp(2*lsigma).
An alternative possibility would be insisting on the fact that the "sigma"
parameter must be strictly positive, otherwise the log-likelihood would be
marked as invalid. In order to accomplis this, one simple way would be
changing the line
ERR = kfilter(&kb)
to
ERR = (sigma > 1.0e-12) && kfilter(&kb)
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------