Differences in power law fit vs. linear fit on log-log scale
조회 수: 33 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
the cyclist
2022년 11월 28일
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
load(websave('myFile','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1210228/example.mat'))
% 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)])
추가 답변 (1개)
Matt J
2022년 11월 28일
편집: Matt J
2022년 11월 28일
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.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!