How can I reduce error on loglog scale using linear regression?
1 回表示 (過去 30 日間)
古いコメントを表示
This is what I am doing with my imported data. What can I do to reduce the multiplicative errors? I tried to adapt non-linear regression to my script but I don't understand the examples that I've found so far. If possible, please suggest what could I do in both scenarios.
- Reduce the error in linear regression
- Apply non-linear regression instead with every line explained
The plot of my data in log scale is shown below.
Thanks
% x: assume any column vector x
% y: assume any column vector y
loglog(x,y, '*');
% % Estimating the best-fit line
const = polyfit(log(x),log(y), 1);
m = const(1);
k = const(2);
bfit = x.^m.*exp(k); % y = x^m * exp(k)
hold on
loglog(x,bfit)
![Screen Shot 2018-11-13 at 00.33.57.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/194777/Screen%20Shot%202018-11-13%20at%2000.33.57.png)
0 件のコメント
採用された回答
Star Strider
2018 年 11 月 13 日
Change them to additive errors (as they should be) using nonlinear regerssion techniques.
Example (from another Answer) —
temp = [100,200,400,600,800,1000,1200,1400,1600]';
density = [3.5,1.7,0.85,0.6,0.45,0.35,0.3,0.25,0.2]';
fcn = @(b,x) exp(b(1).*x).*exp(b(2)) + b(3);
[B,rsdnorm] = fminsearch(@(b) norm(density - fcn(b,temp)), [-0.01; max(density); min(density)]);
fprintf(1, 'Slope \t\t=%10.5f\nIntercept \t=%10.5f\nOffset \t\t=%10.5f\n', B)
tv = linspace(min(temp), max(temp));
figure
plot(temp, density, 'p')
hold on
plot(tv, fcn(B,tv), '-')
grid
text(500, 1.7, sprintf('f(x) = %.2f\\cdote^{%.4f\\cdotx} + %.2f', B([2 1 3])))
There are a number of funcitons you can use to do nonlinear parameter estimation in MATLAB. I use fminsearch here because every body has it.
7 件のコメント
Star Strider
2018 年 11 月 13 日
The fminsearch function is much more sensitive to initial parameter estimates than other optimisation routines. I decided to let the Global Optimization Toolbox genetic algorithm ga funciton see what it could come up with, using patternsearch to fine-tune the parameter estimates.
The best were:
B =
3.29616368688383 -75.2881776260513 0.0003711181640625 -256076512.169127
producing a residual norm of 0.0010247, and:
![How can I reduce error on loglog scale using linear regression - 2018 11 13.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/194920/How%20can%20I%20reduce%20error%20on%20loglog%20scale%20using%20linear%20regression%20-%202018%2011%2013.png)
This is simply the nature of many nonlinear parameter estimation problems. Your problem is particularly difficult because of the range and magnitude of your data, and the small number of data you have.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Linear Least Squares についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!