Re: [Gretl-devel] [Gretl-users] pre-multiplication by transpose
by Riccardo (Jack) Lucchetti

On Fri, 7 Dec 2012, Allin Cottrell wrote:
> In fact, although we could go either way in terms of resolving the
> inconsistency of treatment of X'Y and X'*Y, for X or Y 1x1 and not
> strictly conformable with the other operand, it would be easier (I
> think) to make the latter operation reduce to the former, hence
> (absent any other changes) enforcing the stricter interpretation. If
> that's what we want.
Premise: matrix-oriented languages have a short history, compared to the
tradition in mathematically-formal matrix notation. A few conventions have
been emerging in Gauss, Matlab and Ox, with hansl and mata as the
newcomers in the field. It's perfectly natural that some good ideas become
de facto standards (or almost such, such as the A'B syntax, matlab being
the exception), while at the same time there may be inconsistencies and
oddities. Moreover, hansl has not been "designed": many of its features
have been added incrementally as needed, so quirks may arise just as they
do in natural languages, such as English. Sometimes (like in the case of
left- and right- matrix divisions) changing to conform to what others do
is a good idea, sometimes it isn't. I'd say it depends. IMO, the objective
must be to conform to intuition (and established mathematical conventions)
as closely as possible without infringing consistency and predictability
of behaviour.
This said, I think both expressions should be legal: in the expressions
"a'b" and "a' * b" the 'prime' character actually performs a different
role (as Allin already said): in the first case, it's shorthand for
"transpose and then multiply"; in the second case, it means "transpose and
see what happens next".
In the interest of common sense, I imagine that everybody agrees that
transposition on a 1x1 matrix should be a no-op which takes precedence on
anything else, so "a' * b" is exactly equivalent to "a*b". For similar
reasons, "a'b" should be interpreted as "since this is shorthand for
"(a')*b, just do the same".
>> What's trickier is plain "X*Y" when X is 1x1 and Y is not a row vector
>> (so written without any transposition), but that apparently is not the
>> topic right now.
>
> No, but rescinding the "1x1 matrix is treated as a scalar" policy
> more generally would be seriously backward-incompatible.
Not only that, it would be wrong IMO. A scalar is not, strictly speaking,
a 1x1 matrix. In fact, the common mathematical convention on how to
interpret $k \cdot A$, $k \in \Re$ and $A \in \Re^{m \times n}$ (pardon my
TeX) is there exactly to avoid the boring and cumbersome details on how to
do "the right way" something quite trivial.
> Allin Cottrell
>
> P.S. Although I haven't shifted it myself, shouldn't this be on
> gretl-devel?
>
It's now on both. Is this a bad idea?
-------------------------------------------------------
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
-------------------------------------------------------
11 years, 6 months

@-substitution and printf
by Allin Cottrell

This follows on the gretl-users thread starting with
http://lists.wfu.edu/pipermail/gretl-users/2012-December/008282.html
where Artur Tarassow raised a question about commands such as
printf "%.3f\n", m1ATfoo
where "foo" is the name of a pre-defined string variable (and
where I've written "AT" in place of the at-sign to try to
avoid getting mangled by pipermail).
Artur's intent was that gretl should interpret the argument
(after substitution) as the name of scalar variable, but this
wasn't working, because the usual at-sign substitution wasn't
being done for the arguments to printf.
I then commented that it would seem more consistent to do
string substitution in that context, and I made a change in
CVS that enabled commands of this sort.
However, I also mentioned that I thought there had been a
reason, at some point in the past, for _not_ doing such
substitution, and now I've rediscovered it. The reason is not
compelling in itself, but ignoring it does introduce an
element of backward incompatibility.
Take a sequence like this:
string tmp = "hello"
printf "%10s\n", ATtmp # Exhibit A
(where again I've used "AT" to prevent mangling). Should this
work? Arguably it should not, since after substitution what we
have as an argument is "hello", _without_ the double quotes,
and this is neither a string literal nor the name of a string
variable (unless it happens that a string named "hello" was
defined earlier). Correct variants of the above would be
printf "%10s\n", tmp
or (clumsy but OK)
printf "%10s\n", "ATtmp"
The only problem is that Exhibit A used to work, and I've
found an instance among the contributed function packages. It
worked on condition that we (a) did not do ordinary string
subst for the printf arguments, but then (b) did a special
fix-up when the arguments were processed through the "genr"
mechanism. This was ugly hack, supporting something that
really shouldn't have worked, and I'm not recommending we
re-establish it. I'm just pointing out that there's a backward
compatibility issue here: if we keep the new code we'll have
to advertise the change properly.
Allin
11 years, 6 months

Re. gretl too liberal with zero-length matrices
by Allin Cottrell

In
http://lists.wfu.edu/pipermail/gretl-devel/2012-December/004176.html
I wrote:
<quote>
On Fri, 7 Dec 2012, Sven Schreiber wrote:
> I just noticed that this:
> matrix m = ones(1,1) | zeros(0,9)
>
> actually works. I think gretl should complain instead,
> because for concatenation one of the dimensions must match.
Fair enough. A related point is that, up till now,
"zeros(0,9)" didn't actually produce a 0 x 9 matrix, the
result was 0 x 0. That's now fixed in CVS, along with the
conformability question.
For row concatenation, '|', the two matrices must always have
the same number of columns, and for column concatenation, '~',
they must always have the same number of rows.
(Although I do retain a suspicion that it's not altogether
meaningful to say a matrix has 9 columns when it has zero
rows.)
</quote>
Sorry: Error, Fail! This "fix" broke things that are stated to
work in the manual (e.g. the ability to use a null matrix as
the basis for either row or column concatenation). I think
that's now put to rights in CVS.
Maybe not for right now, but... I tend to think that we should
not allow the construction of matrices like the one in Sven's
example above -- that is, with zero rows but a positive number
of columns or vice versa. You can have a proper null matrix,
or you can have a matrix with rows > 0 and cols > 0, but not a
chimera.
As I mentioned, doing "zeros(0,9)" would (silently) produce a
proper null matrix (0x0) until recently. That was not very
satisfactory and for the present I've left in place the "fix"
that produces a 0x9 matrix, but I think that shouldn't stand
for long. Thoughts?
Allin
11 years, 6 months

gretl too liberal with zero-length matrices
by Sven Schreiber

Hello again,
I just noticed that this:
matrix m = ones(1,1) | zeros(0,9)
actually works. I think gretl should complain instead, because for
concatenation one of the dimensions must match.
thanks,
sven
11 years, 6 months

bundles multiplying like rabbits in icon view (and causing crashes)
by Sven Schreiber

Hi,
I have loops which create and overwrite bundles, and afterwards I get
many bundles with exactly the same names in the icon view. So
replacing/overwriting doesn't seem to work. (This is the latest release
--not the snapshot-- on windows 7, from the non-admin zip package.) When
trying to open (double-clicking) one of these items, gretl crashes.
It happens in various settings:
* In one case, the bundle is an input argument to a function. What's
funny is that the name in the icon view is not the name of the bundle in
the outer scope, but the argument name inside the function.
* In another case, the bundle is created in the top-level scope of the
script, but I also tried to explicitly do 'delete <nameofbundle>' before
creating it again, and it didn't seem to work. Note that here also the
bundle is the return value of a function.
* In both cases, the number of icons with identical names in the icon
view does not seem to coincide with the number of loop repetitions.
Hope this is clear enough,
Sven
11 years, 6 months

