Standard error of regression curve

조회 수: 35 (최근 30일)
Hakan Süleyman
Hakan Süleyman 2020년 9월 13일
댓글: Hakan Süleyman 2020년 9월 13일
Hello,
I have two vectors, named as x and y. I would like to estimate the standard error of a regressed curve of these data points. The regression model is defined as ft in the below code. Can you please let me know if there is a way to estimate the standard error of b and m coefficients of this fit type?
x=[2;4;6;9;12;15;18]
y=[188;198;294;433;661;875;1097]
ft = fittype( 'b*x^m');
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
fitresult= fit( x, y, ft, opts );

채택된 답변

Adam Danz
Adam Danz 2020년 9월 13일
편집: Adam Danz 2020년 9월 13일
Follow this answer provided by MathWorks support [here]. Since the degrees of freedom are not defined in that answer, here's a more complete answer:
% Your data and their fit
x=[2;4;6;9;12;15;18]
y=[188;198;294;433;661;875;1097]
ft = fittype( 'b*x^m');
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
[fitresult, gof] = fit( x, y, ft, opts ); % <-- also include 2nd output!
% Compute standard error of the coefficients.
alpha = 0.95; % Choose an alpha level
ci = confint(fitresult, alpha)
df = gof.dfe;
t = tinv((1+alpha)/2, df);
se = (ci(2,:)-ci(1,:)) ./ (2*t) % Standard Error
% Results in same order as coefficients listed in fitresult.
% se =
% 10.0399163997427 0.0994320537151288
  댓글 수: 3
Adam Danz
Adam Danz 2020년 9월 13일
@Hakan Süleyman you have a good point and now I'm second guessing that approach for nonlinear models.
Unforunately I have to shut down for the day but this discussion linked below might be what you're looking for, particularly Richard Willey's answer.
I'd be interested if you find a more suitable approach and I may look into it later, myself.
Hakan Süleyman
Hakan Süleyman 2020년 9월 13일
The solution provided by MathWorks support (that you shared in your first comment) returns a very logical result. When I also tried the function given in Richard Willey's answer (in the link you provided in your latter comment), it gives exactly the same SE estimates:
x=[2;4;6;9;12;15;18]
y=[188;198;294;433;661;875;1097]
ft = fittype('b*x^m');
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
[fitresult, gof] = fit( x, y, ft, opts );
coeff=coeffvalues(fitresult);
myFit = NonLinearModel.fit(x,y, 'y ~ b0*x1^b1', [coeff(1), coeff(2)])
myFit.Coefficients.SE
% ans =
%
% 10.0400
% 0.0994
It seems both ways work for custom fit types. I will only need to be sure for the mathematical part. Thanks a lot!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by