Calculate R^2 of two graphs

조회 수: 18 (최근 30일)
Oliver Makan
Oliver Makan 2021년 11월 12일
댓글: Star Strider 2021년 11월 18일
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

채택된 답변

Star Strider
Star Strider 2021년 11월 12일
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
X = 50×4
1.0e+05 * 0.0000 0.0000 0.0000 0.0000 0.0001 0.0000 0.0000 0.0000 0.0005 0.0001 0.0000 0.0000 0.0015 0.0003 0.0001 0.0000 0.0035 0.0005 0.0001 0.0000 0.0067 0.0008 0.0001 0.0000 0.0116 0.0011 0.0001 0.0000 0.0183 0.0015 0.0001 0.0000 0.0272 0.0019 0.0001 0.0000 0.0387 0.0025 0.0002 0.0000
[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'})
ParameterStats = 4×3 table
Lower 95% CI Parameter Value Upper 95% CI ____________ _______________ ____________ x^3 5.1529e-06 7.0396e-06 8.9263e-06 x^2 -0.0011438 -0.0008994 -0.00065504 x 0.031404 0.040307 0.049211 Const -0.21537 -0.12867 -0.041973
Rsq = Stats(1)
Rsq = 0.9192
F_p = [Stats(2:3)]
F_p = 1×2
174.3300 0.0000
ErrorVar_Est = Stats(4)
ErrorVar_Est = 0.0066
figure
plot(x, y, '+b')
hold on
plot(x, X*B, '-r')
hold off
grid
Experiment with the actual data.
.
  댓글 수: 3
Oliver Makan
Oliver Makan 2021년 11월 18일
again thank you for your quick reply :)
Star Strider
Star Strider 2021년 11월 18일
As always, my pleasure!
.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Oliver Makan
Oliver Makan 2021년 11월 18일
Hi Star Strider,
thank you for the quick approach.
Just for a better understanding:
The regression is a polynomial x^3 regression with x&y graph tested on which data ?
additional, is it possible to get the goodness of fit of a function F=exp^(x/d) to the dataset x/y.
What does the matrix X stand for ?
again thank you very much.

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by