linear regression in log-log scale

43 次查看(过去 30 天)
sani
sani 2020-10-16
评论: sani 2020-10-17
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 个评论
sani
sani 2020-10-17
Hi, Thats interesting, I thought if im using basic fitting tool it does that automatically, along with R^2. Do I have to manually write it?
Star Strider
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
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)
  1 个评论
sani
sani 2020-10-17
but isn't polyfit returns the coefficients of the polynomial?
then what is the meaning of mdl if it returns y and x?
X = [0.5 1 5 10 1000 5000];
Y = [0.52 0.99 4.58 10.14 902.9 4026];
those are my X and Y values and as I put them into mdl I get
mdl =
0.9780 0.0079
which 0.9780 is A and 0.0079 is B in the equation A*x+B, am I right? I tried to plot it but it doesn't make any sense.

请先登录,再进行评论。

类别

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