How to linear regress data on a log-log plot?
조회 수: 11 (최근 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!