changes to 'extra'
by Sven Schreiber
Hi,
let me start a new thread here. First a reminder to everybody that the
'extra.gfn' package is now an add-on so that the code base lives in git.
I propose the following updates / changes, and wanted to mention them
here first:
1) Add the 'powerset' function as discussed in the other thread. Please
speak up especially if you think another name would be better, because
changing it later is difficult.
2) There's a little bug in the 'commute' function I think, or at least
in the documentation related to non-square matrices. [commute(vec(B),
rows(B)) without the other integer argument will fail if B is not
square.] So I want to clarify the help text and add an input error check
to the function.
3) Want to add an 'eliminate' function as a sister of 'commute', which
returns the result of pre-multiplying with the elimination matrix.
Haven't looked at whether post-multiplication would be wanted as well.
Here's my code:
<hansl>
function matrix eliminate(const matrix vecA)
# The input vecA is assumed to come from the
# operation vec(A) on a square matrix, thus
# rows(vecA) must be a square number.
# Returns vech(A), which is the result of pre-
# multiplying vec(A) with the "elimination"
# matrix L_m.
if cols(vecA) != 1
funcerr "input must be a column vector"
endif
sqr = sqrt(rows(vecA)
if sqr != round(sqr)
funcerr "input must have a square number of elements"
endif
return vech(mshape(vecA, sqr, sqr))
end function
</hansl>
4) Add a remark to the help text that (pre-)multiplication with the
duplication matrix is as simple as doing:
vec(unvech(vechA))
where vechA is supposed to come from vech(A). The relevant input checks
come for free from the unvech() function, hence no new function.
Comments and also suggestions for other new functions are welcome.
Thanks,
sven
6 years, 2 months
redundancies in the setobs command?
by Sven Schreiber
Hi,
I wonder if there's a way to make the setobs command more user friendly.
From its help: "In the case of panel data the starting observation
should be given as 1:1; and in the case of cross-sectional data, as 1."
So if the user has no options in these cases, why does (s)he still have
to get these parts right, instead of leaving them out?
A related question is why a periodicity has to be given for the
--cross-section option. That also seems to be redundant and to add to
the syntax complexity.
thanks,
sven
6 years, 2 months
mode function (also for 'extra')
by Sven Schreiber
Hi,
we still have the dangling issue of a possible "mode" function for
inclusion in the 'extra' package.
Here's the latest suggestion from the stack-replacement thread (another
issue):
function matrix mode(matrix v)
# v should be a vector
E = ecdf(vec(v))
howmuch = diff(0 | E[,2])[2:] # make sure the 1st is also diffed
where = imaxc(howmuch)
return E[where, 1] | howmuch[where]
end function
It was noted that this is not optimal for multi-modal input, but "what
should be done is debatable". And I mentioned that "this is partly
inherited from the imax*/imin* suite of gretl functions", which also
return _something_ when in fact it is ambiguous.
My proposal is to simply document that the function only returns one
mode, not all (if several exist). But I'm happy to hear improvements.
thanks,
sven
6 years, 2 months
global series penetrating into functions problem
by oleg_komashko@ukr.net
Dear all,
Below is a script illustrating the problem
# creates list of all global series
function list fun1(void)
list retlist = seq(1,$nvars-1)
return retlist
end function
# identity list function
function list fun2(list a_list)
return a_list
end function
# checking function
function void fu(string name)
catch eval @name
err = $error
if err
printf "Variable %s is not defined\n", name
endif
end function
#contaminating function
function void spoil(void)
list list1 = fun1()
list list2 = fun2(list1)
end function
###### example
nulldata 20
set seed 13
x1 = normal()
# before
fu("x1")
# looking at x1
print x1
# spoiling
spoil()
# after
fu("x1")
On the first run fu("x1") does not know
global series 'x1' but after running spoil()
fu("x1") knows and evaluates x1
Oleh
6 years, 2 months
Function packages on Windows: new path permanently added
by Sven Schreiber
Hi,
I'm noticing that with the Oct 4th snapshot in the (local) function
package list window a (preliminary) package appears that lives in a
non-standard path.
This is new I think, because it used to be that one could switch to a
user-specified path, and then only those packages from there was shown.
If one reverted to the standard listing, the non-standard paths would be
forgotten again.
Is this a bug or a feature?
thanks,
sven
6 years, 2 months
fresh "penetration" impressions (almost ok)
by oleg_komashko@ukr.net
Dear all,
<hansl>
function list das(void)
list da = seq(1,$nvars - 1)
return da
end function
function scalar mynelem (const list alist)
return nelem(alist)
end function
function series get_global(int i)
txt = sprintf("ols 0 %d -q",i)
@txt
return $xlist[1]
end function
#eval get_values(global)
function string get_globnames(void)
ret = ""
loop i=1..($nvars - 1) -q
ret = ret~" "~getinfo(i).name
endloop
return ret
end function
function void spoil100(bundle *b)
s = nelem(b.xlist)
end function
function list spoil200(const bundle b)
list li = das()
s = mynelem(b.xlist)
nams = get_globnames()
ser = get_global(1)
return li
end function
function void fu(string name)
catch eval @name
end function
nulldata 20
set seed 13
y = normal()
x1 = normal()
x2 = normal()
bundle bu
list bu.xlist = x1 x2
fu("x1")
fu("x2")
fu("y")
# no effect
spoil100(&bu)
fu("x1")
fu("x2")
fu("y")
# "penetrating" the only difference
# between spoil100 and spoil200 is in
# using user-specified mynelem and
# the native nelem; with mynelem
# being just wrapper over nelem
list lis = spoil200(bu)
fu("x1")
fu("x2")
fu("y")
lis
<hansl>
goes as expected on fresh git!
A minor problem has left:
function list spoil300(const bundle b)
s = mynelem(b.xlist)
nams = get_globnames()
ser = get_global(1)
list li = das()
return li
end function
list lis2 = spoil300(bu)
fu("x1")
fu("x2")
fu("y")
lis2
Generated list lis2
? fu("x1")
> x1
? fu("x2")
> x2
? fu("y")
> y
? lis2
index y x1 x2 ser
I. e. ser has penetrated into global
data set
Olewh
6 years, 2 months
proposal for a new function of the extra package
by Riccardo (Jack) Lucchetti
I was looking at some code that people (Sven, Oleh, myself among others)
have written for function packages and I thought that the fact that we
don't have named arguments for functions like R and Python have is
sometimes a little inconvenient.
So I thought one could pass a string argument to a function with options
of the kind "a = _something_", where _something_ is a scalar or a string,
or better still, a sequence of these statements, separated by semicolons.
The results would be collected in a bundle. I'm attaching a simple inp
file which should exemplify what I have in mind.
If we decide this is worthwhile having, it could be put into the
extra package or perhaps into libgretl.
Comments welcome.
-------------------------------------------------------
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
-------------------------------------------------------
6 years, 2 months
A different way of "penetration" of dataset series
by oleg_komashko@ukr.net
Dear All,
Here it is:
function void fun1001 (list alist)
print ""
end function
function void spoil100(bundle *b)
fun1001(b.xlist)
end function
function void fu(string name)
catch eval @name
end function
nulldata 20
set seed 13
y = normal()
x1 = normal()
x2 = normal()
bundle bu
list bu.xlist = x1 x2
fu("x1")
fu("x2")
fu("y")
spoil100(&bu)
fu("x1")
fu("x2")
fu("y")
Hopefully, this time
list components of bundles
will not be excluded
Oleh
6 years, 2 months
arima issues
by oleg_komashko@ukr.net
Dear all,
Below is a script illustrating
some problems with arima command
For convenience .inp file is also added
<hansl
open greene5_1.gdt
logs *
arima 1 1 1; l_realcons
mod1 = $model
eval mod1.ylist
eval $ylist
# it seems the both variants output series with ID = 1
# this crashes gretl (resent snpshots) both on Windows 10 (64)
# and Ubuntu 18.4 (64):
matrix a_matrix = zeros(2,1)
set initvals a_matrix
arima 1 1 1; l_realcons --nc
# but on 2018a the output is
/*
The convergence criterion was not met
Error executing script: halting
> arima 1 1 1; l_realcons --nc
*/
# on 2018a
arima 1 1 1; l_realcons --nc --lbfgs
/*
Function evaluations: 8
Evaluations of gradient: 8
Model 1: ARIMA, using observations 1950:2-2000:4 (T = 203)
Estimated using Kalman filter (exact ML)
Dependent variable: (1-L) l_realcons
Standard errors based on Hessian
coefficient std. error z p-value
--------------------------------------------------------
phi_1 0.872604 0.0756384 11.54 8.64e-031 ***
theta_1 −0.481946 0.136679 −3.526 0.0004 ***
Mean dependent var 0.008817 S.D. dependent var 0.008856
Mean of innovations 0.002195 S.D. of innovations 0.009571
Log-likelihood 655.4098 Akaike criterion −1304.820
Schwarz criterion −1294.880 Hannan-Quinn −1300.798
Real Imaginary Modulus Frequency
-----------------------------------------------------------
AR
Root 1 1.1460 0.0000 1.1460 0.0000
MA
Root 1 2.0749 0.0000 2.0749 0.0000
-----------------------------------------------------------
*/
# for comparison
arima 1 1 1; l_realcons --nc --x-12-arima
# on snapshot
arima 1 1 1; l_realcons --nc --lbfgs
/*
The convergence criterion was not met
Error executing script: halting
> arima 1 1 1; l_realcons --nc --lbfgs
*/
# the same (The convergence criterion was not met)
# from 2018a arima 1 1 1; l_realcons --nc --lbfgs
matrix a_ma = {0.872604,−0.481946}
set initvals a_ma
arima 1 1 1; l_realcons --nc --lbfgs
# approx from arima 1 1 1; l_realcons --nc --x-12-arima
matrix a_ma2 = {0.99,−0.99}
set initvals a_ma2
arima 1 1 1; l_realcons --nc --lbfgs
# this also crashes gretl (resent snpshots)
matrix a_matrix = zeros(2,1)
set initvals a_matrix
arima 1 1 1; l_realcons --nc --lbfgs
# does not affects
set initvals a_matrix
arima 1 1 1; l_realcons --nc --x-12-arima
hansl>
Oleh
6 years, 2 months