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

17 次查看(过去 30 天)
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.

回答(1 个)

Star Strider
Star Strider 2015-1-26
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 个评论
Joey
Joey 2015-1-26
Thanks! Polyfit is exactly what I needed.
Star Strider
Star Strider 2015-1-26
My pleasure!
I would still prefer you go with the nonlinear parameter estimation. It will give accurate parameter estimates.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by