Nonlinear regression; minimze absolute relative error
이전 댓글 표시
Greetings, I would appreciate if anyone can guide me through this. I am trying to fit the following data:
- aw = 0, 0.1145, 0.2260, 0.3232, 0.4355, 0.5251, 0.5779, 0.7083, 0.7554, 0.8432, 0.9044
- X = 0, 0.0149, 0.0353, 0.0565, 0.0590, 0.0754, 0.0906, 0.2688, 0.3326, 0.5300, 0.7894
to the following equation (Eq. 1) using the "fit" function
- Xm*C*K*aw/((1-K*aw)*(1-K*aw+C*K*aw)); parameters K, C, Xm (Eq. 1)
When the absolute relative error (Eq. 2) is minimized with the "Solver" add-in of Microsoft Excel, the fit yields K = 0.9146, C = 8.1415, Xm = 0.0244
Abs((Obs-Pred)/Obs) (Eq. 2)
Nevertheless, I cannot reproduce this K, C, and Xm values using the MATLAB "fit" function. I've already tried to modify other "fit" function arguments, and I ran out of ideas:
- Changing the 'Algorithm'
- Specifying 'Robsut' and 'LAR'
- Setting the Excel solution as the 'StartPoint'
- Constraining the 'Upper' and 'Lower' bounds of every parameter, but paramter Xm always takes the upper bound value
- Setting higher tolerance for model and coefficient values
Thank you,
Vinicio
댓글 수: 6
Star Strider
2014년 2월 19일
편집: Star Strider
2014년 2월 19일
I don’t have the Curve Fitting Toolbox so I can’t help you with that, but I do have nlinfit and lsqcurvefit. With starting parameter estimates of ( [0.1 0.1 0.1] ) and with ‘MaxIter’, 10000, I get:
Xm = 12.9417e+000
C = 6.1165e-003
K = 809.4168e-003
Mean squared residual = 323.5635e-006
and parameter confidence intervals:
ci =
12.9417e+000 12.9417e+000
4.6496e-003 7.5834e-003
776.2376e-003 842.5960e-003
If you get parameter estimates close to these with fit, I would trust them. I suggest you plot the function with the estimated parameter values against your original data.
Vinicio Serment
2014년 2월 20일
편집: Vinicio Serment
2014년 2월 20일
Matt Tearle
2014년 2월 20일
As Star Strider says, look at the quality of the fit you get from the two solutions:
f = @(C,K,Xm,aw) Xm*C*K*aw./((1-K*aw).*(1-K*aw+C*K*aw));
errorfun = @(C,K,Xm) nanmean(abs((X - f(C,K,Xm,aw))./X));
awfine = linspace(0,1);
K = 0.9146;
C = 8.1415;
Xm = 0.0244;
plot(aw,X,'o',awfine,f(C,K,Xm,awfine))
errorfun(C,K,Xm)
Xm = 12.9417e+000;
C = 6.1165e-003;
K = 809.4168e-003;
figure
plot(aw,X,'o',awfine,f(C,K,Xm,awfine))
errorfun(C,K,Xm)
The solution fit is finding has a lower error than the one you're looking for from Excel.
Given your comments about the physical interpretation, it looks like you need to include some kind of constraint on Xm. Are you doing that somehow in Excel? If so, what is the constraint you're imposing?
Star Strider
2014년 2월 20일
편집: Star Strider
2014년 2월 20일
As Matt Tearle notes, if you’re constraining the parameters, we need to know the constraints you’re imposing. We can’t guess what you’re thinking.
I’m obviously missing something. This looks like a reasonably good fit to me:

Vinicio Serment
2014년 2월 21일
Star Strider
2014년 2월 21일
When I use your unusual cost function ( errorfun ), I get a value of 5.6621e-003 for the mean squared error (mean of the squared residuals) and parameter estimates:
Xm = 1.0434e+000
C = 3.0440e+000
K = 44.8857e-003
If I use the sum-of-squares cost function instead:
errorfun = @(p) sum((X-f(p, aw)).^2);
I get a mean squared error of 327.9325e-006 and parameter estimates:
Xm = 847.9914e-003
C = 110.4277e-003
K = 693.9700e-003
I can’t account for the differences in the parameter estimates between fminsearch and nlinfit with similar mean-squared-errors, other than perhaps nlinfit and the other curve-fitting algorithms are more robust and managed to find the global minimum, and fminsearch found a local minimum. I’ll leave this for those who know more about the details of the respective algorithms.
답변 (0개)
카테고리
도움말 센터 및 File 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!