linear regression in log-log scale
이전 댓글 표시
Hello,
I have a data set that I want to present in log log scale and to fit a linear regression with equation and R^2
I tried to use the log log function and the basic fitting tool, but the line is not linear.
this is the results I get

댓글 수: 3
Mathieu NOE
2020년 10월 16일
hi
you mean you plotted the data on a log log graph but did you do the linear fitting on the log of your data ?
explanation : the linear regression is on the log of your data : so the equation is log(y) = A*log(x) + B
A and B are the result of the fitting function made on the log of the data
if you want now an equation between y and x , you just have to take the power of 10 on both sides of the equation :
y = 10^(A*log(x) + B).
sani
2020년 10월 17일
Star Strider
2020년 10월 17일
‘if you want now an equation between y and x , you just have to take the power of 10 on both sides of the equation :
y = 10^(A*log(x) + B).’
Definitely the correct approach, however in error on the essential point that the log function in MATLAB and all other computer languages is the natural logarithm, not the base 10 logarithm (that in MATLAB would be log10), so exp(...) not 10^(...). At least to the best of my knowledge.
답변 (1개)
John D'Errico
2020년 10월 17일
편집: John D'Errico
2020년 10월 17일
Sadly, while I wish the fitting tool would fit your data on log scales if that is how the axes are set, it does not. (That has always bugged me. But who am I to say? They made a choice that seemed valid to the author of the basic fitting tool.) It still fits your unlogged data to the desired curve.
However, you do not need to "write" the linear regression yourself. polyfit will do perfectly well.
mdl = polyfit(log(x),log(y),1)
카테고리
도움말 센터 및 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!