Mann-Kendall test
by Sven Schreiber

Hi,
I've just read about the non-parametric Mann-Kendall test for a trend
(hence my recent postings about Kendall's tau and ties in a series).
It looked pretty easy, so I'm attaching an attempt at a basic
implementation. Full disclosure: I've used the description from
https://cran.r-project.org/web/packages/trend/vignettes/trend.pdf (only
the basic version in section 1.1).
All you have to do is call "MannKendall(x)", where x is your series of
interest.
I'd be happy about feedback regarding cross-checks and correctness (for
example in the above document in equ. (4) the case S>0 wrongly appears
twice, and I had to make an educated guess where to switch the
signs...), whether it should become a function package and so on.
thanks,
sven
2 years, 8 months

another ternary woe
by Sven Schreiber

Hi,
very short minimal script here:
<hansl>
matrix heyho = ("a" == "b") ? garbl[3,] : I(2)
</hansl>
There is no object "garbl", but that's by design in the case that the
condition isn't true. Gretl says "[" would be invalid here.
thanks,
sven
2 years, 10 months

multivariate ARCH test for VARs
by Allin Cottrell

Following up on Sven at
http://lists.wfu.edu/pipermail/gretl-devel/2017-March/007508.html
Thanks for another nice hansl prototype! I've now implemented this in
C and you can access it after estimating a VAR, with
modtest [horizon] --arch --multivariate
(--multivariate is currently a "secret" option).
Lutkepohl provides some example results (2005, p. 578) but
unfortunately in this case they're based on a dataset that has
apparently not been made public (Volkswagen daily stock returns).
However I've done some basic testing:
* The test seems to be sized about right, based on Monte Carlo
using varsimul() -- thanks, Jack! -- with plain mnormal() errors.
* I've verified that the new test collapses to equivalence with our
existing univariate ARCH test for a "VAR" with a single variable.
Well, almost: there's a small difference in that our univariate test
skips missing lagged residuals at the start of the sample range while
the new one substitutes zeros.
For anyone wanting to mess with this, here's my Monte Carlo script:
<hansl>
set verbose off
scalar T = 200
# coeffs from Lutkepohl's VW example
matrix A = {0, 0.02, -0.18, 0.16, -0.08, 0.11 ;\
0.12, -0.13, -0.08, 0.03, -0.01, 0.01 }
matrix y0 = zeros(3, 2)
n = T + 3
nulldata n --preserve
setobs 12 2000:01
K = 5000
matrix rej05 = zeros(K, 3)
matrix rej01 = zeros(K, 3)
matrix pv
loop i=1..K -q
matrix U = mnormal(T, 2)
matrix Y = varsimul(A, U, y0)
series y1 = Y[,1]
series y2 = Y[,2]
smpl 4 ;
var 3 y1 y2 --silent
modtest 6 --arch --multivariate --quiet
pv = $pvalue
rej05[i, 1] = pv[1] < 0.05
rej05[i, 2] = pv[3] < 0.05
rej05[i, 3] = pv[6] < 0.05
rej01[i, 1] = pv[1] < 0.01
rej01[i, 2] = pv[3] < 0.01
rej01[i, 3] = pv[6] < 0.01
smpl full
endloop
sz05 = sumc(rej05) / K
sz01 = sumc(rej01) / K
print sz05
print sz01
</hansl>
Allin
2 years, 11 months

VAR autocorrelation testing
by Sven Schreiber

Hi,
I've just revisited the available tools for diagnostic checking of VARs
(as you may have guessed from my earlier email this morning). To be
honest, I've found them a little lacking.
Attached is an implementation of the Rao-style F-statistic for VAR
residual autocorrelation that is described in Helmut Luetkepohl's "New"
book (also more than 10 years old already), section 4.4.4 (Lagrange
Multiplier Tests for Checking the Whiteness of the Residuals).
A simple test case is also included (at the bottom of the script). Note
the different p-values for order 4 compared to the built-in tests.
Comments and corrections welcome. Eventually I would propose to adapt
this as a built-in "modtest" variant (if no problems arise with this).
thanks,
sven
2 years, 11 months

outfile mybuf --buffer problem on Windows
by oleg_komashko＠ukr.net

Dear all,
To reproduce (also attached):
open greene22_2.gdt --quiet
outfile mybuf --buffer --quiet
labels 2
outfile --close
string s = mybuf
print s
eval strlen(s)
### Ubuntu 16.10 (64) output
# ? open greene22_2.gdt --quiet
# Read datafile /usr/local/share/gretl/data/greene/greene22_2.gdt
# ? outfile mybuf --buffer --quiet
# Now writing output to 'mybuf'
# Closed output file 'mybuf'
# ? string s = mybuf
# Generated string s
# ? print s
# Listing labels for variables:
# Z1: Gender (0 = female, 1 = male)
#
#
# ? eval strlen(s)
# 66
### XP(32) & W 10(64) output
# ? open greene22_2.gdt --quiet
# Read datafile C:\Program Files\gretl\data\greene\greene22_2.gdt
# ? outfile mybuf --buffer --quiet
# Now writing output to 'mybuf'
# Closed output file 'mybuf'
# ? string s = mybuf
# Generated string s
# ? print s
#
# ? eval strlen(s)
# 0
Oleh
2 years, 11 months

