On Fri, 16 Feb 2018, Alecos Papadopoulos wrote:
I guess this is elementary and I should be embarrassed, but it seems
I cannot
find a way to tell gretl to include what is essentially a quadratic form in
the expression for the log-likelihood contributions (llc) (1st line in the
mle command).
There are two reemarks I'd like to make here: one is related to the syntax
of the mle line. In your example, "q" is the full matrix of observations,
but "qform(q, inv(S))" implicitly refers to q as the i-th row of
that matrix. A minimal modification of your script that fixes this is
<hansl>
nulldata 128
series N1 = normal()
series N2 = normal()
scalar s1 = 1
scalar s2 = 1
scalar c12 = 0.5
matrix q = {N1, N2}
mle logl = check ? -0.5 * (qqq + ldet(S)) : NA
matrix S = {s1^2,c12;c12,s2^2}
scalar check = (s1>0) && (s2>0) && (abs(c12)<1)
matrix qq = q * inv(S)
series qqq = sumr(q.*qq)
params s1 s2 c12
end mle
# check
Shat = q'q ./ $nobs
print Shat
eval sqrt(diag(Shat))
</hansl>
Having said this, though, there's a more general point, on the check for
positive definiteness of S. If you reparametrise the problem, you can make
S pd by construction simply optimising over the elements of the Cholesky
factor of S rather than S itself. This is a very nice trick, which saves
you lots of intermediate computation, works quite well in practice and is
trivial to generalise to any number of columns of q. For example:
<hansl>
nulldata 128
series N1 = normal()
series N2 = normal()
scalar s1 = 1
scalar s2 = 1
scalar c12 = 0.5
matrix q = {N1, N2}
matrix S = I(2)
matrix theta = vech(S)
mle logl = -0.5 * (qqq + ldet(S))
matrix K = lower(unvech(theta))
matrix S = K*K'
matrix qq = q * invpd(S)
series qqq = sumr(q.*qq)
params theta
end mle
# check
Shat = q'q ./ $nobs
eval cholesky(Shat)
</hansl>
Hope this helps.
-------------------------------------------------------
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
-------------------------------------------------------