Akaike Information Criterion and Log Likelhood of a call to nlinfit

1 次查看(过去 30 天)
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.

回答(1 个)

the cyclist
the cyclist 2017-1-14
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

类别

Help CenterFile Exchange 中查找有关 Regression 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by