To calculate the Akaike Information Criterion with a correction for finite sample sizes (AICC
) in Matlab, you can use the following code:
main.m669 chars20 lines
In this code, I assumed that you have loaded your data into X
and Y
matrices or tables (replace mydata.mat
with your data file name if needed). You can define your candidate models using the fitlm
function, which estimates a linear (or quadratic, in this example) regression model. Then, you can compute the log-likelihood for each model using the LogLikelihood
property of the model object. Next, you can compute the number of model parameters (k
) based on the number of coefficients in the model object. Finally, you can calculate AICC for each model using the formula:
AICC = -2 * log-likelihood + 2k + 2k(k+1)/(n-k-1)
Note that the formula for AICC includes a correction factor that depends on k
and n
, which adjusts the penalty for model complexity based on the sample size. Lower AICC values indicate better model fit, with a penalty for model complexity.
gistlibby LogSnag