arima-Problem: unexpected $bic values
by Sven Schreiber

Hi,
first I've noticed a strange behavior with Jack's BNdecomp.gfn package
when I used the auto choice of AR/MA orders. But I think I've tracked
this down to what the $bic accessor gives with gretl's arima command.
(So I don't think this is a problem with BNdecomp, it just shows up there.)
Below is a complete example of what I mean. The $bic value for an
ARIMA(1,1,0) model --which is obviously just an AR(1) in first
differences-- is noticeably higher when gretl's "arima" command is used,
compared to what the manual AR(1) to the diffs gives me.
Notice that this difference flips around the ranking of the models; the
manual approach (and conventional wisdom) prefers to include the first
lag, while the $bic values from "arima" would point to the ARIMA(0,1,0)
model without lags. (And that's what may lead to strange results of the
BNdecomp auto choice.)
thanks,
sven
<example-comparison>
open AWM.gdt
set verbose off
series DY = diff(YER) # YER: real GDP
smpl 1975:1 1998:4
# manual ARIMA(1,1,0) on levels GDP via OLS:
ols DY const DY(-1) # highly significant first lag
bic_man110 = $bic
# comparison ARIMA(0,1,0) = ARMA(0,0)
ols DY const
bic_man010 = $bic
# gretl ARIMA(1,1,0)
arima 1 1 0; YER
bic_a110 = $bic
# comparison gretl ARIMA(0,1,0)
arima 0 1 0; YER
bic_a010 = $bic
print "---------- 1 1 0"
print bic_man110 # 1922.5920
print bic_a110 # 1929.7816
print "---------- 0 1 0"
print bic_man010 # 1923.8034
print bic_a010 # same (1923.8034)
</example-comparison>
2 years, 11 months

args in lags() vs. mlag()
by Sven Schreiber

Hi,
I find it confusing in routine work that the lags() function wants to
have the lag number as the first arg, while the mlag() function wants to
have the input matrix first and afterwards the lag number.
Don't know how, maybe this could be aligned somehow in the future.
cheers,
sven
2 years, 11 months

anonymous string arrays in colnames()
by Sven Schreiber

Hi,
is this failure expected or/and a bug?:
<hansl>
matrix m = I(2)
strings ms = defarray("a", "b")
colnames(m, ms) # works
print m
colnames(m, defarray("a", "b")) # fails
print m
</hansl>
Last month's snapshot -- should I update?
thanks,
sven
2 years, 11 months

additions to the VAR chapter in the guide
by Sven Schreiber

Hi,
browsing through the VAR chapter again (after a long time of not looking
at it) two things seem necessary:
1. add a cross reference to the SVAR add-on, because otherwise people
just end up with the assertion "Gretl does not currently provide a
native implementation" of SVARs.
2. Say something about the diagnostic tests available.
This message is just a reminder to whomever (myself included) finds time
to do it...
(I was looking at the October 2016 version.)
thanks,
sven
2 years, 11 months

scriptopt
by Sven Schreiber

Hi,
in January Jack mentioned a trick to inject an option value into a gretl
script when running the script from the command line. First of all that
is an undocumented thing (except if you do "gretlcli -h"), so I wanted
(and still want) to send at least a message to the users list for
reference. I guess it should also be added to the manual chapter "The
command line interface".
I put together the following example script which should be
self-explanatory:
<cli-script>
# Script to be run from the command-line/shell with gretlcli
# to test the "--scriptopt" trick, as in:
# > gretlcli scriptopttest.inp -b --scriptopt=3
if exists(scriptopt)
eval scriptopt
eval typestr(scriptopt) # gives "matrix" for me
if scriptopt == 3
print "Recognized as integer 3" # is printed
endif
else
print "Sorry, didn't work" # redundant, it works
endif
</cli-script>
One question I have before I send something like this to the users list,
why do I get typestr(scriptopt) == "matrix" ? I thought perhaps gretl is
expecting/allowing a matrix there, but then I tried the following command:
<shell-command>
gretlcli scriptopttest.inp -b --scriptopt={1;2}
</shell-command>
...and the output I got was:
? eval scriptopt --- so exists(scriptopt) must be true!
0 --- where does this come from?
? eval typestr(scriptopt)
null --- neither "0" nor "{1;2}" should give this!
So some more minor mysteries appearing here...
thanks,
sven
2 years, 11 months