Differences in power law fit vs. linear fit on log-log scale
28 views (last 30 days)
I am fitting data using cftool to a power law, i.e. , and comparing it to the 1st-order polynomial fit, i.e. when I take the base-10 log of the same data in both x and y. The scaling exponent that I get is different: 0.523 in the first case vs. 0.498 in the second case. Why is there any diference? Should I just go by whichever fit has the better goodness-of-fit statistics, or is there some better way of going about this? Attached is the data that I am using as an example. The x values are in the first column, and the y values are in the second column.
the cyclist on 28 Nov 2022
Hm. I get much closer values when I use fitlm (0.498) and nlinfit (0.504), for the log-space and original space, respectively. (I don't have the curve fitting toolbox.)
It's close enough that I would not have thought twice about it, and chalked it up to convergence criteria, perhaps.
I think it is possible that the fit is not quite mathematically equivalent, because the minimization criteria involves a squared term, and therefore not equivalent when doing the log conversion. I'm not sure, and I'd have to think more carefully about it.
If there is truly a difference, the ideal way to decide whether to solve this in linear or log space would be based on which space obeys the model assumptions better (things like residuals being normally distributed, etc.) Frankly, the models are so close to each other that I'm not sure it much matters, from a pragmatic point of view. But, there is probably a "right" answer, if one needs to be theoretically nitpicky.
% Load your file from the web
% Assign x and y from your C matrix
x = C(:,1);
y = C(:,2);
% Fit the model in log space.
% (I used natural log, not base10 log, but it doesn't matter for the slope term)
mdl = fitlm(log(x),log(y))
% Define function that will be used to fit data (F is a vector of fitting parameters)
f = @(F,x) F(1) * x.^(-F(2));
% Do the non-linear fit
F_fitted = nlinfit(x,y,f,[1 1]);
% Display fitted coefficients
disp(['F = ',num2str(F_fitted)])
More Answers (1)
Matt J on 28 Nov 2022
Edited: Matt J on 28 Nov 2022
There is a difference because the statistical distribution of the measurement errors changes under the log transformation. You should go with the one that fits the best. That will probably the model whose errors are most close to Gaussian additive noise, though.