How to linear regress data on a log-log plot?
5 ビュー (過去 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!