/usr/share/gretl/functions/criteria.gfn is in gretl-common 2016a-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | <?xml version="1.0" encoding="UTF-8"?>
<gretl-functions>
<gretl-function-package name="criteria" ID="1266796477" minver="1.8.6">
<author>Allin Cottrell</author>
<version>1.0</version>
<date>2010-02-21</date>
<description>Calculate model selection criteria</description>
<help>
Computes the Akaike Information Criterion (AIC), Schwarz's Bayesian
Information Criterion (BIC) and the Hannan-Quinn criterion (HQC),
given ess (error sum of squares), the number of observations (n),
and the number of coefficients (k).
The AIC is computed as in Akaike's original (1974) formulation,
namely AIC = -2L + 2k, where L denotes the maximized log-likelihood.
The BIC is computed as BIC = -2L + k log n.
The HQC is computed as HQC = -2L + 2k log log n.
A row vector containing the three criteria is available for
assignment on return.
</help>
<gretl-function name="criteria" type="matrix" private="0">
<params count="3">
<param name="ess" type="scalar"/>
<param name="n" type="scalar"/>
<param name="k" type="scalar"/>
</params>
<code>if (ess <= 0 || k < 1 || n <= k)
funcerr "We require ess > 0, k > 0 and n > k"
endif
matrix crit = zeros(1, 3)
scalar logn = log(n)
scalar llm = n * log(ess)
llm += n * (log(2*pi) + 1 - logn)
crit[1] = llm + 2*k
crit[2] = llm + k*logn
crit[3] = llm + 2*k*log(logn)
printf "Using ess = %g, %d observations, %d coefficients\n", ess, n, k
printf "\nAIC = %g\nBIC = %g\nHQC = %g\n\n", crit[1], crit[2], crit[3]
return crit
</code>
</gretl-function>
<sample-script>
# Demonstrate that the criteria() function produces the
# same results as gretl does for a given model.
open data4-10
ols 1 0 2 3 4
matrix cr = criteria($ess, $T, $ncoeff)
# printing cr is somewhat redundant, but this is just an
# illustration
print cr
</sample-script>
</gretl-function-package>
</gretl-functions>
|