2

I have two sets of data: Peak Velocity and Amplitude. The relation between the two parameters is not linear and I used a logarithmic (base10) plot before performing linear regressions (this process is supposed to be equivalent to a power law fit).

However, when I have the data plotted in a log-log scaled graph (both axes in logarithmic scale) the linear fit does not appear to me to be linear. How can I perform a linear regression in a log-log graph with Matlab.

I have attached a picture of the graph and the linear fitting that I obtained.

Any help is much appreciated!

Thank you in advance!

enter image description here

Joseph Ravenwolfe
  • 6,480
  • 6
  • 31
  • 31
Flowers
  • 59
  • 1
  • 2
  • 12
  • Can you post the code that generates that image? – phyrox Jan 25 '14 at 17:50
  • @phyrox . Once I obtained the graph with the data1 plotted, the line was fitted using the basic fitting option from the tools tab (in the graph window). The graph is obtained with the following bit of code: `'% Plot #2: amplitude vs. peak velocity figure('Name','Main sequence','NumberTitle','off'); loglog(Saccades.amplitude, Saccades.peakVelocity, 'green.'); xlabel('Amplitude (°)'); ylabel('Peak velocity (°/s)'); title('Saccade Main sequence');` – Flowers Jan 25 '14 at 18:58
  • I think you are creating the regression using the linear data. You should first make the exponential (or the log) of the dta, and then make the regression (and plot it in a linear plot) – phyrox Jan 25 '14 at 19:15

1 Answers1

2

This is indeed a fit of a power law, which can be described with the formula y = k * x^tau. If you plot this in a log-log figure, you get a straight line. To retrieve the parameters, you have to take the logarithm of both sides of the equation, and then do a linear fit:

% generate some data with random noise
x = logspace(-.5, 1.5, 100);
y = 42 * x.^0.66;
y = y .* (1 + 0.2 * randn(size(y)));

% do linear fit: log(y) = p(1) * log(x) + p(2)
p = polyfit(log(x), log(y), 1);

% retrieve original parameters
tau = p(1);
k = exp(p(2));

% plot
loglog(x, y, '.', x, k*x.^tau, 'r')
axis([.1 100 10 1000])
legend('data', sprintf('power law fit: y = %.1f * x^{%.2f}', k, tau))
xlabel('Amplitude')
ylabel('Velocity')

Result: power law fit Note that this is just a quick and dirty trick, it probably does not give a result that is statistically correct.

Bas Swinckels
  • 18,095
  • 3
  • 45
  • 62