How to linear regress data on a log-log plot?
10 次查看(过去 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.
0 个评论
回答(1 个)
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 个评论
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 Center 和 File Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!