Calculate R^2 of two graphs
26 views (last 30 days)
Show older comments
Oliver Makan
on 12 Nov 2021
Commented: Star Strider
on 18 Nov 2021
Hi guys,
I wanted to know if it is possible to calculate the goodness of fit or R^2 to evaluate the performance of the fit.
I have two separate graphs which are separately calculated: the probability plot (brown) and the dataset (blue cross).
I know that it is able to fit a predefined graph ( e.g. quadratic, polynomial etc.) to a dataset with the toolbox but is it possible to fit my calculated graph to the dataset ?
Thank you
0 Comments
Accepted Answer
Star Strider
on 12 Nov 2021
One approach —
x = linspace(0.1, 85, 50); % Create Data
y = atanh((x-mean(x))/max(x)*2)/4+0.5 + randn(size(x))*0.01; % Create Data
X = [x(:).^3 x(:).^2 x(:) ones(size(x(:)))]; % Design Matrix
[B,Bint,R,Rint,Stats] = regress(y(:), X);
ParameterStats = table(Bint(:,1), B, Bint(:,2), 'VariableNames',{'Lower 95% CI','Parameter Value','Upper 95% CI'}, 'RowNames',{'x^3','x^2','x','Const'})
Rsq = Stats(1)
F_p = [Stats(2:3)]
ErrorVar_Est = Stats(4)
figure
plot(x, y, '+b')
hold on
plot(x, X*B, '-r')
hold off
grid
Experiment with the actual data.
.
3 Comments
More Answers (1)
See Also
Categories
Find more on Linear and Nonlinear Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!