Problem of Nonlinear Regression

4 views (last 30 days)
Kim Jeong Min
Kim Jeong Min on 31 Jul 2019
Answered: Alex Sha on 1 Aug 2019
Hello, everyone.
I want to fit the time vs temperature data (Attachment "Data.txt")
Using a nonlinear equation as below
Every parameters except t is a constant value.
The problem is the initial value of each parameters is unknown.
What I expected is , , .
Thanks for any helpful ideas.
  1 Comment
Star Strider
Star Strider on 31 Jul 2019
The model that you posted:
and that I coded as:
objfcn = @(b,t) b(1) + (b(2)./(1 - exp(-b(3) + b(4).*t)) - 1)./b(5);
does not describe your data. Even using a genetic algorithm (the ga function) and an unconstrained fit, I cannot get even a reasonable fit to your data with your model.

Sign in to comment.

Accepted Answer

Alex Sha
Alex Sha on 1 Aug 2019
Hi, Kim, if take time t as x, temperature T as y, your model function looks like:
y=t1+(x0/(1-exp(-c+b*x))-1)/a;
However, your constraint conditions are not enough for getting unique results:
Results 1:
Root of Mean Square Error (RMSE): 2.52934677609146
Sum of Squared Residual: 140.747092501933
Correlation Coef. (R): 0.999963269065018
R-Square: 0.999926539479198
Adjusted R-Square: 0.999918806792798
Determination Coef. (DC): 0.999926539479198
Chi-Square: 0.655121289041804
F-Statistic: 57849.9544626346
Parameter Best Estimate
---------- -------------
x0 0.693513613034404
a -0.000281616005220676
t1 1004.82691662351
c 1.17804643673168
b 0.000241938254130124
results 2:
Root of Mean Square Error (RMSE): 2.52934677609147
Sum of Squared Residual: 140.747092501935
Correlation Coef. (R): 0.999963269065018
R-Square: 0.999926539479198
Adjusted R-Square: 0.999918806792798
Determination Coef. (DC): 0.999926539479198
Chi-Square: 0.655121252952012
F-Statistic: 57849.9546119436
Parameter Best Estimate
---------- -------------
x0 0.760684251933242
a -0.000308892144387651
t1 1318.38503693851
c 1.17804624141689
b 0.000241938218639866
c202.jpg

More Answers (2)

Jon
Jon on 31 Jul 2019
Edited: Jon on 31 Jul 2019
If you have the Statistics and Machine learning toolbox you can use fitnlm or nlinfit see documentation https://www.mathworks.com/help/stats/nonlinear-regression-1.html
If you don't have the Statistics and Machine learning toolbox but have the Optimization toolbox you could set up your own optimization problem to minimize, for example, the sum of the squared errors between model prediction and actual and then solve it using fminunc (or fmincon if you wanted to put some hard limits on the parameter values)

John D'Errico
John D'Errico on 31 Jul 2019
I'm not terribly sure why you want to fit that choice of model, especilly if it does not fit.
First, with t as time, and T as temperature, I get a simple model, that fits reasonably well. (Use the curve fitting toolbox, as by far the best tool for these problems.)
ft = fittype('a + b*exp(t/c)','indep','t')
ft =
General model:
ft(a,b,c,t) = a + b*exp(t/c)
>> mdl = fit(t,T,ft,'start',[1000,-1000,1000])
mdl =
General model:
mdl(t) = a + b*exp(t/c)
Coefficients (with 95% confidence bounds):
a = 1673 (1629, 1718)
b = -678.2 (-720.4, -635.9)
c = 1835 (1759, 1912)
plot(mdl)
grid on
hold on
plot(t,T,'o')
xlabel 'time'
ylabel 'temperature'
untitled.jpg
So absolutely no problem in the fit, and quite a reasonable fit too with a simple model. Perhaps the problem is this model predicts that temperature will got to -inf for large time, and of course that is nonsense, since temperature will be limited at absolute zero.
As well, I see that you plotted it with a logged axis for time. The problem is, if you want to estimate a sigmoid shaped function, you problably need more data, for longer times, in order to estimate where that process starts to slow down. Otherwise, all you can do is predict the shape will continue to accelerate with time. In fact, if I look at the shape of your data (using a spline fit), it does not appear to have even started to slow down.

Community Treasure Hunt

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

Start Hunting!