Allin Cottrell
1.2
2016-10-29
Calculate model selection criteria
C10
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.
```
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
```

include criteria.gfn
# 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