# Akaike Information Criterion and Log Likelhood of a call to nlinfit

2 views (last 30 days)
Pitch Mandava on 14 Jan 2017
Answered: the cyclist on 14 Jan 2017
I fit a model to data using a call below
[pmsf(i).params pmsf(i).resids pmsf(i).jacobian SIGMA mse] = nlinfit(pdatain, pzi, @my_lin_fun, a0);
How can I calculate AIC and Log Likelihood for the fit.

the cyclist on 14 Jan 2017
I don't think AIC is an output of nlinfit. While I expect that one could calculate it from the output, it might actually be faster to rewrite your code to use the more modern fitnlm function, which does have AIC as an output.
I've attached a simple example of fitnlm, in case that helps.
rng 'default'
% Here is an example of using fitnlm(). For simplicity, none of
% of the fitted parameters are actually nonlinear!
% Define the data to be fit
x=(0:1:10)'; % Explanatory variable
y = 5 + 3*x + 7*x.^2; % Response variable (if response were perfect)
y = y + 2*randn((size(x)));% Add some noise to response variable
% Tabulate the data
tbl = table(x,y);
% % Fit the model
% Define function that will be used to fit data
% (F is a vector of fitting parameters)
f = @(F,x) F(1) + F(2).*x + F(3).*x.^2;
beta0 = [1 1 1];
mdl = fitnlm(tbl,f,beta0);
% Calculate the model values at the empirical x
y_predicted = predict(mdl,x);
% Plot the data and fit
figure
plot(x,y,'*',x,y_predicted,'g');
legend('data','fit')
% Display AIC
AIC = mdl.ModelCriterion.AIC