Function error: variable 0 is duplicated in the list of instructions
by juan de botton

Hi everyone,
Fist of all I want to say thanks to Sven and Ignacio because his suggestions about inserting a statistical table in a function have been very helpful.
Now, I have some problems with my function script and I don't really understand what is actually the problem.
When I trie to run my sample script, I get the following error message: "the variable 0 is duplicated in the list of instructions"
Here is my function script. I ommit A and B matrices because are quite large, but everything else is there:
function bundle DeWallis_test (series y "Explained variable", list xlist "Explanatory variables (Note: constant term is included by default)", bool dummy[0] "Are dummy variables included in the regression? (remember that constant is included by default)") T = $nobs list xlist = const xlist if T<16 funcerr "Insufficient observations" endif ols y xlist --quiet scalar SCE = $ess matrix uhat = $uhat scalar ut = 0 loop i = 5..T --quiet scalar ui = (uhat[i,1] - uhat[i-4,1])^2 ut = ut + ui endloop scalar DeWallis_stat = ut/SCE #A : DeWallis_stat_table_nodummy #B : DeWallis_stat_table_dummy #De Wallis test if dummy matrix xlist = xlist scalar k = cols(xlist) - 4 if k>5 funcerr "The number of regressors has to be less or equal to 5 (withot considering the constant term nor the dummy variables)" endif if k<1 funcerr "Insufficient number of regressors. Please make sure you input at least one independent variable and the three dummy") endif scalar row = T/4 -3 scalar row = floor(row) scalar col_left = 2*k scalar col_right = 2*k +1 if DeWallis_stat < B[row , col_left] string DeWallis_test_result = "We reject H0, there is evidence of negative autocorrelation" else if DeWallis_stat > B[row, col_right] string DeWallis_test_result = "We reject H0, there is evidence of positive autocorrelation" else string DeWallis_test_result = "The test does not provide enough evidence to suggest autocorrelation" endif endif else matrix xlist = xlist scalar k = cols(xlist) - 1 if k>5 funcerr "The number of regressors has to be less or equal to 5 (withot considering the constant term)" endif if k<1 funcerr "Insufficient number of regressors. Please make sure you input at least one independent variable") endif scalar row = T/4 -3 scalar row = floor(row) scalar col_left = 2*k scalar col_right = 2*k +1 if DeWallis_stat < A[row , col_left] string DeWallis_test_result = "We reject H0, there is evidence of negative autocorrelation" else if DeWallis_stat > A[row, col_right] string DeWallis_test_result = "We reject H0, there is evidence of positive autocorrelation" else string DeWallis_test_result = "The test does not provide enough evidence to suggest autocorrelation" endif endif endif DeWallis_test["De Wallis statisitic"] = DeWallis_stat DeWallis_test["Test result"] = DeWallis_test_result print "--------------------------------------------\n" printf "The value of the De Wallis statistic is: %g\n", DeWallis_stat print "--------------------------------------------\n" return DeWallis_test end function
#Sample scriptinclude DeWallis_test.gfnopen 'C:\Users\Owner\Documents\MATLAB\BasesDeDatos\np.xlsx' --quietseries y = v1list xlist = const v2 bundle results = DeWallis_test(y,xlist,0)print results
Thanks in advance for your help.
Sincerely, Juan Pablo de Botton Falcón.
11 years, 6 months

Insert Stat-Table to a function.
by juan de botton

Hi everyone,
My name is Juan Pablo de Botton and I am developing a simple function (it is an autocorrelation test) to share with the Gretl community in the near future. The statistic has its own distribution so, in order to do the test, I need to insert a complete statistical table that depends on the number of the observations and independent variables you use in your regression. Since I have little experience in hansl programming, I was wondering if there is a simple way to this. My first idea was to 1) insert all the values in excel, 2) import them to gretl and, finally, 3) define that matrix in my script. The function should be available to everyone so I don't know if this a good way to do it.
By the way, I'm new in hansl programming so any advice is welcome.
Thank you in advance for your help.
Sincerely, Juan Pablo de Botton Falcón.
11 years, 6 months