How can I reduce error on loglog scale using linear regression?

2 views (last 30 days)
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.
  1. Reduce the error in linear regression
  2. 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

Accepted Answer

Star Strider
Star Strider on 13 Nov 2018
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 Comments
Marisabel Gonzalez
Marisabel Gonzalez on 13 Nov 2018
3E-4; 0.04; -1; 1E+8
How can you tell that these are the most accurate guesses? Even with the slightest change the results differ a lot...
What's the criteria to estimate these?
I'm struggling to find explanatory content regarding this bit...
Star Strider
Star Strider on 13 Nov 2018
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
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.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!