Filter löschen
Filter löschen

How to linear regress data on a log-log plot?

5 Ansichten (letzte 30 Tage)
Joey
Joey am 26 Jan. 2015
Kommentiert: Star Strider am 26 Jan. 2015
I have 5 data points plotted on a log-log scale, and I want to find a linear regression equation for it. The original (un-logged) equation I'm trying to find is in the form m=k*P^n. Plotting the data on a log-log scale makes it linear so I just need the slope and y-intercept to get the original equation (where k is the y-int and n is the slope). I forgot how to do this.

Antworten (1)

Star Strider
Star Strider am 26 Jan. 2015
It is relatively easy with core MATLAB functions to do a nonlinear regression. See http://www.mathworks.com/matlabcentral/answers/171718-how-can-write-this-in-matlab#comment_262537 for a nonlinear regression of a function quite similar to yours.
The problem with log transformations, especially with only 5 data pairs, is that the additive, normally-distributed errors (that the least squares technique assumes) become log-normally distributed, giving potentially inaccurate parameter estimates.
Since ‘k’ is the y-intercept and ‘n’ is the slope, your objective function (replacing the ‘P’ function in my previous answer) and where k=b(1) and n=b(2) is:
m = @(b,P) b(1).*P.^b(2);
and the cost function becomes:
SSECF = @(b) sum((y - m(b,P)).^2);
If you absolutely must do a log-log regression, use polyfit:
B = polyfit(log(P), log(m), 1);
  2 Kommentare
Joey
Joey am 26 Jan. 2015
Thanks! Polyfit is exactly what I needed.
Star Strider
Star Strider am 26 Jan. 2015
My pleasure!
I would still prefer you go with the nonlinear parameter estimation. It will give accurate parameter estimates.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Linear and Nonlinear Regression finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by