Allin Cottrell 1.5 2024-04-12 Calculate model selection criteria C10 This simple package contains a single function with this signature: matrix criteria (scalar ess, int n, int k, bool quiet[0]) It computes the Akaike Information Criterion (AIC), Schwarz's Bayesian Information Criterion (BIC), the Hannan-Quinn criterion (HQC) and the corrected AIC (AICc), given ess (error sum of squares), the number of observations (n) and the number of coefficients (k). Following estimation of a model in gretl the quantities wanted as arguments for criteria() can be accessed as $ess, $T and $ncoeff, respectively. 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 The AICc is AIC with a correction for small sample size, to remedy the tendency for AIC to overfit. It is computed as follows: AICc = AIC + (2*k(k+1)) / (n-k-1) A row vector containing the four criteria is available for assignment on return. If you just want this vector you can give a non-zero value for the optional "quiet" argument to suppress printed output. if ess <= 0 || n <= k funcerr "We require ess > 0 and n > k" endif matrix crit = zeros(1, 4) 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) crit[4] = crit[1] + (2 * k * (k+1)) / (n-k-1) cnameset(crit, defarray("AIC", "BIC", "HQC", "AICc")) if !quiet printf "Using ess = %g, %d observations, %d coefficients\n", ess, n, k printf "\nAIC = %#g\nBIC = %#g\nHQC = %#g\nAICc = %#g\n\n", crit[1], crit[2], crit[3], crit[4] endif return crit set verbose off 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 the matrix is somewhat redundant, but this is just for # illustration print cr