On Mon, 7 Nov 2011, Sven Schreiber wrote:
On 11/07/2011 09:58 PM, Andreas Noack Jensen wrote:
> Den 07/11/2011 kl. 21.35 skrev Riccardo (Jack) Lucchetti:
>
>> On Mon, 7 Nov 2011, Allin Cottrell wrote:
>>
>>> On Mon, 7 Nov 2011, Andreas Noack Jensen wrote:
>>>
>>>> When talking about eigsolve it would nice if the Command
>>>> Reference indicated in which order the values and vectors are
>>>> sorted.
>>>
>>> Yes, granted. At present they're sorted from smallest to largest,
>>> which is the way lapack's dsyev gives them. But while we're
>>> thinking about this, is there a case for reversing the order?
>>> It's more convenient to have them in descending order for
>>> cointegration analysis but of course there are other uses for
>>> eigen-calculations...
>>
>> (Badly impersonating Sven:) But that would be
>> backward-incompatible, wouldn't it?
>>
>> No, seriously. IMO, once we've made it clear what the function's
>> behaviour is, we're ok.
>
> As a new user I have no idea about how much code there would be
> affected, but the fact that it has not been documented so far makes
> it easier to change, I believe. Right now I am reversing the order
> each time I use these functions so it would be easier for me if was
> changed but on the other hand it is quite easy to do it. Just for
> comparison with the other players, R and Ox have descending, Matlab
> one function for each direction of ordering.
>
You have a point that it can be argued that the ordering was not a
feature of the function, just a coincidence.
In any case, if gretl adds a sorting layer on top, this will slow things
down. IMHO at least the user should have access to the faster version
without the additional sorting, for heavy-duty computations (presumably
loops and simulations and such). So syntactically either two function
variants or an additional argument.
Good point. What I've done in CVS at present is
(a) left the eigenvalues in ascending order, as supplied by
dsyev(), for speed (and noted the order in the help); and
(b) added a function eigsort() (not yet documented), which
reorders the eigenvalues and vectors to descending, and has an
optional last integer argument to enable trimming of the
eigenvalues and vectors, which can be useful in cointegration
analysis.
Here's a complete script which illustrates the use of eigsort:
<hansl>
open denmark.gdt -q
list Y = LRM LRY IBO IDE
coint2 2 Y --rc
# now do (part of) the analysis manually
list dY = diff(Y)
list dY_1 = lags(1, dY)
list Y_1 = lags(1, Y) const
smpl +2 ;
matrix mX = {dY_1}
matrix mY = {dY} ~ {Y_1}
scalar T = rows(mX)
scalar n = nelem(Y)
matrix U
mols(mY, mX, &U)
U0 = U[,1:n]
U1 = U[,n+1:]
matrix S00 = U0'U0 ./ T
matrix S11 = U1'U1 ./ T
matrix S01 = U0'U1 ./ T
matrix A = qform(S01', inv(S00))
matrix evecs
matrix evals = eigsolve(A, S11, &evecs)
eigsort(&evals, &evecs, n)
print evals
print evecs
</hansl>
Allin