Non-linear regression
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Collin Pecora
le 5 Mai 2021
Commenté : the cyclist
le 6 Mai 2021
This is a question on non-linear curve fitting, not on model selection and not particularly on how to do regression in matlab.
I have 2 models for the same physical process, each a function of the vector x, and both have two coefficients, for m1, they are x0 and b and for m2 they are x0 and theta, where theta is notationally, b/x0. The models return slightly different values for x0 and theta from m2 does not general equal b/x0 from m1.
I am looking for advice on how to justify the use of one model over the other.
x = linspace(0,1,1e3); % For example
m1 = @(x) (1 - (x./x0)) .* exp(-b .* (x/x0));
m2 = @(x) (1 - (x./x0)) .* exp(-theta .* x);
Thanks
Collin
0 commentaires
Réponse acceptée
the cyclist
le 5 Mai 2021
It seems to me that your two models are equivalent, but one is specified in a way that masks that fact.
x0 is really just a scaling parameter -- you can think of it as the "units" of x. Define a new variable:
z = x/x0;
Then
mz1 = @(z) (1 - z) .* exp(-b .* z);
mz2 = @(z) (1 - z) .* exp(-theta .* x0 .* z);
and then define a new parameter
b2 = theta .* x0;
resulting in
mz1 = @(z) (1 - z) .* exp(-b .* z);
mz2 = @(z) (1 - z) .* exp(-b2 .* z);
and you see that your models are equivalent, 1-parameter models.
2 commentaires
the cyclist
le 6 Mai 2021
Actually, I have to take back what I said about these boiling down to a 1-parameter model. Because you don't know x0 a priori, you can't do that step.
However, the two models are certainly equivalent.
% Set random number generator seed, for reproducibility
rng default
% Generative process for creating the data, with a little noise in y.
b = 2;
x0 = 3;
theta = 5;
m1 = @(x) (1 - (x./x0)) .* exp(-b .* (x/x0));
x = linspace(0,1,20)';
y = m1(x) + 0.02*randn(size(x));
% The two forms of the fitting function
f1 = @(B1,x) (1 - (x./B1(1))) .* exp(-B1(2) .* (x./B1(1)));
f2 = @(B2,x) (1 - (x./B2(1))) .* exp(-B2(2) .* x);
% The two fits
mdl1 = fitnlm(x,y,f1,[1 1])
mdl2 = fitnlm(x,y,f2,[1 1])
% The predicted y values from the fits
y1 = predict(mdl1,x);
y2 = predict(mdl2,x);
% Plot the data and fits
figure
hold on
scatter(x,y)
plot(x,y1,'-')
plot(x,y2,'--')
legend({'data','1st model','2nd model'})
% Compare coefficents
coef1 = mdl1.Coefficients.Estimate;
coef2 = mdl2.Coefficients.Estimate;
fprintf('\nb/x0 from first model: %10.7f\n',coef1(2)/coef1(1))
fprintf('theta from second model: %10.7f\n',coef2(2))
You are seeing, though, that because of the numerical nature of the calculation, they do not return exactly the same result. But I don't think you can "justify" one over the other. They are truly equivalent, mathematically.
It's difficult to tell from inspection, but I think that the second method may be a bit more numerically stable, because with just one parameter in the exponential, you will likely not get as large deviations calculated. Perhaps that is a reason to choose it.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Linear and Nonlinear Regression dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!