Hi. I am trying to add a log-linear trend to a scatterplot with log y axis, but I cant seem to figure out how to do it. It is a very simple plot like this:
>> scatter(data1,data2)
>> set(gca, 'yScale', 'log')
Any suggestions on how to add a log-linear trend? Thanks in advan[c]e.
IR

댓글 수: 2

Star Strider
Star Strider 2016년 10월 1일
Please describe what you mean by ‘a log-linear trend’.
Your code sets the y-axis to a logarithmic scale.
Ida Rosendahl
Ida Rosendahl 2016년 10월 1일
I mean a log linear best fit for my data. My plot is a scatterplot with logarithmic scaled y-axis and linear x-axis.

댓글을 달려면 로그인하십시오.

 채택된 답변

dpb
dpb 2016년 10월 1일

0 개 추천

Fit the log(y), compute the fitted result and add...
b=polyfit(data1,log(data2),1); % ln y = mx + b
yhat=exp(polyval(data1)); % compute fitted result
hold all % prepare to add the fittted line
hLyhat=plot(data1,yhat); % add to the plot; save handle to make fixups as wanted

댓글 수: 4

Ida Rosendahl
Ida Rosendahl 2016년 10월 1일
Thank you for taking time to respond - that was exactly what I was looking for.
dpb
dpb 2016년 10월 1일
No problem; don't know why TMW doesn't have the logarithmic models as one of the prepackaged ones in the fitting toolbox, but they don't...
Star Strider
Star Strider 2016년 10월 1일
Probably because doing a log transformation transforms the additive errors into multiplicative errors, violating the assumptions of least-squares regression (normally-distributed residuals). It’s mathematically appropriate (and correct) to do a nonlinear regression of an exponential function, that will give you accurate parameter estimates, rather than doing a log transformation and getting the wrong parameter estimates.
dpb
dpb 2016년 10월 1일
Often in my experience if the data are exponential so are the errors. The assumption of normality only affects conclusions drawn from any statistics derived, not the method of fitting itself.
Should probably noted that in answer; the log transform minimizes the residuals in the log space whereas the exponential minimizes the residual of the original data values. Which resulting fit is better is dependent upon the application; I've seen reasons to choose both cases in practice.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

질문:

2016년 10월 1일

댓글:

dpb
2016년 10월 1일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by