goodness of fit data for a fit

7 views (last 30 days)
Sara on 14 Jan 2023
I am new in matlab and I would be thankful if you help me.
I want to get the goodness of fit data using fit = goodnessOfFit(x,xref,cost_func) or any other command that provides statistics of goodness of fit for the following fit:
  • load sample.mat;
  • rangemin = 50;
  • rangemax = 149;
  • xprime(1)=1;
  • xprime(2)=20;
  • [x]=lsqcurvefit(@our,xprime,t(rangemin:rangemax),ourdata(rangemin:rangemax));
  • y=our(x,t);
  • x1=x(1,1)
  • x2=x(1,2)
  • function y=our(x,t)
  • y=((0.282*x(2))-0.24)*x(1)*exp((x(2)-0.24)*t);
  • end
I am not sure what should be x and xref and cost_func here and where I should put this command?

Answers (2)

Torsten on 14 Jan 2023
Edited: Torsten on 14 Jan 2023
Statistical information about the goodness of fit can be obtained by using "fit" instead of "lsqcurvefit" and the second output argument structure "gof":
I think the function "goodnessOfFit" is insufficient for this purpose.

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 14 Jan 2023
From your posted link, you can see that:
(1) x is:
x = lisqcurvefit(...) gives you the found fit model coefficients. E.g.: from your exercise:
  • y=((0.282*x(2))-0.24)*x(1)*exp((x(2)-0.24)*t);
x = [x(1), (x2)]
(2) xref is:
xref is your measured data
(3) cost_func is:
cost_func = 'NRMSE' % normalized root mean squared error (NRMSE) as the cost function
You may also consider setting it to be:
cost_func = 'MSE'; % Mean squared error
cost_func = 'NMSE'; % Normalized mean squared error




Community Treasure Hunt

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

Start Hunting!

Translated by