# How to calculate AIC from an fmincon optimization

5 views (last 30 days)
Rozh Al-Mashhdi on 22 Apr 2016
Answered: Vaibhav Awale on 3 May 2016
I have some independent and dependent data measurements in two variables (vectors), called X and Y, respectively. I am using fmincon to minimize the following cost function
function SSerr = ObjFun(C, X, Y)
Yhat = Model(C, X);
T = ( Yhat - Y ).^2;
SSerr = sum(T(:));
end
the function "Model" above just calculates the predicted values (Yhat) based on the measured independent variable data (X) and some fit-parameters (C).
I assume that the errors (deviations between predicted Yhat and measured Y) come from a normal (Gaussian) distribution with mean=0 and variance sigma, G(0, sigma2)
I want to calculate the Akaikes Information Criterion (AIC).
I have found the formula for the AIC, at wikipedia
AIC = 2k - 2ln(L)
where k is the number of parameters used for the fit (in my case the length of C) and L is the maximum value of the likelihood function.
So my question is: how do I calculate the maximum value of the likelihood function ?
I have seen here that minimising the sum of the squares of the residuals (RSS), as I do above, is equivalent to maximising the likelihood function if the residuals are normally distributed.
But this does not mean that the RSS is equal to the likelihood function - or does it ?

Vaibhav Awale on 3 May 2016
Hi Rozh,
From the link that you have provided, it seems that maximum value of likelihood function will occur at minimum value of RSS. However, for calculating maximum value of likelihood from RSS, you will need to know the variance of the model as well.
Please refer to following documentation link which has MATLAB function 'aic', which is used to find Akaike's Information Criterion for estimated model.
I hope this helps.
Regards,
Vaibhav

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by