How do I find Rsquared?

11 visualizaciones (últimos 30 días)
Renan Fraga
Renan Fraga el 22 de Mayo de 2021
Comentada: Sulaymon Eshkabilov el 23 de Mayo de 2021
Hello! Please, I need help. Tried everything and couldn't do it.
I have 2 vectors of values:
T0 = [-49;-45;-19;-20;30;30;100;98;238;239;350;349];
Y = [0;0;0;0;12;8;48;44;46;34;34;40];
And I need to use the equation F=A+B*tanh((T-T0)/C) to fit these points. So I'm using the optimoptions to find the best fit:
lb = [];
ub = [];
% Starting point
x0 = [10;10;10;10];
F = @(x) (x(1) + x(2)*tanh((x(3) - T0)/x(4)) );
Fobj = @(x,T0) F(x);
options = optimoptions('lsqcurvefit','Algorithm','levenberg-marquardt');
x = lsqcurvefit(Fobj,x0,T0,Y,lb,ub,options);
I know (using the Curve Fit Toolbox) that the values of x are supposed to create a curve with Rsquared = 0.9585, but even using the function corrcoef I can't find this R squared.
Can anybody, please help?

Respuesta aceptada

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 22 de Mayo de 2021
Hi,
Here is the quick solution:
% Starting point
x0 = [10;10;10;10];
F = @(x) (x(1) + x(2)*tanh((x(3) - T0)/x(4)) );
Fobj = @(x,T0) F(x);
options = optimoptions('lsqcurvefit','Algorithm','levenberg-marquardt');
x = lsqcurvefit(Fobj,x0,T0,Y,lb,ub,options);
FM = (x(1) + x(2)*tanh((x(3) - T0)/x(4)) );
plot(T0, Y, 'ro', T0, FM, 'b--')
RSS = sum((Y-FM).^2);
TSS = sum((Y-mean(Y)).^2);
R_sq = 1-RSS/TSS;
fprintf('R square = %1.3f \n', R_sq)
Good luck.
  2 comentarios
Renan Fraga
Renan Fraga el 23 de Mayo de 2021
Thank you so much!
Sulaymon Eshkabilov
Sulaymon Eshkabilov el 23 de Mayo de 2021
You are most welcome! It is just a pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by